ubi_helper: do not erase mtd while boot from ubi

This commit is contained in:
hanwckf
2022-11-27 15:32:46 +08:00
parent 955ebf6de7
commit 3d36ea4ae7

View File

@@ -89,7 +89,7 @@ static int write_ubi1_image(const void *data, size_t size,
ii->ubi_size + ii->marker_size);
}
static int mount_ubi(struct mtd_info *mtd)
static int mount_ubi(struct mtd_info *mtd, bool auto_erase_ubi)
{
struct ubi_device *ubi;
int ret;
@@ -103,15 +103,19 @@ static int mount_ubi(struct mtd_info *mtd)
ret = ubi_init();
if (ret) {
cprintln(CAUTION, "*** Failed to attach UBI ***");
cprintln(NORMAL, "*** Rebuilding UBI ***");
ret = mtd_erase_generic(mtd, 0, mtd->size);
if (ret)
return ret;
if (auto_erase_ubi) {
cprintln(NORMAL, "*** Rebuilding UBI ***");
ret = mtd_erase_generic(mtd, 0, mtd->size);
if (ret)
return ret;
ret = ubi_init();
if (ret) {
cprintln(ERROR, "*** Failed to attach UBI ***");
ret = ubi_init();
if (ret) {
cprintln(ERROR, "*** Failed to attach UBI ***");
return -ret;
}
} else {
return -ret;
}
}
@@ -410,7 +414,7 @@ static int write_ubi1_tar_image(const void *data, size_t size,
if (ret)
return ret;
ret = mount_ubi(mtd_ubi);
ret = mount_ubi(mtd_ubi, true);
if (ret)
return ret;
@@ -441,7 +445,7 @@ static int write_ubi2_tar_image(const void *data, size_t size,
if (ret)
return ret;
ret = mount_ubi(mtd);
ret = mount_ubi(mtd, true);
if (ret)
return ret;
@@ -476,7 +480,7 @@ static int boot_from_ubi(struct mtd_info *mtd)
data_load_addr = CONFIG_LOADADDR;
#endif
ret = mount_ubi(mtd);
ret = mount_ubi(mtd, false);
if (ret)
return ret;