Skip to content

Commit bbe3d9e

Browse files
author
Wayne Ren
committed
example: bootloader: code format and bug fixes
* code format * fix code bugs * fix typos in .rst file Signed-off-by: Wayne Ren <[email protected]>
1 parent 417ec2d commit bbe3d9e

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

example/baremetal/bootloader/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ Detailed Description
8181
- Bootloader example only support arc core configuration which has DDR with cache enabled.
8282
- Bootloader example runs in DDR ram, not in CCM.
8383
- Bootloader example itself can be treated as a ntshell example, you can run some ntshell commands using this example.
84-
- The bootloader example is also built optimized for the ARC core you selected, so the example built for one specified core may not run sucessfully
84+
- The bootloader example is also built optimized for the ARC core you selected, so the example built for one specified core may not run successfully
8585
- Supported core configurations
8686
+ EMSK 1.1: EM6, EM6GP
8787
+ EMSK 2.2/2.3: EM7D, EM11D
8888

89-
Buidling and Running
89+
Building and Running
9090
********************
9191

9292
- Generate a secondary bootloader binary file
@@ -142,7 +142,7 @@ If the binary file is generated successfully, you will output as follows:
142142
+ Insert SDCard to PC, and copy generated binary file *obj_emsk_23/gnu_arcem7d/freertos_kernel_gnu_arcem7d.bin* to SDCard Root, and rename it to boot.bin
143143
+ Insert SDCard back to EMSK, make sure bit 4 of DIP Switch is ON, and press re-configure button above letter **C**, and wait for autoload.
144144

145-
.. note:: Make sure you have selected the correct configuration of EMSK via dipswitches and that you have reset the board (button above “R”) to confirme its configuration
145+
.. note:: Make sure you have selected the correct configuration of EMSK via dipswitches and that you have reset the board (button above "R") to confirm its configuration
146146

147147
Sample Output
148148
=============

example/baremetal/bootloader/main.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define RAM_STARTADDRESS 0x10000000 /*!< default ram start address of boot.bin */
4545
#define APP_CFG_ADDR 0x17f00000 /*!< save the app configuration file name */
4646
#elif defined(BOARD_IOTDK)
47-
#define RAM_STARTADDRESS EXT_RAM_START
47+
#define RAM_STARTADDRESS ICCM_START
4848
#define APP_CFG_ADDR ARC_X_MEM_START
4949
#endif
5050

@@ -53,9 +53,9 @@
5353
typedef int (*fp_t)(void);
5454

5555
struct wifi_cfg_t {
56-
char* wifi_sel;
57-
char* SSID;
58-
char* PSK;
56+
char *wifi_sel;
57+
char *SSID;
58+
char *PSK;
5959
uint8_t DHCP;
6060
uint8_t version;
6161
uint8_t address[4];
@@ -110,47 +110,56 @@ int main(void)
110110
default_bt_flag = 1;
111111
} else {
112112
res = f_read(&file, boot_json, file.fsize, &cnt);
113+
113114
if (res) {
114115
EMBARC_PRINTF("read boot cfg file error\r\n");
115116
default_bt_flag = 1;
116117
}
118+
117119
f_close(&file);
118120
}
119121

120122
if (default_bt_flag == 0) {
121123
JSON_Value *user_data = json_parse_string((const char *)boot_json);
124+
122125
if (user_data != NULL) {
123126
/*parse the boot.json*/
124127
const char *str;
125128
str = json_object_get_string(json_object(user_data), "boot_file");
129+
126130
if (str != NULL) {
127131
boot_cfg.boot_file = str;
128132
}
133+
129134
str = json_object_get_string(json_object(user_data), "app_cfg");
135+
130136
if (str != NULL) {
131137
boot_cfg.app_cfg = str;
132138
}
133139

134140
uint32_t num;
135141
num = json_object_get_number(json_object(user_data), "ram_startaddress");
142+
136143
if (num != 0) {
137144
boot_cfg.ram_startaddress = num;
138145
}
139146

140147
int32_t boo;
141148
boo = json_object_get_boolean(json_object(user_data), "ntshell");
149+
142150
if (boo != -1) {
143151
boot_cfg.ntshell = boo;
144152
}
145153

146154
JSON_Object *obj;
147155
obj = json_object_get_object(json_object(user_data), "wifi");
156+
148157
if (obj != NULL) {
149158
/*TODO: parse wifi setting*/
150159
}
151160

152161
EMBARC_PRINTF("boot_file:%s\napp_cfg:%s\nram:0x%x\nntshell:%d", \
153-
boot_cfg.boot_file, boot_cfg.app_cfg, boot_cfg.ram_startaddress, boot_cfg.ntshell);
162+
boot_cfg.boot_file, boot_cfg.app_cfg, boot_cfg.ram_startaddress, boot_cfg.ntshell);
154163
} else {
155164
EMBARC_PRINTF("Cannot parse boot.json, please check it. Now use default bootloader\n");
156165
default_bt_flag = 1;
@@ -160,17 +169,19 @@ int main(void)
160169
if (default_bt_flag == 1) {
161170
EMBARC_PRINTF("\r\nPress any button on board to stop auto boot in %d s\r\n", PROMT_DELAY_S);
162171
cur_ms = OSP_GET_CUR_MS();
172+
163173
do {
164174
if (((OSP_GET_CUR_MS()-cur_ms)/1000) == cur_cnt) {
165175
cur_cnt ++;
166176
EMBARC_PRINTF(". ");
167177
}
178+
168179
/* any button pressed */
169180
if (button_read(BOARD_BTN_MASK)) {
170181
load_flag = 0;
171182
break;
172183
}
173-
} while((OSP_GET_CUR_MS() - cur_ms) < max_promt_ms);
184+
} while ((OSP_GET_CUR_MS() - cur_ms) < max_promt_ms);
174185
}
175186

176187
if (default_bt_flag == 0 && boot_cfg.ntshell == 1 || load_flag == 0) {
@@ -183,22 +194,26 @@ int main(void)
183194

184195
EMBARC_PRINTF("\r\nStart loading %s from sdcard to 0x%x and run...\r\n", boot_cfg.boot_file, boot_cfg.ram_startaddress);
185196
led_write(0xF, 0xFF); /* Start to load application */
197+
186198
if (boot_cfg.boot_file[strlen(boot_cfg.boot_file) - 3] == 'h') {
187199
ihex_start();
188200
res = ihex_load(IHEX_SD_CARD, (void *)boot_cfg.boot_file);
201+
189202
if (res != IHEX_END) {
190203
EMBARC_PRINTF("%s open or read error\r\n", boot_cfg.boot_file);
191204
load_flag = 0;
192205
}
193206
} else if (boot_cfg.boot_file[strlen(boot_cfg.boot_file) - 3] == 'b') {
194207
res = f_open(&file, boot_cfg.boot_file, FA_READ | FA_OPEN_EXISTING);
208+
195209
if (res) {
196210
EMBARC_PRINTF("%s open error\r\n", boot_cfg.boot_file);
197211
load_flag = 0;
198212
} else {
199213
ram = (void *)boot_cfg.ram_startaddress;
200214
res = f_read(&file, ram, file.fsize, &cnt);
201215
f_close(&file);
216+
202217
if (res || ((uint32_t)cnt != file.fsize)) {
203218
EMBARC_PRINTF("%s read error\r\n", boot_cfg.boot_file);
204219
load_flag = 0;
@@ -216,6 +231,7 @@ int main(void)
216231
/** enter ntshell command routine no return */
217232
ntshell_task((void *)nt_io);
218233
}
234+
219235
led_write(0xF0, 0xFF); /* Load application finished */
220236

221237
ram = (void *)APP_CFG_ADDR;
@@ -225,14 +241,12 @@ int main(void)
225241
for (int i = NUM_EXC_CPU; i < NUM_EXC_ALL; i++) {
226242
int_disable(i);
227243
}
244+
228245
/* set up an enviroment for application */
229-
if ((_arc_aux_read(AUX_BCR_I_CACHE) & 0x7) >= 0x2) {
230-
//icache_invalidate();
231-
}
232246
if ((_arc_aux_read(AUX_BCR_D_CACHE) & 0x7) >= 0x2) {
233-
//dcache_flush();
234247
dcache_invalidate();
235248
}
249+
236250
led_write(0xFF, 0xFF); /* Start application */
237251

238252
fp = (fp_t)(*((uint32_t *)boot_cfg.ram_startaddress));

0 commit comments

Comments
 (0)