mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-11 04:01:35 +08:00
Parameter transition from block device to LittleFS
This commit can be reverted after the transition period
This commit is contained in:
@@ -77,6 +77,18 @@ __EXPORT int px4_mtd_get_geometry(const mtd_instance_s *instance, unsigned long
|
||||
*/
|
||||
__EXPORT ssize_t px4_mtd_get_partition_size(const mtd_instance_s *instance, const char *partname);
|
||||
|
||||
/*
|
||||
Helper function for transition to LittleFS.
|
||||
It will unmount MTD for parameters with LittleFS and mount Block Device
|
||||
*/
|
||||
__EXPORT int px4_mtd_unmount_littlefs_mount_block_device(void);
|
||||
|
||||
/*
|
||||
Helper function for transition to LittleFS.
|
||||
It will unmount MTD for parameters with Block Device and mount LittleFS with auto formatting
|
||||
*/
|
||||
__EXPORT int px4_mtd_unmount_block_device_mount_littlefs(void);
|
||||
|
||||
int px4_at24c_initialize(FAR struct i2c_master_s *dev,
|
||||
uint8_t address, FAR struct mtd_dev_s **mtd_dev);
|
||||
|
||||
|
||||
@@ -70,6 +70,10 @@ static int num_instances = 0;
|
||||
static int total_blocks = 0;
|
||||
static mtd_instance_s *instances[MAX_MTD_INSTANCES] = {};
|
||||
|
||||
static uint8_t param_instance = 0;
|
||||
static uint8_t param_part = 0;
|
||||
static uint8_t param_block = 0;
|
||||
|
||||
|
||||
static int ramtron_attach(mtd_instance_s &instance)
|
||||
{
|
||||
@@ -396,6 +400,10 @@ memoryout:
|
||||
|
||||
if (instances[i]->partition_types[part] == MTD_PARAMETERS) {
|
||||
|
||||
param_instance = i;
|
||||
param_part = part;
|
||||
param_block = total_blocks;
|
||||
|
||||
rv = register_mtddriver(blockname, instances[i]->part_dev[part], 0755, nullptr);
|
||||
|
||||
if (rv < 0) {
|
||||
@@ -404,7 +412,8 @@ memoryout:
|
||||
}
|
||||
|
||||
// Now create a character device on the block device
|
||||
rv = nx_mount(blockname, instances[i]->partition_names[part], "littlefs", 0, "autoformat");
|
||||
//TODO: after the transition period return "autoformat"
|
||||
rv = nx_mount(blockname, instances[i]->partition_names[part], "littlefs", 0, "");
|
||||
|
||||
printf("nx_mount: blockname: %s partition: %s\n", blockname, instances[i]->partition_names[part]);
|
||||
|
||||
@@ -493,4 +502,72 @@ __EXPORT int px4_mtd_query(const char *sub, const char *val, const char **get)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int px4_mtd_unmount_littlefs_mount_block_device(void)
|
||||
{
|
||||
char blockname[32];
|
||||
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", param_block);
|
||||
|
||||
// in case if it is mounted
|
||||
nx_umount2(instances[param_instance]->partition_names[param_part], 0);
|
||||
|
||||
int ret = unregister_mtddriver(blockname);
|
||||
|
||||
if (ret < 0) {
|
||||
PX4_ERR("unregister_mtddriver fail: %d", ret);
|
||||
|
||||
} else {
|
||||
ret = ftl_initialize(0, instances[0]->part_dev[0]);
|
||||
|
||||
if (ret < 0) {
|
||||
PX4_ERR("ftl_initialize 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int px4_mtd_unmount_block_device_mount_littlefs(void)
|
||||
{
|
||||
char blockname[32];
|
||||
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", param_block);
|
||||
|
||||
int ret = bchdev_unregister(instances[param_instance]->partition_names[param_part]);
|
||||
|
||||
if (ret < 0) {
|
||||
PX4_ERR("bchdev_unregister %s failed: %d", instances[param_instance]->partition_names[param_part], ret);
|
||||
|
||||
} else {
|
||||
ret = unregister_blockdriver(blockname);
|
||||
|
||||
if (ret < 0) {
|
||||
PX4_ERR("unregister_blockdriver %s failed: %d", blockname, ret);
|
||||
|
||||
} else {
|
||||
ret = register_mtddriver(blockname, instances[param_instance]->part_dev[param_part], 0755, nullptr);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // CONFIG_MTD
|
||||
|
||||
Reference in New Issue
Block a user