mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-13 21:51:36 +08:00
Improvement when params are corrupted
This commit is contained in:
@@ -122,7 +122,7 @@ else
|
|||||||
then
|
then
|
||||||
echo "ERROR [init] param transition"
|
echo "ERROR [init] param transition"
|
||||||
else
|
else
|
||||||
echo "Successful param transition. The system will reboot!"
|
echo "The system will reboot!"
|
||||||
# Wait for UART to send messages
|
# Wait for UART to send messages
|
||||||
usleep 200000
|
usleep 200000
|
||||||
reboot
|
reboot
|
||||||
|
|||||||
@@ -85,10 +85,16 @@ __EXPORT int px4_mtd_unmount_littlefs_mount_block_device(void);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Helper function for transition to LittleFS.
|
Helper function for transition to LittleFS.
|
||||||
It will unmount MTD for parameters with Block Device and mount LittleFS with auto formatting
|
It will unmount MTD for parameters with Block Device and mount LittleFS with force formatting
|
||||||
*/
|
*/
|
||||||
__EXPORT int px4_mtd_unmount_block_device_mount_littlefs(void);
|
__EXPORT int px4_mtd_unmount_block_device_mount_littlefs(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Helper function for transition to LittleFS.
|
||||||
|
It will force formatting to LittleFS
|
||||||
|
*/
|
||||||
|
__EXPORT int px4_mtd_forceformat_littlefs(void);
|
||||||
|
|
||||||
int px4_at24c_initialize(FAR struct i2c_master_s *dev,
|
int px4_at24c_initialize(FAR struct i2c_master_s *dev,
|
||||||
uint8_t address, FAR struct mtd_dev_s **mtd_dev);
|
uint8_t address, FAR struct mtd_dev_s **mtd_dev);
|
||||||
|
|
||||||
|
|||||||
@@ -507,27 +507,21 @@ int px4_mtd_unmount_littlefs_mount_block_device(void)
|
|||||||
char blockname[32];
|
char blockname[32];
|
||||||
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", param_block);
|
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", param_block);
|
||||||
|
|
||||||
// in case if it is mounted
|
// in case LittleFS is mounted, unmount it
|
||||||
nx_umount2(instances[param_instance]->partition_names[param_part], 0);
|
nx_umount2(instances[param_instance]->partition_names[param_part], 0);
|
||||||
|
unregister_mtddriver(blockname);
|
||||||
|
|
||||||
int ret = unregister_mtddriver(blockname);
|
int ret = ftl_initialize(0, instances[0]->part_dev[0]);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
PX4_ERR("unregister_mtddriver fail: %d", ret);
|
PX4_ERR("ftl_initialize failed: %d", ret);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret = ftl_initialize(0, instances[0]->part_dev[0]);
|
ret = bchdev_register(blockname, instances[param_instance]->partition_names[param_part], false);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
PX4_ERR("ftl_initialize failed: %d", ret);
|
PX4_ERR("bchdev_register failed: %d", ret);
|
||||||
|
|
||||||
} else {
|
|
||||||
ret = bchdev_register(blockname, instances[param_instance]->partition_names[param_part], false);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
PX4_ERR("bchdev_register failed: %d", ret);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,19 +545,29 @@ int px4_mtd_unmount_block_device_mount_littlefs(void)
|
|||||||
PX4_ERR("unregister_blockdriver %s failed: %d", blockname, ret);
|
PX4_ERR("unregister_blockdriver %s failed: %d", blockname, ret);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret = register_mtddriver(blockname, instances[param_instance]->part_dev[param_part], 0755, nullptr);
|
ret = px4_mtd_forceformat_littlefs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
return ret;
|
||||||
PX4_ERR("register_mtddriver %s failed: %d", blockname, ret);
|
}
|
||||||
|
|
||||||
} else {
|
int px4_mtd_forceformat_littlefs(void)
|
||||||
ret = nx_mount(blockname, instances[param_instance]->partition_names[param_part], "littlefs", 0, "forceformat");
|
{
|
||||||
|
char blockname[32];
|
||||||
|
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", param_block);
|
||||||
|
|
||||||
if (ret < 0) {
|
int ret = register_mtddriver(blockname, instances[param_instance]->part_dev[param_part], 0755, nullptr);
|
||||||
PX4_ERR("nx_mount %s failed: %d", instances[param_instance]->partition_names[param_part], ret);
|
|
||||||
|
if (ret < 0) {
|
||||||
|
PX4_ERR("register_mtddriver %s failed: %d", blockname, ret);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ret = nx_mount(blockname, instances[param_instance]->partition_names[param_part], "littlefs", 0, "forceformat");
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
PX4_ERR("nx_mount %s failed: %d", instances[param_instance]->partition_names[param_part], ret);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -483,18 +483,35 @@ do_transition()
|
|||||||
if (ret_val < 0) {
|
if (ret_val < 0) {
|
||||||
PX4_ERR("Transition from LittleFS to Blockdriver");
|
PX4_ERR("Transition from LittleFS to Blockdriver");
|
||||||
} else {
|
} else {
|
||||||
ret_val = do_import("/fs/mtd_params");
|
char param_path[] = "/fs/mtd_params";
|
||||||
|
PX4_INFO("Try path: %s", param_path);
|
||||||
|
ret_val = do_import(param_path);
|
||||||
|
|
||||||
if (ret_val < 0) {
|
if (ret_val == 1) {
|
||||||
PX4_ERR("Import from blockdriver");
|
PX4_WARN("Try path: %s", param_path);
|
||||||
} else {
|
|
||||||
|
char param_path_backup[] = "/fs/microsd/parameters_backup.bson";
|
||||||
|
ret_val = do_import(param_path_backup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret_val == 0) {
|
||||||
ret_val = px4_mtd_unmount_block_device_mount_littlefs();
|
ret_val = px4_mtd_unmount_block_device_mount_littlefs();
|
||||||
|
|
||||||
if (ret_val < 0){
|
if (ret_val < 0) {
|
||||||
PX4_ERR("Transition from Blockdriver to LittleFS failed");
|
PX4_ERR("Transition from Blockdriver to LittleFS failed");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
PX4_INFO("Exporting params to LittleFS!");
|
||||||
ret_val = param_export(param_get_default_file(), nullptr);
|
ret_val = param_export(param_get_default_file(), nullptr);
|
||||||
|
|
||||||
|
if (ret_val == 0) {
|
||||||
|
PX4_INFO("Successful params transition!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
PX4_INFO("Params are unreadable from any known path. Format partition to LittleFS!");
|
||||||
|
ret_val = px4_mtd_forceformat_littlefs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user