diff --git a/uboot-mtk-20220606/board/mediatek/common/ubi_helper.c b/uboot-mtk-20220606/board/mediatek/common/ubi_helper.c index c2312dfb8..ffed67ab3 100644 --- a/uboot-mtk-20220606/board/mediatek/common/ubi_helper.c +++ b/uboot-mtk-20220606/board/mediatek/common/ubi_helper.c @@ -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;