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
26
27
28
29/*
30 * Authors:
31 *    Shengquan Yuan  <shengquan.yuan@intel.com>
32 *    Fei Jiang  <fei.jiang@intel.com>
33 *
34 */
35
36#include <stdio.h>
37#define TOPAZ_FW_FILE_NAME_ANDROID "/etc/firmware/topaz_fw.bin"
38#define MSVDX_FW_FILE_NAME_ANDROID "/etc/firmware/msvdx_fw.bin"
39
40#define TOPAZ_FW_FILE_NAME_MEEGO "/lib/firmware/topaz_fw.bin"
41#define MSVDX_FW_FILE_NAME_MEEGO "/lib/firmware/msvdx_fw.bin"
42
43struct topaz_fw_info_item_s {
44    unsigned short ver;
45    unsigned short codec;
46
47    unsigned int  text_size;
48    unsigned int data_size;
49    unsigned int data_location;
50};
51typedef struct topaz_fw_info_item_s topaz_fw_info_item_t;
52
53enum topaz_fw_codec_e {
54    FW_JPEG = 0,
55    FW_H264_NO_RC,
56    FW_H264_VBR,
57    FW_H264_CBR,
58    FW_H264_VCM,
59    FW_H263_NO_RC,
60    FW_H263_VBR,
61    FW_H263_CBR,
62    FW_MPEG4_NO_RC,
63    FW_MPEG4_VBR,
64    FW_MPEG4_CBR,
65    FW_NUM
66};
67typedef enum topaz_fw_codec_e topaz_fw_codec_t;
68
69struct fw_table_s {
70    topaz_fw_codec_t index;
71    topaz_fw_info_item_t header;
72    //  unsigned int *fw_text;
73    //  unsigned int *fw_data;
74};
75typedef struct fw_table_s fw_table_t;
76
77
78struct msvdx_fw {
79    unsigned int ver;
80    unsigned int  text_size;
81    unsigned int data_size;
82    unsigned int data_location;
83};
84
85
86static char *codec_to_string(int codec)
87{
88    switch (codec) {
89    case FW_H264_NO_RC:
90        return "H264_NO_RC";
91    case FW_H264_VBR:
92        return "H264_VBR";
93    case FW_H264_CBR:
94        return "H264_CBR";
95    case FW_H264_VCM:
96        return "H264_VCM";
97    case FW_H263_NO_RC:
98        return "H263_NO_RC";
99    case FW_H263_VBR:
100        return "H263_VBR";
101    case FW_H263_CBR:
102        return "H263_CBR";
103    case FW_MPEG4_NO_RC:
104        return "MPEG4_NO_RC";
105    case FW_MPEG4_VBR:
106        return "MPEG4_VBR";
107    case FW_MPEG4_CBR:
108        return "MPEG4_CBR";
109    default:
110        return "Undefined codec";
111    }
112    return "";
113}
114
115int main()
116{
117    FILE *fp = NULL;
118    topaz_fw_codec_t iter = FW_H264_NO_RC;
119    //  unsigned int read_data;
120    unsigned int lseek;
121    unsigned char system_id = 0;
122    fw_table_t topaz_fw_table[FW_NUM + 1];
123    struct msvdx_fw fw;
124
125
126    /* open file
127     * RRRdetermine Android or Meego
128     * system_id = 0  Android
129     * system_id = 1  Meego
130     */
131    fp = fopen(TOPAZ_FW_FILE_NAME_ANDROID, "r");
132
133    if (NULL == fp) {
134        fp = fopen(TOPAZ_FW_FILE_NAME_MEEGO, "r");
135        if (NULL == fp) {
136            printf("\nSystem isn't Android or Meego\n\n");
137            printf("\nCan't open topaz_fw.bin\n");
138            return -1;
139        }
140        system_id = 1;
141        printf("\nSystem is Meego\n\n");
142    } else {
143        printf("\nSystem is Android\n\n");
144    }
145
146    //  fseek (fp, 0, SEEK_SET);
147
148    printf("topza:Try to read and print topaz_fw_table...\n\n\n\n");
149
150    /* read fw table into the topz_fw_table */
151    while (iter < FW_NUM) {
152
153        /* read header */
154        fread(&(topaz_fw_table[iter].header), sizeof(topaz_fw_table[iter].header), 1, fp);
155
156        /* print header */
157        printf("topaz: index          : %s\n", codec_to_string(topaz_fw_table[iter].header.codec));
158        printf("topaz: ver            : 0x%04x\n", topaz_fw_table[iter].header.ver);
159        printf("topaz: Codec          : %s\n", codec_to_string(topaz_fw_table[iter].header.codec));
160        printf("topaz: text_size      : %d\n", (topaz_fw_table[iter].header.text_size >> 2));
161        printf("topaz: data_size      : %d\n", (topaz_fw_table[iter].header.data_size >> 2));
162        printf("topaz: data_location  : 0x%08x\n\n", topaz_fw_table[iter].header.data_location);
163
164        fseek(fp, topaz_fw_table[iter].header.text_size + topaz_fw_table[iter].header.data_size, SEEK_CUR);
165#if 0
166        /* read and print fw_text */
167        printf("fw_text = {\n");
168        for (i = 0; i < (topaz_fw_table[iter].header.text_size >> 2); i++) {
169            fread(&read_data, 1, 4, fp);
170            printf("            0x%08x\n", read_data);
171        }
172        printf("          }\n\n\n\n");
173
174        /* read and print fw_data */
175        printf("fw_data = {\n");
176        for (i = 0; i < (topaz_fw_table[iter].header.data_size >> 2); i++) {
177            fread(&read_data, 1, 4, fp);
178            printf("            0x%08x\n", read_data);
179        }
180        printf("          }\n\n\n\n");
181#endif
182
183        ++iter;
184    }
185
186    /* close topaz_fw.bin file */
187    fclose(fp);
188
189    printf("\n\n\n\nmsvdx:Try to read and print msvdx_fw...\n\n\n\n");
190
191    /* open msvdx_fw.bin */
192    if (system_id == 0) {
193        fp = fopen(MSVDX_FW_FILE_NAME_ANDROID, "r");
194    } else {
195        fp = fopen(MSVDX_FW_FILE_NAME_MEEGO, "r");
196    }
197    if (NULL == fp) {
198        printf("Can't open msvdx_fw.bin\n");
199        return -1;
200    }
201
202    //  fseek (fp, 0, SEEK_SET);
203
204    /*read and print fw*/
205    fread(&fw, sizeof(fw), 1, fp);
206
207    printf("msvdx slice switch firmware: ver            : 0x%04x\n", fw.ver);
208    printf("msvdx slice switch firmware: text_size      : %d\n", fw.text_size);
209    printf("msvdx slice switch firmware: data_size      : %d\n", fw.data_size);
210    printf("msvdx slice switch firmware: data_location  : 0x%08x\n\n", fw.data_location);
211
212    lseek = ((sizeof(fw) + (fw.text_size + fw.data_size) * 4 + 0xfff) & ~0xfff);
213    fseek(fp, lseek, SEEK_SET);
214
215    /*read and print fw*/
216    fread(&fw, sizeof(fw), 1, fp);
217
218    printf("msvdx frame switch firmware: ver            : 0x%04x\n", fw.ver);
219    printf("msvdx frame switch firmware: text_size      : %d\n", fw.text_size);
220    printf("msvdx frame switch firmware: data_size      : %d\n", fw.data_size);
221    printf("msvdx frame switch firmware: data_location  : 0x%08x\n\n", fw.data_location);
222
223    /* close msvdx_fw.bin file */
224    fclose(fp);
225
226    return 0;
227}
228
229
230
231