summaryrefslogtreecommitdiff
path: root/fw/fwinfo.c
blob: 4cdd0574fe6c31cb5d14b46f45db57a14f507e68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
 * Copyright (c) Imagination Technologies Limited, UK
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */




/*
 * Authors:
 *    Shengquan Yuan  <shengquan.yuan@intel.com>
 *    Fei Jiang  <fei.jiang@intel.com>
 *
 */

#include <stdio.h>
#define TOPAZ_FW_FILE_NAME_ANDROID "/etc/firmware/topaz_fw.bin"
#define MSVDX_FW_FILE_NAME_ANDROID "/etc/firmware/msvdx_fw.bin"

#define TOPAZ_FW_FILE_NAME_MEEGO "/lib/firmware/topaz_fw.bin"
#define MSVDX_FW_FILE_NAME_MEEGO "/lib/firmware/msvdx_fw.bin"

struct topaz_fw_info_item_s {
    unsigned short ver;
    unsigned short codec;

    unsigned int  text_size;
    unsigned int data_size;
    unsigned int data_location;
};
typedef struct topaz_fw_info_item_s topaz_fw_info_item_t;

enum topaz_fw_codec_e {
    FW_JPEG = 0,
    FW_H264_NO_RC,
    FW_H264_VBR,
    FW_H264_CBR,
    FW_H264_VCM,
    FW_H263_NO_RC,
    FW_H263_VBR,
    FW_H263_CBR,
    FW_MPEG4_NO_RC,
    FW_MPEG4_VBR,
    FW_MPEG4_CBR,
    FW_NUM
};
typedef enum topaz_fw_codec_e topaz_fw_codec_t;

struct fw_table_s {
    topaz_fw_codec_t index;
    topaz_fw_info_item_t header;
    //  unsigned long *fw_text;
    //  unsigned long *fw_data;
};
typedef struct fw_table_s fw_table_t;


struct msvdx_fw {
    unsigned int ver;
    unsigned int  text_size;
    unsigned int data_size;
    unsigned int data_location;
};


static char *codec_to_string(int codec)
{
    switch (codec) {
    case FW_H264_NO_RC:
        return "H264_NO_RC";
    case FW_H264_VBR:
        return "H264_VBR";
    case FW_H264_CBR:
        return "H264_CBR";
    case FW_H264_VCM:
        return "H264_VCM";
    case FW_H263_NO_RC:
        return "H263_NO_RC";
    case FW_H263_VBR:
        return "H263_VBR";
    case FW_H263_CBR:
        return "H263_CBR";
    case FW_MPEG4_NO_RC:
        return "MPEG4_NO_RC";
    case FW_MPEG4_VBR:
        return "MPEG4_VBR";
    case FW_MPEG4_CBR:
        return "MPEG4_CBR";
    default:
        return "Undefined codec";
    }
    return "";
}

int main()
{
    FILE *fp = NULL;
    topaz_fw_codec_t iter = FW_H264_NO_RC;
    //  unsigned int read_data;
    unsigned int i, lseek;
    unsigned char system_id = 0;
    fw_table_t topaz_fw_table[FW_NUM + 1];
    struct msvdx_fw fw;


    /* open file
     * RRRdetermine Android or Meego
     * system_id = 0  Android
     * system_id = 1  Meego
     */
    fp = fopen(TOPAZ_FW_FILE_NAME_ANDROID, "r");

    if (NULL == fp) {
        fp = fopen(TOPAZ_FW_FILE_NAME_MEEGO, "r");
        if (NULL == fp) {
            printf("\nSystem isn't Android or Meego\n\n");
            printf("\nCan't open topaz_fw.bin\n");
            return -1;
        }
        system_id = 1;
        printf("\nSystem is Meego\n\n");
    } else {
        printf("\nSystem is Android\n\n");
    }

    //  fseek (fp, 0, SEEK_SET);

    printf("topza:Try to read and print topaz_fw_table...\n\n\n\n");

    /* read fw table into the topz_fw_table */
    while (iter < FW_NUM) {

        /* read header */
        fread(&(topaz_fw_table[iter].header), sizeof(topaz_fw_table[iter].header), 1, fp);

        /* print header */
        printf("topaz: index          : %s\n", codec_to_string(topaz_fw_table[iter].header.codec));
        printf("topaz: ver            : 0x%04x\n", topaz_fw_table[iter].header.ver);
        printf("topaz: Codec          : %s\n", codec_to_string(topaz_fw_table[iter].header.codec));
        printf("topaz: text_size      : %d\n", (topaz_fw_table[iter].header.text_size >> 2));
        printf("topaz: data_size      : %d\n", (topaz_fw_table[iter].header.data_size >> 2));
        printf("topaz: data_location  : 0x%08x\n\n", topaz_fw_table[iter].header.data_location);

        fseek(fp, topaz_fw_table[iter].header.text_size + topaz_fw_table[iter].header.data_size, SEEK_CUR);
#if 0
        /* read and print fw_text */
        printf("fw_text = {\n");
        for (i = 0; i < (topaz_fw_table[iter].header.text_size >> 2); i++) {
            fread(&read_data, 1, 4, fp);
            printf("            0x%08x\n", read_data);
        }
        printf("          }\n\n\n\n");

        /* read and print fw_data */
        printf("fw_data = {\n");
        for (i = 0; i < (topaz_fw_table[iter].header.data_size >> 2); i++) {
            fread(&read_data, 1, 4, fp);
            printf("            0x%08x\n", read_data);
        }
        printf("          }\n\n\n\n");
#endif

        ++iter;
    }

    /* close topaz_fw.bin file */
    fclose(fp);

    printf("\n\n\n\nmsvdx:Try to read and print msvdx_fw...\n\n\n\n");

    /* open msvdx_fw.bin */
    if (system_id == 0) {
        fp = fopen(MSVDX_FW_FILE_NAME_ANDROID, "r");
    } else {
        fp = fopen(MSVDX_FW_FILE_NAME_MEEGO, "r");
    }
    if (NULL == fp) {
        printf("Can't open msvdx_fw.bin\n");
        return -1;
    }

    //  fseek (fp, 0, SEEK_SET);

    /*read and print fw*/
    fread(&fw, sizeof(fw), 1, fp);

    printf("msvdx slice switch firmware: ver            : 0x%04x\n", fw.ver);
    printf("msvdx slice switch firmware: text_size      : %d\n", fw.text_size);
    printf("msvdx slice switch firmware: data_size      : %d\n", fw.data_size);
    printf("msvdx slice switch firmware: data_location  : 0x%08x\n\n", fw.data_location);

    lseek = ((sizeof(fw) + (fw.text_size + fw.data_size) * 4 + 0xfff) & ~0xfff);
    fseek(fp, lseek, SEEK_SET);

    /*read and print fw*/
    fread(&fw, sizeof(fw), 1, fp);

    printf("msvdx frame switch firmware: ver            : 0x%04x\n", fw.ver);
    printf("msvdx frame switch firmware: text_size      : %d\n", fw.text_size);
    printf("msvdx frame switch firmware: data_size      : %d\n", fw.data_size);
    printf("msvdx frame switch firmware: data_location  : 0x%08x\n\n", fw.data_location);

    /* close msvdx_fw.bin file */
    fclose(fp);

    return 0;
}