Home | History | Annotate | Download | only in topazhp
      1 /*
      2  * INTEL CONFIDENTIAL
      3  * Copyright 2007 Intel Corporation. All Rights Reserved.
      4  * Copyright 2005-2007 Imagination Technologies Limited. All Rights Reserved.
      5  *
      6  * The source code contained or described herein and all documents related to
      7  * the source code ("Material") are owned by Intel Corporation or its suppliers
      8  * or licensors. Title to the Material remains with Intel Corporation or its
      9  * suppliers and licensors. The Material may contain trade secrets and
     10  * proprietary and confidential information of Intel Corporation and its
     11  * suppliers and licensors, and is protected by worldwide copyright and trade
     12  * secret laws and treaty provisions. No part of the Material may be used,
     13  * copied, reproduced, modified, published, uploaded, posted, transmitted,
     14  * distributed, or disclosed in any way without Intel's prior express written
     15  * permission.
     16  *
     17  * No license under any patent, copyright, trade secret or other intellectual
     18  * property right is granted to or conferred upon you by disclosure or delivery
     19  * of the Materials, either expressly, by implication, inducement, estoppel or
     20  * otherwise. Any license under such intellectual property rights must be
     21  * express and approved by Intel in writing.
     22  */
     23 
     24 
     25 /*
     26  * Authors:
     27  *    Elaine Wang <zhaohan.ren (at) intel.com>
     28  *
     29  */
     30 
     31 #include <stdio.h>
     32 
     33 #include "JPEGMasterFirmware_bin.h"
     34 
     35 #include "H264MasterFirmware_bin.h"
     36 #include "H264MasterFirmwareCBR_bin.h"
     37 #include "H264MasterFirmwareVBR_bin.h"
     38 #include "H264MasterFirmwareVCM_bin.h"
     39 #include "H264MasterFirmwareLLRC_bin.h"
     40 #include "H264MasterFirmwareALL_bin.h"
     41 
     42 #include "H263MasterFirmware_bin.h"
     43 #include "H263MasterFirmwareCBR_bin.h"
     44 #include "H263MasterFirmwareVBR_bin.h"
     45 //#include "H263MasterFirmwareLLRC_bin.h"
     46 
     47 #include "MPG2MasterFirmware_bin.h"
     48 #include "MPG2MasterFirmwareCBR_bin.h"
     49 #include "MPG2MasterFirmwareVBR_bin.h"
     50 //#include "MPG2MasterFirmwareLLRC_bin.h"
     51 
     52 #include "MPG4MasterFirmware_bin.h"
     53 #include "MPG4MasterFirmwareCBR_bin.h"
     54 #include "MPG4MasterFirmwareVBR_bin.h"
     55 #include "MPG4MasterFirmwareLLRC_bin.h"
     56 
     57 #include "H264MVCMasterFirmware_bin.h"
     58 #include "H264MVCMasterFirmwareCBR_bin.h"
     59 #include "H264MVCMasterFirmwareVBR_bin.h"
     60 #include "H264MVCMasterFirmwareLLRC_bin.h"
     61 
     62 #include "thread0_bin.h"
     63 
     64 #include "Primary_VRL.txt"
     65 
     66 
     67 #define FW_VER 0x5D
     68 #define FW_FILE_NAME_A0 "topazhp_fw.bin"
     69 #define FW_FILE_NAME_B0 "topazhp_fw_b0.bin"
     70 
     71 static const unsigned char pad_val = 0x0;
     72 
     73 
     74 #define FW_MASTER_INFO(codec,prefix) \
     75         { FW_MASTER_##codec,\
     76           { FW_VER,\
     77             FW_MASTER_##codec,\
     78             ui32##prefix##_MasterMTXTOPAZFWTextSize,\
     79             ui32##prefix##_MasterMTXTOPAZFWDataSize,\
     80             ui32##prefix##_MasterMTXTOPAZFWDataOrigin\
     81           },\
     82           aui32##prefix##_MasterMTXTOPAZFWText, aui32##prefix##_MasterMTXTOPAZFWData \
     83         }
     84 
     85 #define FW_SLAVE_INFO(codec,prefix) \
     86         { FW_SLAVE_##codec,\
     87           { FW_VER,\
     88             FW_SLAVE_##codec,\
     89             ui32##prefix##_SlaveMTXTOPAZFWTextSize,\
     90             ui32##prefix##_SlaveMTXTOPAZFWDataSize,\
     91             ui32##prefix##_SlaveMTXTOPAZFWDataOrigin\
     92           },\
     93           aui32##prefix##_SlaveMTXTOPAZFWText, aui32##prefix##_SlaveMTXTOPAZFWData \
     94         }
     95 
     96 struct topaz_fw_info_item_s {
     97     unsigned short ver;
     98     unsigned short codec;
     99 
    100     unsigned int text_size;
    101     unsigned int data_size;
    102     unsigned int data_location;
    103 };
    104 
    105 typedef struct topaz_fw_info_item_s topaz_fw_info_item_t;
    106 
    107 /* Commented out all the SLAVE structure according to DDK */
    108 enum topaz_fw_codec_e {
    109         FW_MASTER_JPEG = 0,                         //!< JPEG
    110         FW_MASTER_H264_NO_RC,           //!< H264 with no rate control
    111         FW_MASTER_H264_VBR,                     //!< H264 variable bitrate
    112         FW_MASTER_H264_CBR,                     //!< H264 constant bitrate
    113         FW_MASTER_H264_VCM,                     //!< H264 video conferance mode
    114         FW_MASTER_H264_LLRC,            //!< H264 low-latency rate control
    115         FW_MASTER_H264ALL,
    116         FW_MASTER_H263_NO_RC,           //!< H263 with no rate control
    117         FW_MASTER_H263_VBR,                     //!< H263 variable bitrate
    118         FW_MASTER_H263_CBR,                     //!< H263 constant bitrate
    119         FW_MASTER_MPEG4_NO_RC,          //!< MPEG4 with no rate control
    120         FW_MASTER_MPEG4_VBR,            //!< MPEG4 variable bitrate
    121         FW_MASTER_MPEG4_CBR,            //!< MPEG4 constant bitrate
    122         FW_MASTER_MPEG2_NO_RC,          //!< MPEG2 with no rate control
    123         FW_MASTER_MPEG2_VBR,            //!< MPEG2 variable bitrate
    124         FW_MASTER_MPEG2_CBR,            //!< MPEG2 constant bitrate
    125         FW_MASTER_H264MVC_NO_RC,        //!< MVC H264 with no rate control
    126         FW_MASTER_H264MVC_CBR,          //!< MVC H264 constant bitrate
    127         FW_MASTER_H264MVC_VBR,          //!< MVC H264 variable bitrate
    128         FW_MASTER_H264MVC_LLRC,         //!< MVC H264 low-latency rate control
    129 	FW_NUM
    130 };
    131 
    132 typedef enum topaz_fw_codec_e topaz_fw_codec_t;
    133 
    134 struct fw_table_s {
    135     topaz_fw_codec_t index;
    136     topaz_fw_info_item_t header;
    137     unsigned int *fw_text;
    138     unsigned int *fw_data;
    139 };
    140 
    141 typedef struct fw_table_s fw_table_t;
    142 
    143 #define SECURE_ALIGN 1
    144 #define B0_ALIGN 4
    145 #define SECURE_VRL_HEADER 728
    146 #define SECURE_FIP_HEADER 296
    147 
    148 struct fw_table_A0 {
    149     unsigned int addr;
    150     unsigned int text_size_bytes;
    151     unsigned int data_size_bytes;
    152     unsigned int data_relocation;
    153 };
    154 
    155 static void create_firmware_A0(fw_table_t *tng_fw_table, FILE *fp)
    156 {
    157     struct fw_table_A0 sec_t[FW_NUM];
    158     const unsigned int ui_secure_align = SECURE_ALIGN - 1;
    159     unsigned int i = 0;
    160     int iter = 0;
    161     int size = 0;
    162 
    163     printf("fm num is %d\n", FW_NUM);
    164     /////////////////////////////////////////////////
    165     size = SECURE_VRL_HEADER + SECURE_FIP_HEADER;
    166 
    167     for (iter = 0; iter < size; iter++) {
    168         fwrite(&pad_val, 1, 1, fp);
    169     }
    170     /////////////////////////////////////////////////
    171     iter = 0;
    172 
    173     sec_t[iter].addr = FW_NUM * 16 + SECURE_VRL_HEADER + SECURE_FIP_HEADER;
    174     sec_t[iter].text_size_bytes = tng_fw_table[iter].header.text_size * 4;
    175     sec_t[iter].data_size_bytes = tng_fw_table[iter].header.data_size * 4;
    176     sec_t[iter].data_relocation = tng_fw_table[iter].header.data_location;
    177     fwrite(&(sec_t[iter]), sizeof(struct fw_table_A0), 1, fp);
    178 
    179     iter = 1;
    180 
    181 
    182     /* write fw table into the file */
    183     while (iter < FW_NUM) {
    184         sec_t[iter - 1].text_size_bytes = (sec_t[iter - 1].text_size_bytes + ui_secure_align) & (~ui_secure_align);
    185         sec_t[iter - 1].data_size_bytes = (sec_t[iter - 1].data_size_bytes + ui_secure_align) & (~ui_secure_align);
    186 
    187         sec_t[iter].addr = sec_t[iter-1].addr + sec_t[iter-1].text_size_bytes + sec_t[iter-1].data_size_bytes;
    188 
    189         sec_t[iter].text_size_bytes = tng_fw_table[iter].header.text_size * 4;
    190         sec_t[iter].data_size_bytes = tng_fw_table[iter].header.data_size * 4;
    191 	sec_t[iter].data_relocation = tng_fw_table[iter].header.data_location;
    192         fwrite(&(sec_t[iter]), sizeof(struct fw_table_A0), 1, fp);
    193         ++iter;
    194     }
    195 
    196     sec_t[iter - 1].text_size_bytes = (sec_t[iter - 1].text_size_bytes + ui_secure_align) & (~ui_secure_align);
    197     sec_t[iter - 1].data_size_bytes = (sec_t[iter - 1].data_size_bytes + ui_secure_align) & (~ui_secure_align);
    198 
    199     iter = 0;
    200     while (iter < FW_NUM) {
    201 
    202         /* write text */
    203         size = tng_fw_table[iter].header.text_size * 4;
    204         fwrite(tng_fw_table[iter].fw_text, 1, size, fp);
    205         for (i = 0; i < (sec_t[iter].text_size_bytes - size); i++)
    206             fwrite(&pad_val, 1, 1, fp);
    207 
    208 
    209         /* write data */
    210         size = tng_fw_table[iter].header.data_size * 4;
    211         fwrite(tng_fw_table[iter].fw_data, 1, size, fp);
    212         for (i = 0; i < (sec_t[iter].data_size_bytes - size); i++)
    213             fwrite(&pad_val, 1, 1, fp);
    214 
    215         fflush(fp);
    216 
    217         ++iter;
    218     }
    219     return ;
    220 }
    221 
    222 struct fw_table_B0 {
    223     unsigned int addr;
    224     unsigned int text_size_dword;
    225     unsigned int data_size_dword;
    226     unsigned int text_size_bytes;
    227 };
    228 
    229 static const char FIP_Header[] = {
    230 	0x24, 0x56, 0x45, 0x43,
    231 	0x01, 0x00, 0x01, 0x00,
    232 	0x4a, 0x00, 0x00, 0x00,
    233 	0x8e, 0x00, 0x00, 0x00,
    234 	0x22, 0x00, 0x9c, 0x00,
    235 	0x0e, 0x00, 0x00, 0x00
    236 };
    237 static void create_firmware_B0(fw_table_t *tng_fw_table, FILE *fp)
    238 {
    239     struct fw_table_B0 sec_t[FW_NUM];
    240     const unsigned int i_align = B0_ALIGN - 1;
    241     const unsigned int data_loco = 0x0ffff;
    242     unsigned int i = 0;
    243     int iter = 0;
    244     int size = 0;
    245 
    246     printf("fm num is %d\n", FW_NUM);
    247     /////////////////////////////////////////////////
    248     size = sizeof(FIP_Header);
    249     fwrite(FIP_Header, size, 1, fp);
    250     printf("FIP header is %d, 296\n", size);
    251 
    252     size = SECURE_FIP_HEADER - sizeof(FIP_Header);
    253     for (iter = 0; iter < size; iter++) {
    254         fwrite(&pad_val, 1, 1, fp);
    255     }
    256     /////////////////////////////////////////////////
    257     iter = 0;
    258 
    259     sec_t[iter].addr = FW_NUM * 16 + SECURE_VRL_HEADER + SECURE_FIP_HEADER;
    260     sec_t[iter].text_size_bytes = tng_fw_table[iter].header.data_location & data_loco;
    261     sec_t[iter].text_size_dword = sec_t[iter].text_size_bytes >> 2;
    262 
    263     sec_t[iter].data_size_dword = (tng_fw_table[iter].header.data_size + i_align) & (~i_align);
    264     fwrite(&(sec_t[iter]), sizeof(struct fw_table_B0), 1, fp);
    265 
    266     iter = 1;
    267 
    268     /* write fw table into the file */
    269     while (iter < FW_NUM) {
    270         sec_t[iter].addr = sec_t[iter-1].addr +
    271 		sec_t[iter-1].text_size_bytes +
    272 		(sec_t[iter-1].data_size_dword << 2);
    273 
    274         sec_t[iter].text_size_bytes = tng_fw_table[iter].header.data_location & data_loco;
    275         sec_t[iter].text_size_dword = sec_t[iter].text_size_bytes >> 2;
    276 
    277         sec_t[iter].data_size_dword = (tng_fw_table[iter].header.data_size + i_align) & (~i_align);
    278         fwrite(&(sec_t[iter]), sizeof(struct fw_table_B0), 1, fp);
    279         ++iter;
    280     }
    281 
    282     iter = 0;
    283     while (iter < FW_NUM) {
    284 
    285         /* write text */
    286         size = tng_fw_table[iter].header.text_size * 4;
    287         fwrite(tng_fw_table[iter].fw_text, 1, size, fp);
    288         for (i = 0; i < (sec_t[iter].text_size_bytes - size); i++)
    289             fwrite(&pad_val, 1, 1, fp);
    290 
    291 
    292         /* write data */
    293         size = tng_fw_table[iter].header.data_size * 4;
    294         fwrite(tng_fw_table[iter].fw_data, 1, size, fp);
    295         for (i = 0; i < ((sec_t[iter].data_size_dword << 2) - size); i++)
    296             fwrite(&pad_val, 1, 1, fp);
    297 
    298         fflush(fp);
    299 
    300         ++iter;
    301     }
    302     return ;
    303 }
    304 
    305 static void normal_firmware(fw_table_t *topaz_fw_table, FILE *fp)
    306 {
    307     unsigned int i = 0;
    308     topaz_fw_codec_t iter = 0;
    309     int size = 0;
    310 
    311     printf("fm num is %d\n", FW_NUM);
    312 
    313     /* write fw table into the file */
    314     while (iter < FW_NUM) {
    315         /* record the size use bytes */
    316         topaz_fw_table[iter].header.data_size *= 4;
    317         topaz_fw_table[iter].header.text_size *= 4;
    318 
    319         /* write header */
    320         fwrite(&(topaz_fw_table[iter].header), sizeof(topaz_fw_table[iter].header), 1, fp);
    321 
    322         /* write text */
    323         size = topaz_fw_table[iter].header.text_size;
    324         fwrite(topaz_fw_table[iter].fw_text, 1, size, fp);
    325 
    326         /* write data */
    327         size = topaz_fw_table[iter].header.data_size;
    328         fwrite(topaz_fw_table[iter].fw_data, 1, size, fp);
    329 
    330         ++iter;
    331     }
    332 }
    333 
    334 
    335 
    336 int main()
    337 {
    338     FILE *fp = NULL;
    339 
    340     fw_table_t topaz_fw_table[] = {
    341         FW_MASTER_INFO(JPEG, JPEG),	//FW_MASTER_JPEG = 0,                         //!< JPEG
    342         FW_MASTER_INFO(H264_NO_RC, H264),//FW_MASTER_H264_NO_RC,           //!< H264 with no rate control
    343         FW_MASTER_INFO(H264_VBR, H264VBR),//FW_MASTER_H264_VBR,                     //!< H264 variable bitrate
    344         FW_MASTER_INFO(H264_CBR, H264CBR),//FW_MASTER_H264_CBR,                     //!< H264 constant bitrate
    345         FW_MASTER_INFO(H264_VCM, H264VCM),//FW_MASTER_H264_VCM,                     //!< H264 video conferance mode
    346         FW_MASTER_INFO(H264_LLRC, H264LLRC),//FW_MASTER_H264_LLRC,            //!< H264 low-latency rate control
    347         FW_MASTER_INFO(H264ALL, H264ALL),
    348         FW_MASTER_INFO(H263_NO_RC, H263),//FW_MASTER_H263_NO_RC,           //!< H263 with no rate control
    349         FW_MASTER_INFO(H263_VBR, H263VBR),//FW_MASTER_H263_VBR,                     //!< H263 variable bitrate
    350         FW_MASTER_INFO(H263_CBR, H263CBR),//FW_MASTER_H263_CBR,                     //!< H263 constant bitrate
    351         FW_MASTER_INFO(MPEG4_NO_RC, MPG4),//FW_MASTER_MPEG4_NO_RC,          //!< MPEG4 with no rate control
    352         FW_MASTER_INFO(MPEG4_VBR, MPG4VBR),//FW_MASTER_MPEG4_VBR,            //!< MPEG4 variable bitrate
    353         FW_MASTER_INFO(MPEG4_CBR, MPG4CBR),//FW_MASTER_MPEG4_CBR,            //!< MPEG4 constant bitrate
    354         FW_MASTER_INFO(MPEG2_NO_RC, MPG2),//FW_MASTER_MPEG2_NO_RC,          //!< MPEG2 with no rate control
    355         FW_MASTER_INFO(MPEG2_VBR, MPG2VBR),//FW_MASTER_MPEG2_VBR,            //!< MPEG2 variable bitrate
    356         FW_MASTER_INFO(MPEG2_CBR, MPG2CBR),//FW_MASTER_MPEG2_CBR,            //!< MPEG2 constant bitrate
    357         FW_MASTER_INFO(H264MVC_NO_RC, H264MVC),//FW_MASTER_H264MVC_NO_RC,        //!< MVC H264 with no rate control
    358         FW_MASTER_INFO(H264MVC_CBR, H264MVCCBR),//FW_MASTER_H264MVC_CBR,          //!< MVC H264 constant bitrate
    359         FW_MASTER_INFO(H264MVC_VBR, H264MVCVBR),//FW_MASTER_H264MVC_VBR,          //!< MVC H264 variable bitrate
    360         FW_MASTER_INFO(H264MVC_LLRC, H264MVCLLRC),//FW_MASTER_H264MVC_LLRC,         //!< MVC H264 low-latency rate control
    361     };
    362 
    363 #ifdef B0_DEBUG
    364     printf("fw_num is %d, fw = %d\n", FW_NUM, (int)sizeof(topaz_fw_table));
    365     for(i = 0; i < FW_NUM; i++) {
    366         topaz_fw_table[i].index = i;
    367         topaz_fw_table[i].header.ver = FW_VER;
    368         topaz_fw_table[i].header.codec = FW_MASTER_H264_NO_RC;
    369         topaz_fw_table[i].header.text_size = 6883;
    370         topaz_fw_table[i].header.data_size = 2997;
    371         topaz_fw_table[i].header.data_location = 0x82886b90;
    372         topaz_fw_table[i].fw_text = aui32H264_MasterMTXTOPAZFWText;
    373         topaz_fw_table[i].fw_data = aui32H264_MasterMTXTOPAZFWData;
    374     }
    375 #endif
    376 
    377     /* open file  */
    378     fp = fopen(FW_FILE_NAME_A0, "w");
    379 
    380     if (NULL == fp)
    381         return -1;
    382 
    383     create_firmware_A0(topaz_fw_table, fp);
    384 
    385     /* close file */
    386     fclose(fp);
    387 
    388     fp = fopen(FW_FILE_NAME_B0, "w");
    389 
    390     if (NULL == fp)
    391         return -1;
    392 
    393     create_firmware_B0(topaz_fw_table, fp);
    394 
    395     /* close file */
    396     fclose(fp);
    397 
    398     return 0;
    399 }
    400