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     unsigned long lseek;
56     FILE *ptr = NULL;
57     FILE *fp_ll_dma = NULL;
58     struct msvdx_fw fw;
59     FIRMWARE fw_DE3;
60 
61     fw_DE3 = sFirmware1366_FS; /* VXD3xx_DEVA_DDK_3_0_5 */
62     fw_DE3 = sFirmware1366_SS; /* VXD3xx_DEVA_DDK_3_0_5 */
63     fw_DE3 = sFirmware1419_FS; /* VXD3xx_DEVA_DDK_3_1_2 */
64     fw_DE3 = sFirmware_FS; /* VXD3xx_DEVA_DDK_3_2_4 */
65     fw_DE3 = sFirmware_SS; /* VXD3xx_DEVA_DDK_3_2_4 */
66     //fw_DE3 = sFirmware0000_SS; /* 1366based, for VP only, be able to disable WDT in Csim */
67     fw_DE3 = sFirmware_SS_DE3_3_20;
68     //fw_DE3 = sFirmware_SS_1472_3_8;
69     fw_DE3 = sFirmware_SS_1472_3_10;
70     fw_DE3 = sFirmware_1472_3_20_SS;
71 
72     fw.ver = 0x0496;
73     fw.text_size = fw_DE3.uiTextSize / 4;
74     fw.data_size = fw_DE3.uiDataSize / 4;;
75     fw.data_location = fw_DE3.DataOffset + 0x82880000;
76 
77     ptr = fopen("msvdx_fw_mfld_DE2.0.bin", "w");
78     if (ptr == NULL) {
79         fprintf(stderr, "Create msvdx_fw_mfld_DE2.0.bin failed\n");
80         exit(-1);
81     }
82     fwrite(&fw, sizeof(fw), 1, ptr);
83 
84     for (i = 0; i < fw.text_size; i++) {
85         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
86     }
87     for (i = 0; i < fw.data_size; i++) {
88         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
89     }
90     fclose(ptr);
91 
92     /* Create stitch image of msvdx fw */
93     ptr = fopen("unsigned_msvdx_fw.bin", "w");
94     if (ptr == NULL) {
95         fprintf(stderr, "Create unsigned_msvdx_fw failed\n");
96         exit(-1);
97     }
98     fp_ll_dma = fopen("linked_list_struct", "r");
99     if (fp_ll_dma == NULL) {
100         fprintf(stderr, "Cannot open linked_list_struct failed %d\n", __LINE__);
101         exit(-1);
102     }
103 
104     unsigned int buf[(MTX_SIZE + sizeof(fw))/4];
105     fread(buf, 1, LINKED_LIST_SIZE, fp_ll_dma);
106     fwrite(buf, 1, LINKED_LIST_SIZE, ptr);
107 
108     memset(buf, UNINITILISE_MEM, MTX_SIZE + sizeof(fw));
109     buf[((MTX_SIZE + sizeof(fw))/4) - 1] = STACKGUARDWORD;
110 
111     fwrite(buf, 1, MTX_SIZE + sizeof(fw), ptr);
112 
113     fseek(ptr, LINKED_LIST_SIZE, SEEK_SET);
114     fwrite(&fw, sizeof(fw), 1, ptr);
115 
116     for (i = 0; i < fw.text_size; i++) {
117         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
118     }
119 
120     fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
121 
122     for (i = 0; i < fw.data_size; i++) {
123         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
124     }
125     fclose(ptr);
126     fclose(fp_ll_dma);
127 
128     /* Create stitch image of 56k msvdx fw */
129     ptr = fopen("unsigned_msvdx_fw_56k.bin", "w");
130     if (ptr == NULL) {
131         fprintf(stderr, "Create unsigned_msvdx_fw failed\n");
132         exit(-1);
133     }
134     fp_ll_dma = fopen("linked_list_struct_56k", "r");
135     if (fp_ll_dma == NULL) {
136         fprintf(stderr, "Cannot open linked_list_sturct_56k failed\n");
137         exit(-1);
138     }
139 
140     unsigned int buf1[(MTX_SIZE1 + sizeof(fw))/4];
141     fread(buf1, 1, LINKED_LIST_SIZE, fp_ll_dma);
142     fwrite(buf1, 1, LINKED_LIST_SIZE, ptr);
143 
144     memset(buf1, UNINITILISE_MEM, MTX_SIZE1 + sizeof(fw));
145     buf1[((MTX_SIZE1 + sizeof(fw))/4) - 1] = STACKGUARDWORD;
146 
147     fwrite(buf1, 1, MTX_SIZE1 + sizeof(fw), ptr);
148 
149     fseek(ptr, LINKED_LIST_SIZE, SEEK_SET);
150     fwrite(&fw, sizeof(fw), 1, ptr);
151 
152     for (i = 0; i < fw.text_size; i++) {
153         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
154     }
155 
156     fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
157 
158     for (i = 0; i < fw.data_size; i++) {
159         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
160     }
161     fclose(ptr);
162     fclose(fp_ll_dma);
163 
164     /* Create mrfl unsigned image */
165     ptr = fopen("unsigned_msvdx_fw_mrfl.bin", "w");
166     if (ptr == NULL) {
167         fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n");
168         exit(-1);
169     }
170     fp_ll_dma = fopen("linked_list_struct_mrfld", "r");
171     if (fp_ll_dma == NULL) {
172         fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n");
173         exit(-1);
174     }
175 
176     unsigned int buf2[MTX_SIZE3];
177     unsigned char FIP_HEADER[FIP_SIZE];
178     int fw_size = (MTX_SIZE3 - LINKED_LIST_SIZE);
179 
180     memset(FIP_HEADER, 0, FIP_SIZE);
181     fwrite(FIP_HEADER, 1, FIP_SIZE, ptr);
182 
183     fread(buf2, 1, LINKED_LIST_SIZE, fp_ll_dma);
184 
185     fwrite(buf2, 1, LINKED_LIST_SIZE, ptr);
186 
187     memset(buf2, UNINITILISE_MEM, fw_size);
188     buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD;
189 
190     fwrite(buf2, 1, fw_size, ptr);
191 
192     fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET);
193     //fwrite(&fw, sizeof(fw), 1, ptr);
194 
195     for (i = 0; i < fw.text_size; i++) {
196         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
197     }
198 
199     //fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET);
200     fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET);
201 
202     for (i = 0; i < fw.data_size; i++) {
203         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
204     }
205     fclose(ptr);
206     fclose(fp_ll_dma);
207 
208     /* Create mrfl unsigned image 56k */
209     ptr = fopen("unsigned_msvdx_fw_mrfl_56k.bin", "w");
210     if (ptr == NULL) {
211         fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n");
212         exit(-1);
213     }
214     fp_ll_dma = fopen("FIP_Constant_linkedlist", "r");
215     if (fp_ll_dma == NULL) {
216         fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n");
217         exit(-1);
218     }
219 
220     unsigned int buf3[MTX_SIZE4];
221     fw_size = (MTX_SIZE4);
222 
223     fread(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, fp_ll_dma);
224     fwrite(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, ptr);
225 
226     memset(buf3, UNINITILISE_MEM, fw_size);
227     buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD;
228 
229     fwrite(buf2, 1, fw_size, ptr);
230 
231     fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET);
232 
233     for (i = 0; i < fw.text_size; i++) {
234         fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr);
235     }
236 
237     fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET);
238 
239     for (i = 0; i < fw.data_size; i++) {
240         fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr);
241     }
242     fclose(ptr);
243     fclose(fp_ll_dma);
244 
245     return 0;
246 }
247