Skip to content

Commit 82eedc9

Browse files
committed
Upgrade: don't change active image until reset
1 parent 3a458e6 commit 82eedc9

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

firmware/programmer/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ int main()
3838
cdc_init();
3939
printf("done.\r\n");
4040

41+
printf("Programmer init...");
42+
np_init();
43+
printf("done.\r\n");
44+
4145
while (1)
4246
np_handler();
4347

firmware/programmer/nand_programmer.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ typedef struct
252252
int nand_wr_in_progress;
253253
uint32_t nand_timeout;
254254
chip_info_t chip_info;
255+
uint8_t active_image;
255256
} np_prog_t;
256257

257258
typedef struct
@@ -262,6 +263,7 @@ typedef struct
262263
} np_cmd_handler_t;
263264

264265
static np_comm_cb_t *np_comm_cb;
266+
static np_prog_t prog;
265267

266268
uint8_t np_packet_send_buf[NP_PACKET_BUF_SIZE];
267269

@@ -1175,12 +1177,16 @@ static int np_cmd_active_image_get(np_prog_t *prog)
11751177

11761178
DEBUG_PRINT("Get active image command\r\n");
11771179

1178-
if (np_boot_config_read(&boot_config))
1179-
return NP_ERR_INTERNAL;
1180+
if (prog->active_image == 0xff)
1181+
{
1182+
if (np_boot_config_read(&boot_config))
1183+
return NP_ERR_INTERNAL;
1184+
prog->active_image = boot_config.active_image;
1185+
}
11801186

11811187
resp.header.code = NP_RESP_DATA;
11821188
resp.header.info = resp_len - sizeof(resp.header);
1183-
resp.active_image = boot_config.active_image;
1189+
resp.active_image = prog->active_image;
11841190

11851191
if (np_comm_cb)
11861192
np_comm_cb->send((uint8_t *)&resp, resp_len);
@@ -1354,7 +1360,9 @@ static int np_cmd_fw_update_end(np_prog_t *prog)
13541360
if (np_boot_config_read(&boot_config))
13551361
return NP_ERR_INTERNAL;
13561362

1357-
boot_config.active_image = boot_config.active_image ? 0 : 1;
1363+
if (prog->active_image == 0xff)
1364+
prog->active_image = boot_config.active_image;
1365+
boot_config.active_image = prog->active_image ? 0 : 1;
13581366
if (np_boot_config_write(&boot_config))
13591367
return NP_ERR_INTERNAL;
13601368

@@ -1467,10 +1475,13 @@ static void np_nand_handler(np_prog_t *prog)
14671475
}
14681476
}
14691477

1470-
void np_handler()
1478+
void np_init()
14711479
{
1472-
static np_prog_t prog;
1480+
prog.active_image = 0xff;
1481+
}
14731482

1483+
void np_handler()
1484+
{
14741485
np_packet_handler(&prog);
14751486
np_nand_handler(&prog);
14761487
}

firmware/programmer/nand_programmer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef struct
1616

1717
int np_comm_register(np_comm_cb_t *cb);
1818
void np_comm_unregister(np_comm_cb_t *cb);
19+
void np_init();
1920
void np_handler();
2021

2122
#endif

0 commit comments

Comments
 (0)