1 /*
2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3  * Copyright (c) Imagination Technologies Limited, UK
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Waldo Bastian <waldo.bastian@intel.com>
27  *
28  */
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "thread1_bin.h"
34 
35 #define MTX_SIZE (40*1024)
36 #define MTX_SIZE1 (56*1024)
37 #define MTX_SIZE2 (56*1024)
38 #define MTX_SIZE3 (84*1024)
39 #define MTX_SIZE4 (56*1024)
40 #define STACKGUARDWORD          ( 0x10101010 )
41 #define UNINITILISE_MEM         ( 0xcd )
42 #define LINKED_LIST_SIZE	( 32*5 )
43 #define FIP_SIZE		( 296 )
44 
45 struct msvdx_fw {
46     unsigned int ver;
47     unsigned int  text_size;
48     unsigned int data_size;
49     unsigned int data_location;
50 };
51 
main()52 int main()
53 {
54     unsigned long i = 0;
55     FILE *ptr = NULL;
56     FILE *fp_ll_dma = NULL;
57     struct msvdx_fw fw;
58     FIRMWARE fw_DE3;
59 
60     fw_DE3 = sFirmware1366_FS; /* VXD3xx_DEVA_DDK_3_0_5 */
61     fw_DE3 = sFirmware1366_SS; /* VXD3xx_DEVA_DDK_3_0_5 */
62     fw_DE3 = sFirmware1419_FS; /* VXD3xx_DEVA_DDK_3_1_2 */
63     fw_DE3 = sFirmware_FS; /* VXD3xx_DEVA_DDK_3_2_4 */
64     fw_DE3 = sFirmware_SS; /* VXD3xx_DEVA_DDK_3_2_4 */
65     //fw_DE3 = sFirmware0000_SS; /* 1366based, for VP only, be able to disable WDT in Csim */
66     fw_DE3 = sFirmware_SS_DE3_3_20;
67     //fw_DE3 = sFirmware_SS_1472_3_8;
68     fw_DE3 = sFirmware_SS_1472_3_10;
69     fw_DE3 = sFirmware_1472_3_20_SS;
70 
71     fw.ver = 0x0496;
72     fw.text_size = fw_DE3.uiTextSize / 4;
73     fw.data_size = fw_DE3.uiDataSize / 4;;
74     fw.data_location = fw_DE3.DataOffset + 0x82880000;
75 
76     ptr = fopen("msvdx_fw_mfld_DE2.0.bin", "w");
77     if (ptr == NULL) {
78         fprintf(stderr, "Create msvdx_fw_mfld_DE2.0.bin failed\n");
79         exit(-1);
80     }
81     fwrite(&fw, sizeof(fw), 1, ptr);
82 
83     for (i = 0; i < fw.text_size; i++) {
84         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
85     }
86     for (i = 0; i < fw.data_size; i++) {
87         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
88     }
89     fclose(ptr);
90 
91     /* Create stitch image of msvdx fw */
92     ptr = fopen("unsigned_msvdx_fw.bin", "w");
93     if (ptr == NULL) {
94         fprintf(stderr, "Create unsigned_msvdx_fw failed\n");
95         exit(-1);
96     }
97     fp_ll_dma = fopen("linked_list_struct", "r");
98     if (fp_ll_dma == NULL) {
99         fprintf(stderr, "Cannot open linked_list_struct failed %d\n", __LINE__);
100         exit(-1);
101     }
102 
103     unsigned int buf[(MTX_SIZE + sizeof(fw))/4];
104     fread(buf, 1, LINKED_LIST_SIZE, fp_ll_dma);
105     fwrite(buf, 1, LINKED_LIST_SIZE, ptr);
106 
107     memset(buf, UNINITILISE_MEM, MTX_SIZE + sizeof(fw));
108     buf[((MTX_SIZE + sizeof(fw))/4) - 1] = STACKGUARDWORD;
109 
110     fwrite(buf, 1, MTX_SIZE + sizeof(fw), ptr);
111 
112     fseek(ptr, LINKED_LIST_SIZE, SEEK_SET);
113     fwrite(&fw, sizeof(fw), 1, ptr);
114 
115     for (i = 0; i < fw.text_size; i++) {
116         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
117     }
118 
119     fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
120 
121     for (i = 0; i < fw.data_size; i++) {
122         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
123     }
124     fclose(ptr);
125     fclose(fp_ll_dma);
126 
127     /* Create stitch image of 56k msvdx fw */
128     ptr = fopen("unsigned_msvdx_fw_56k.bin", "w");
129     if (ptr == NULL) {
130         fprintf(stderr, "Create unsigned_msvdx_fw failed\n");
131         exit(-1);
132     }
133     fp_ll_dma = fopen("linked_list_struct_56k", "r");
134     if (fp_ll_dma == NULL) {
135         fprintf(stderr, "Cannot open linked_list_sturct_56k failed\n");
136         exit(-1);
137     }
138 
139     unsigned int buf1[(MTX_SIZE1 + sizeof(fw))/4];
140     fread(buf1, 1, LINKED_LIST_SIZE, fp_ll_dma);
141     fwrite(buf1, 1, LINKED_LIST_SIZE, ptr);
142 
143     memset(buf1, UNINITILISE_MEM, MTX_SIZE1 + sizeof(fw));
144     buf1[((MTX_SIZE1 + sizeof(fw))/4) - 1] = STACKGUARDWORD;
145 
146     fwrite(buf1, 1, MTX_SIZE1 + sizeof(fw), ptr);
147 
148     fseek(ptr, LINKED_LIST_SIZE, SEEK_SET);
149     fwrite(&fw, sizeof(fw), 1, ptr);
150 
151     for (i = 0; i < fw.text_size; i++) {
152         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
153     }
154 
155     fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
156 
157     for (i = 0; i < fw.data_size; i++) {
158         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
159     }
160     fclose(ptr);
161     fclose(fp_ll_dma);
162 
163     /* Create mrfl unsigned image */
164     ptr = fopen("unsigned_msvdx_fw_mrfl.bin", "w");
165     if (ptr == NULL) {
166         fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n");
167         exit(-1);
168     }
169     fp_ll_dma = fopen("linked_list_struct_mrfld", "r");
170     if (fp_ll_dma == NULL) {
171         fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n");
172         exit(-1);
173     }
174 
175     unsigned int buf2[MTX_SIZE3];
176     unsigned char FIP_HEADER[FIP_SIZE];
177     int fw_size = (MTX_SIZE3 - LINKED_LIST_SIZE);
178 
179     memset(FIP_HEADER, 0, FIP_SIZE);
180     fwrite(FIP_HEADER, 1, FIP_SIZE, ptr);
181 
182     fread(buf2, 1, LINKED_LIST_SIZE, fp_ll_dma);
183 
184     fwrite(buf2, 1, LINKED_LIST_SIZE, ptr);
185 
186     memset(buf2, UNINITILISE_MEM, fw_size);
187     buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD;
188 
189     fwrite(buf2, 1, fw_size, ptr);
190 
191     fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET);
192     //fwrite(&fw, sizeof(fw), 1, ptr);
193 
194     for (i = 0; i < fw.text_size; i++) {
195         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
196     }
197 
198     //fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
199     fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET);
200 
201     for (i = 0; i < fw.data_size; i++) {
202         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
203     }
204     fclose(ptr);
205     fclose(fp_ll_dma);
206 
207     /* Create mrfl unsigned image 56k */
208     ptr = fopen("unsigned_msvdx_fw_mrfl_56k.bin", "w");
209     if (ptr == NULL) {
210         fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n");
211         exit(-1);
212     }
213     fp_ll_dma = fopen("FIP_Constant_linkedlist", "r");
214     if (fp_ll_dma == NULL) {
215         fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n");
216         exit(-1);
217     }
218 
219     unsigned int buf3[MTX_SIZE4];
220     fw_size = (MTX_SIZE4);
221 
222     fread(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, fp_ll_dma);
223     fwrite(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, ptr);
224 
225     memset(buf3, UNINITILISE_MEM, fw_size);
226     buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD;
227 
228     fwrite(buf2, 1, fw_size, ptr);
229 
230     fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET);
231 
232     for (i = 0; i < fw.text_size; i++) {
233         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
234     }
235 
236     fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET);
237 
238     for (i = 0; i < fw.data_size; i++) {
239         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
240     }
241     fclose(ptr);
242     fclose(fp_ll_dma);
243 
244     return 0;
245 }
246