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 (at) 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 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 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 162 /* Create mrfl unsigned image */ 163 ptr = fopen("unsigned_msvdx_fw_mrfl.bin", "w"); 164 if (ptr == NULL) { 165 fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n"); 166 exit(-1); 167 } 168 fp_ll_dma = fopen("linked_list_struct_mrfld", "r"); 169 if (fp_ll_dma == NULL) { 170 fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n"); 171 exit(-1); 172 } 173 174 unsigned int buf2[MTX_SIZE3]; 175 unsigned char FIP_HEADER[FIP_SIZE]; 176 int fw_size = (MTX_SIZE3 - LINKED_LIST_SIZE); 177 178 memset(FIP_HEADER, 0, FIP_SIZE); 179 fwrite(FIP_HEADER, 1, FIP_SIZE, ptr); 180 181 fread(buf2, 1, LINKED_LIST_SIZE, fp_ll_dma); 182 183 fwrite(buf2, 1, LINKED_LIST_SIZE, ptr); 184 185 memset(buf2, UNINITILISE_MEM, fw_size); 186 buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD; 187 188 fwrite(buf2, 1, fw_size, ptr); 189 190 fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET); 191 //fwrite(&fw, sizeof(fw), 1, ptr); 192 193 for (i = 0; i < fw.text_size; i++) { 194 fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr); 195 } 196 197 //fseek(ptr, LINKED_LIST_SIZE + fw_DE3.DataOffset + sizeof(fw), SEEK_SET); 198 fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET); 199 200 for (i = 0; i < fw.data_size; i++) { 201 fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr); 202 } 203 fclose(ptr); 204 205 /* Create mrfl unsigned image 56k */ 206 ptr = fopen("unsigned_msvdx_fw_mrfl_56k.bin", "w"); 207 if (ptr == NULL) { 208 fprintf(stderr, "Create unsigned_msvdx_fw_mrfl.bin failed\n"); 209 exit(-1); 210 } 211 fp_ll_dma = fopen("FIP_Constant_linkedlist", "r"); 212 if (fp_ll_dma == NULL) { 213 fprintf(stderr, "Cannot open linked_list_sturct_mrfld failed\n"); 214 exit(-1); 215 } 216 217 unsigned int buf3[MTX_SIZE4]; 218 fw_size = (MTX_SIZE4); 219 220 fread(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, fp_ll_dma); 221 fwrite(buf3, 1, LINKED_LIST_SIZE + FIP_SIZE, ptr); 222 223 memset(buf3, UNINITILISE_MEM, fw_size); 224 buf2[fw_size/sizeof(unsigned int) - 1] = STACKGUARDWORD; 225 226 fwrite(buf2, 1, fw_size, ptr); 227 228 fseek(ptr, LINKED_LIST_SIZE + FIP_SIZE, SEEK_SET); 229 230 for (i = 0; i < fw.text_size; i++) { 231 fwrite(&fw_DE3.pui8Text[i*4], 4, 1, ptr); 232 } 233 234 fseek(ptr, FIP_SIZE + LINKED_LIST_SIZE + fw_DE3.DataOffset, SEEK_SET); 235 236 for (i = 0; i < fw.data_size; i++) { 237 fwrite(&fw_DE3.pui8Data[i*4], 4, 1, ptr); 238 } 239 fclose(ptr); 240 241 return 0; 242 } 243