Skip to content

Commit bd9495b

Browse files
committed
ntshell: expand flash command, add a parameter offset addr
Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
1 parent 12b69ce commit bd9495b

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

middleware/ntshell/cmds/cmds_fs/cmd_flash.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static void cmd_flash_help(char *cmd_name, void *extobj)
5252
"Write bin file to flash(eflash or bootspi flash)\r\n"
5353
" -h/H/? Show the help information\r\n"
5454
"Examples: \r\n"
55-
" flash -eflash test.bin Write bin file to eflash\r\n"
56-
" flash -bootspi test.bin Write bin file to bootspi flash\r\n"
55+
" flash -eflash test.bin [offset] Write bin file to eflash\r\n"
56+
" flash -bootspi test.bin [offset] Write bin file to bootspi flash\r\n"
5757
" flash -h Show the help information\r\n", cmd_name);
5858

5959
error_exit:
@@ -70,6 +70,7 @@ static int cmd_flash(int argc, char **argv, void *extobj)
7070
int32_t opt;
7171
int32_t file_size;
7272
uint32_t page_size;
73+
uint32_t offset_addr = 0;
7374
VALID_EXTOBJ(extobj, -1);
7475
NTSHELL_IO_GET(extobj);
7576
EFLASH_DEFINE(eflash_test, EFLASH_CRTL_BASE);
@@ -90,6 +91,15 @@ static int cmd_flash(int argc, char **argv, void *extobj)
9091
goto error_exit;
9192
}
9293

94+
if(argc > 3) {
95+
if (xatoi((char **)(&argv[3]), (long *)(&offset_addr)) != 1) {
96+
CMD_DEBUG("Please check the go address is valid!\r\n");
97+
return E_PAR;
98+
}
99+
} else {
100+
offset_addr = 0;
101+
}
102+
93103
file_size = f_size(&cmd_files[0]);
94104

95105
if (file_size == -1) {
@@ -103,15 +113,16 @@ static int cmd_flash(int argc, char **argv, void *extobj)
103113
smic_eflash_control(eflash_test, SMIC_EFLASH_GET_INFO, (void *)(&eflash_info));
104114
page_size = eflash_info.eflash_page_size;
105115

106-
if (file_size > eflash_info.eflash_page_size * eflash_info.eflash_page_cnt) {
116+
if (file_size + offset_addr > eflash_info.eflash_page_size * eflash_info.eflash_page_cnt) {
107117
ercd = E_SYS;
108-
CMD_DEBUG("filename: %s, file_size = %d > eflash size = %d \r\n", argv[1],
109-
file_size, eflash_info.eflash_page_size * eflash_info.eflash_page_cnt);
118+
CMD_DEBUG("filename: %s, file_size = %d > eflash size = %d \r\n", argv[2],
119+
file_size +offset_addr, eflash_info.eflash_page_size * eflash_info.eflash_page_cnt);
110120
f_close(&cmd_files[0]);
111121
smic_eflash_close(eflash_test);
112122
goto error_exit;
113123
}
114-
124+
CMD_DEBUG("filename: %s, file_size = %d, offset_addr = 0x%X \r\n", argv[2],
125+
file_size, offset_addr);
115126
smic_eflash_control(eflash_test, SMIC_EFLASH_MACRO_ERASE, NULL);
116127
uint32_t txlen = file_size;
117128
int32_t buf_pt=0;
@@ -127,8 +138,8 @@ static int cmd_flash(int argc, char **argv, void *extobj)
127138

128139
f_lseek(&cmd_files[0], buf_pt);
129140
f_read(&cmd_files[0], buffer, send_size, &send_size);
130-
smic_eflash_write(eflash_test, buf_pt, send_size, buffer);
131-
smic_eflash_read(eflash_test, buf_pt, send_size, buffer_r);
141+
smic_eflash_write(eflash_test, buf_pt + offset_addr, send_size, buffer);
142+
smic_eflash_read(eflash_test, buf_pt + offset_addr, send_size, buffer_r);
132143

133144
for (int i = 0; i < send_size; i++) {
134145
if (buffer[i] != buffer_r[i]) {
@@ -146,6 +157,7 @@ static int cmd_flash(int argc, char **argv, void *extobj)
146157

147158
f_close(&cmd_files[0]);
148159
smic_eflash_close(eflash_test);
160+
CMD_DEBUG("eflash write success !\r\n");
149161
return E_OK;
150162
} else if (argv[1][0]=='-' && argv[1][1]=='b') {
151163
res = f_open(&cmd_files[0], argv[2], FA_READ);
@@ -156,6 +168,15 @@ static int cmd_flash(int argc, char **argv, void *extobj)
156168
goto error_exit;
157169
}
158170

171+
if(argc > 3) {
172+
if (xatoi((char **)(&argv[3]), (long *)(&offset_addr)) != 1) {
173+
CMD_DEBUG("Please check the go address is valid!\r\n");
174+
return E_PAR;
175+
}
176+
} else {
177+
offset_addr = 0;
178+
}
179+
159180
file_size = f_size(&cmd_files[0]);
160181

161182
if (file_size == -1) {
@@ -169,16 +190,17 @@ static int cmd_flash(int argc, char **argv, void *extobj)
169190
smic_bootspi_control(bootspi_test, SMIC_BOOTSPI_RESET, NULL);
170191
page_size = SMIC_BOOTSPI_PAGE_SIZE;
171192

172-
if (file_size > SMIC_BOOTSPI_BLK_SIZE * SMIC_BOOTSPI_BLKS_PER_CHIP) {
193+
if (file_size + offset_addr > SMIC_BOOTSPI_BLK_SIZE * SMIC_BOOTSPI_BLKS_PER_CHIP) {
173194
ercd = E_SYS;
174-
CMD_DEBUG("filename: %s, file_size = %d > eflash size = %d \r\n", argv[1],
175-
file_size, SMIC_BOOTSPI_BLK_SIZE * SMIC_BOOTSPI_BLKS_PER_CHIP);
195+
CMD_DEBUG("filename: %s, file_size = %d > bootspi flash size = %d \r\n", argv[2],
196+
file_size, SMIC_BOOTSPI_BLK_SIZE * SMIC_BOOTSPI_BLKS_PER_CHIP);
176197
f_close(&cmd_files[0]);
177198
smic_bootspi_close(bootspi_test);
178199
goto error_exit;
179200
}
180-
181-
smic_bootspi_control(bootspi_test, SMIC_BOOTSPI_CHIP_ERASE, NULL);
201+
CMD_DEBUG("filename: %s, file_size = %d, offset_addr = 0x%X \r\n", argv[2],
202+
file_size, offset_addr);
203+
//smic_bootspi_control(bootspi_test, SMIC_BOOTSPI_CHIP_ERASE, NULL);
182204
uint32_t txlen = file_size;
183205
int32_t buf_pt=0;
184206

@@ -193,8 +215,8 @@ static int cmd_flash(int argc, char **argv, void *extobj)
193215

194216
f_lseek(&cmd_files[0], buf_pt);
195217
f_read(&cmd_files[0], buffer, send_size, &send_size);
196-
smic_bootspi_write(bootspi_test, buf_pt, send_size, buffer);
197-
smic_bootspi_read(bootspi_test, buf_pt, send_size, buffer_r);
218+
smic_bootspi_write(bootspi_test, buf_pt + offset_addr, send_size, buffer);
219+
smic_bootspi_read(bootspi_test, buf_pt + offset_addr, send_size, buffer_r);
198220

199221
for (int i = 0; i < send_size; i++) {
200222
if (buffer[i] != buffer_r[i]) {
@@ -212,6 +234,7 @@ static int cmd_flash(int argc, char **argv, void *extobj)
212234

213235
f_close(&cmd_files[0]);
214236
smic_bootspi_close(bootspi_test);
237+
CMD_DEBUG("bootspi flash write success !\r\n");
215238
return E_OK;
216239
}
217240

0 commit comments

Comments
 (0)