huangcm
2024-09-30 df6679f4a364cf78b2a2ebeceecb7f62994725e2
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * (C) Copyright 2012
 *     wangflord@allwinnertech.com
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program;
 *
 */
#ifndef  __boot0_v2_h
#define  __boot0_v2_h
 
#define STAMP_VALUE                     0x5F0A6C39
 
 
typedef struct
{
   unsigned int        ChannelCnt;
   unsigned int        ChipCnt;                            //the count of the total nand flash chips are currently connecting on the CE pin
    unsigned int       ChipConnectInfo;                    //chip connect information, bit == 1 means there is a chip connecting on the CE pin
   unsigned int        RbCnt;
   unsigned int        RbConnectInfo;                        //the connect  information of the all rb  chips are connected
    unsigned int        RbConnectMode;                        //the rb connect  mode
   unsigned int        BankCntPerChip;                     //the count of the banks in one nand chip, multiple banks can support Inter-Leave
    unsigned int        DieCntPerChip;                      //the count of the dies in one nand chip, block management is based on Die
    unsigned int        PlaneCntPerDie;                     //the count of planes in one die, multiple planes can support multi-plane operation
    unsigned int        SectorCntPerPage;                   //the count of sectors in one single physic page, one sector is 0.5k
    unsigned int       PageCntPerPhyBlk;                   //the count of physic pages in one physic block
    unsigned int       BlkCntPerDie;                       //the count of the physic blocks in one die, include valid block and invalid block
    unsigned int       OperationOpt;                       //the mask of the operation types which current nand flash can support support
    unsigned int        FrequencePar;                       //the parameter of the hardware access clock, based on 'MHz'
    unsigned int        EccMode;                            //the Ecc Mode for the nand flash chip, 0: bch-16, 1:bch-28, 2:bch_32
    unsigned char       NandChipId[8];                      //the nand chip id of current connecting nand chip
    unsigned int       ValidBlkRatio;                      //the ratio of the valid physical blocks, based on 1024
   unsigned int         good_block_ratio;                    //good block ratio get from hwscan
   unsigned int        ReadRetryType;                        //the read retry type
   unsigned int       DDRType;
   unsigned int        Reserved[32];
}boot_nand_para_t0;
 
 
//通用的,和GPIO相关的数据结构
typedef struct _normal_gpio_cfg
{
    unsigned char      port;                       //端口号
    unsigned char      port_num;                   //端口内编号
    char      mul_sel;                    //功能编号
    char      pull;                       //电阻状态
    char      drv_level;                  //驱动驱动能力
    char      data;                       //输出电平
    unsigned char      reserved[2];                //保留位,保证对齐
}normal_gpio_cfg;
 
/******************************************************************************/
/*                              file head of Boot0                            */
/******************************************************************************/
typedef struct _boot0_private_head_t
{
   unsigned int            prvt_head_size;
   char                    prvt_head_vsn[4];       // the version of boot0_private_head_t
   unsigned int            dram_para[32];          // DRAM patameters for initialising dram. Original values is arbitrary,
   int                        uart_port;              // UART控制器编号
   normal_gpio_cfg         uart_ctrl[2];           // UART控制器(调试打印口)数据信息
   int                     enable_jtag;            // 1 : enable,  0 : disable
    normal_gpio_cfg            jtag_gpio[5];           // 保存JTAG的全部GPIO信息
    normal_gpio_cfg         storage_gpio[32];       // 存储设备 GPIO信息
    char                    storage_data[512 - sizeof(normal_gpio_cfg) * 32];      // 用户保留数据信息
    //boot_nand_connect_info_t    nand_connect_info;
}boot0_private_head_t;
 
 
typedef struct standard_Boot_file_head
{
   unsigned int  jump_instruction;   // one intruction jumping to real code
   unsigned char   magic[8];           // ="eGON.BT0" or "eGON.BT1",  not C-style string.
   unsigned int  check_sum;          // generated by PC
   unsigned int  length;             // generated by PC
   unsigned int  pub_head_size;      // the size of boot_file_head_t
   unsigned char   pub_head_vsn[4];    // the version of boot_file_head_t
   unsigned char   file_head_vsn[4];   // the version of boot0_file_head_t or boot1_file_head_t
   unsigned char   Boot_vsn[4];        // Boot version
   unsigned char   eGON_vsn[4];        // eGON version
   unsigned char   platform[8];        // platform information
}standard_boot_file_head_t;
 
 
typedef struct _boot0_file_head_t
{
   standard_boot_file_head_t   boot_head;
   boot0_private_head_t          prvt_head;
}boot0_file_head_t;
 
 
 
 
 
 
#endif     //  ifndef __boot0_h
 
/* end of boot0.h */
 
typedef struct _boot_core_para_t
{
    unsigned int  user_set_clock;                 // 运行频率 M单位
    unsigned int  user_set_core_vol;              // 核心电压 mV单位
    unsigned int  vol_threshold;                  // 开机门限电压
}boot_core_para_t;
 
 
#ifndef  __uboot_h
#define  __uboot_h
 
/******************************************************************************/
/*                              file head of Boot2.0-uboot                          */
/******************************************************************************/
typedef struct _uboot_private_head_t
{
   unsigned int                dram_para[32];
   int                            run_clock;                // Mhz
   int                            run_core_vol;            // mV
   int                            uart_port;              // UART控制器编号
   normal_gpio_cfg             uart_gpio[2];           // UART控制器(调试打印口)GPIO信息
   int                            twi_port;               // TWI控制器编号
   normal_gpio_cfg             twi_gpio[2];            // TWI控制器GPIO信息,用于控制TWI
   int                            work_mode;              // 工作模式
    int                         storage_type;           // 存储介质类型  0:nand   1:sdcard    2: spinor
    normal_gpio_cfg             nand_gpio[32];          // nand GPIO信息
    char                        nand_spare_data[256];    // nand 额外信息
    normal_gpio_cfg             sdcard_gpio[32];        // sdcard GPIO信息
    char                         sdcard_spare_data[256];    // sdcard 额外信息
    int                         secureos_exist;
    uint                        uboot_start_sector_in_mmc;
    int                            reserved[4];            // 保留数据位, 256bytes align
}uboot_private_head_t;
 
typedef struct _uBoot_file_head
{
   unsigned int  jump_instruction;   // one intruction jumping to real code
   unsigned char magic[8];  // ="u-boot"
   unsigned int  check_sum;          // generated by PC
   unsigned int  align_size;          // align size in byte
   unsigned int  length;             // the size of all file
   unsigned int  uboot_length;       // the size of uboot
   unsigned char version[8];         // uboot version
   unsigned char platform[8];        // platform information
   int           reserved[1];        //stamp space, 16bytes align
}uboot_file_head;
 
 
typedef struct _uboot_file_head_t
{
   uboot_file_head      boot_head;
   uboot_private_head_t  prvt_head;
}uboot_file_head_t;
 
#endif     //  ifndef __uboot_h
 
/* end of uboot.h */
 
 
#ifndef  __boot1_h
#define  __boot1_h
/******************************************************************************/
/*                              file head of Boot1.0-boot1                    */
/******************************************************************************/
typedef struct _boot_dram_para_t
{
    __u32           dram_baseaddr;
    __u32           dram_clk;
    __u32           dram_type;
    __u32           dram_rank_num;
    __u32           dram_chip_density;
    __u32           dram_io_width;
    __u32            dram_bus_width;
    __u32           dram_cas;
    __u32           dram_zq;
    __u32           dram_odt_en;
    __u32             dram_size;
    __u32           dram_tpr0;
    __u32           dram_tpr1;
    __u32           dram_tpr2;
    __u32           dram_tpr3;
    __u32           dram_tpr4;
    __u32           dram_tpr5;
    __u32             dram_emr1;
    __u32           dram_emr2;
    __u32           dram_emr3;
}boot_dram_para_t;
 
typedef struct _boot1_private_head_t
{
   __u32              prvt_head_size;
   __u8               prvt_head_vsn[4];                // the version of Boot1_private_hea
   __s32                        uart_port;              // UART控制器编号
   normal_gpio_cfg             uart_ctrl[2];           // UART控制器(调试打印口)GPIO信息
   boot_dram_para_t              dram_para;              // dram init para
   char                        script_buf[32 * 1024];  // 脚本参数
   boot_core_para_t            core_para;              // 关键参数
   __s32                        twi_port;               // TWI控制器编号
   normal_gpio_cfg             twi_ctrl[2];            // TWI控制器GPIO信息,用于控制TWI
   __s32                        debug_enable;           // debug使能参数
    __s32                       hold_key_min;           // hold key最小值
    __s32                       hold_key_max;           // hold key最大值
    __u32                       work_mode;              // 模式,区分量产还是升级
    __u32                       storage_type;           // 存储介质类型  0:nand   1:sdcard    2: spinor
    normal_gpio_cfg             storage_gpio[32];       // 存储设备 GPIO信息
    char                        storage_data[512 - sizeof(normal_gpio_cfg) * 32];      // 用户保留数据信息
    //boot_nand_connect_info_t    nand_connect_info;    // nand 参数
}boot1_private_head_t;
 
typedef struct _Boot1_file_head
{
   __u32  jump_instruction;   // one intruction jumping to real code
   __u8   magic[8];           // ="eGON.BT0" or "eGON.BT1",  not C-style string.
   __u32  check_sum;          // generated by PC
   __u32  length;             // generated by PC
   __u32  boot1_length;       // the size of boot_file_head_t
   __u32  align_size;         // the align size of boot1
   __u8   file_head_vsn[4];   // the version of boot0_file_head_t or boot1_file_head_t
   __u8   Boot_vsn[4];        // Boot version
   __u8   eGON_vsn[4];        // eGON version
   __u8   platform[8];        // platform information
}boot1_file_head;
 
typedef struct _boot1_file_head_t
{
   boot1_file_head      boot_head;
   boot1_private_head_t  prvt_head;
}boot1_file_head_t;
 
#endif     //  ifndef __boot1_h
 
/* end of boot1.h */
 
#ifndef  __toc_h
#define  __toc_h
//toc1的头部数据结构
typedef struct sbrom_toc1_head_info
{
   char name[16]    ;    //user can modify
   unsigned int  magic    ;    //must equal TOC_U32_MAGIC
   unsigned int  add_sum    ;
 
   unsigned int  serial_num    ;    //user can modify
   unsigned int  status        ;    //user can modify,such as TOC_MAIN_INFO_STATUS_ENCRYP_NOT_USED
 
   unsigned int  items_nr;    //total entry number
   unsigned int  valid_len;
   unsigned int  reserved[5];    //reserved for future
   unsigned int  end;
}sbrom_toc1_head_info_t;
 
typedef struct
{
   unsigned char  name[8];
   unsigned int magic;
   unsigned int check_sum;
 
   unsigned int serial_num;
   unsigned int status;
 
   unsigned int items_nr;
   unsigned int length;
   unsigned char  platform[4];
 
   unsigned int reserved[2];
   unsigned int end;
 
}toc0_private_head_t;
 
typedef struct sbrom_toc0_config
{
   unsigned char        config_vsn[4];
   unsigned int          dram_para[32];      // dram参数
   int                      uart_port;          // UART控制器编号
   normal_gpio_cfg       uart_ctrl[2];        // UART控制器GPIO
   int                  enable_jtag;        // JTAG使能
   normal_gpio_cfg       jtag_gpio[5];        // JTAG控制器GPIO
   normal_gpio_cfg      storage_gpio[50];     // 存储设备 GPIO信息
                                            // 0-23放nand,24-31存放卡0,32-39放卡2
                                            // 40-49存放spi
   char                   storage_data[384];  // 0-159,存储nand信息;160-255,存放卡信息
   unsigned int        secure_dram_mbytes; //
   unsigned int        drm_start_mbytes;   //
   unsigned int        drm_size_mbytes;    //
   unsigned int          res[8];               // 总共1024字节
}sbrom_toc0_config_t;
 
#define TOC0_CONFIG_HEAD_OFFSET 0x80
#define  TOC_MAIN_INFO_MAGIC    0x89119800
#endif /*endif toc_*/