static void process_boot_cmd() { boot_cmd_t boot_cmd; sxfs_read(SP_BOOT_PARAMS, 0, (uint8_t*)&boot_cmd, sizeof(boot_cmd)); switch (boot_cmd) { case BOOT_LOAD_RECOVERY_IMG: write_app_img(SP_RECOVERY_IMG); break; case BOOT_LOAD_UPDATE_IMG: write_app_img(SP_UPDATE_IMG); break; case BOOT_DEFAULT: default: break; } if (boot_cmd != BOOT_DEFAULT) { boot_cmd = BOOT_DEFAULT; sxfs_erase_all(SP_BOOT_PARAMS); sxfs_write(SP_BOOT_PARAMS, 0, (uint8_t*)&boot_cmd, sizeof(boot_cmd)); } }
void app_cfg_flush() { sxfs_part_id_t used_app_cfg_part = SP_APP_CFG_1; app_cfg_rec_t* app_cfg = app_cfg_load(&used_app_cfg_part); chMtxLock(&app_cfg_mtx); app_cfg_local.crc = crc32_block(0, &app_cfg_local.data, sizeof(app_cfg_data_t)); if (memcmp(&app_cfg_local, app_cfg, sizeof(app_cfg_rec_t)) != 0) { sxfs_part_id_t unused_app_cfg_part = (used_app_cfg_part == SP_APP_CFG_1) ? SP_APP_CFG_2 : SP_APP_CFG_1; bool ret = sxfs_write(unused_app_cfg_part, 0, (uint8_t*)&app_cfg_local, sizeof(app_cfg_local)); if (ret) { ret = sxfs_erase(used_app_cfg_part); if (!ret) printf("app cfg erase failed! %d\r\n", used_app_cfg_part); } else { printf("app cfg write failed! %d\r\n", unused_app_cfg_part); } } chMtxUnlock(); if (app_cfg != NULL) free(app_cfg); }
static void save_boot_cmd(boot_cmd_t boot_cmd) { sxfs_erase_all(SP_BOOT_PARAMS); sxfs_write(SP_BOOT_PARAMS, 0, (uint8_t*)&boot_cmd, sizeof(boot_cmd)); NVIC_SystemReset(); }