|
29 | 29 |
|
30 | 30 | #define PART_UBI_NAME "ubi"
|
31 | 31 | #define PART_FIRMWARE_NAME "firmware"
|
| 32 | +#define PART_FIT_NAME "fit" |
32 | 33 | #define PART_KERNEL_NAME "kernel"
|
33 | 34 | #define PART_ROOTFS_NAME "rootfs"
|
34 | 35 | #define PART_ROOTFS_DATA_NAME "rootfs_data"
|
@@ -634,6 +635,48 @@ static int read_ubi_volume(const char *volume, void *buff, size_t size)
|
634 | 635 | return ubi_volume_read((char *)volume, buff, size);
|
635 | 636 | }
|
636 | 637 |
|
| 638 | +static int write_ubi_fit_image(const void *data, size_t size, |
| 639 | + struct mtd_info *mtd) |
| 640 | +{ |
| 641 | + int ret; |
| 642 | + |
| 643 | + ret = mount_ubi(mtd, true); |
| 644 | + if (ret) |
| 645 | + return ret; |
| 646 | + |
| 647 | + if (!ubi_find_volume(PART_FIT_NAME)) { |
| 648 | + /* ubi is dirty, erase ubi and recreate volumes */ |
| 649 | + ubi_exit(); |
| 650 | + ret = mtd_erase_skip_bad(mtd, 0, size, mtd->size, NULL, NULL, true); |
| 651 | + if (ret) |
| 652 | + return ret; |
| 653 | + |
| 654 | + ret = mount_ubi(mtd, true); |
| 655 | + if (ret) |
| 656 | + return ret; |
| 657 | + |
| 658 | + ret = create_ubi_volume("ubootenv", 0x100000, -1, false); |
| 659 | + if (ret) |
| 660 | + goto out; |
| 661 | + |
| 662 | + ret = create_ubi_volume("ubootenv2", 0x100000, -1, false); |
| 663 | + if (ret) |
| 664 | + goto out; |
| 665 | + } |
| 666 | + |
| 667 | + /* Remove this volume first in case of no enough PEBs */ |
| 668 | + remove_ubi_volume(PART_ROOTFS_DATA_NAME); |
| 669 | + |
| 670 | + ret = update_ubi_volume(PART_FIT_NAME, -1, data, size); |
| 671 | + if (ret) |
| 672 | + goto out; |
| 673 | + |
| 674 | + ret = create_ubi_volume(PART_ROOTFS_DATA_NAME, 0, -1, true); |
| 675 | + |
| 676 | +out: |
| 677 | + return ret; |
| 678 | +} |
| 679 | + |
637 | 680 | #ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
638 | 681 | static int write_ubi2_tar_image_separate(const void *data, size_t size,
|
639 | 682 | struct mtd_info *mtd_kernel, struct mtd_info *mtd_rootfs)
|
@@ -988,6 +1031,8 @@ static int boot_from_ubi(struct mtd_info *mtd)
|
988 | 1031 | return ret;
|
989 | 1032 |
|
990 | 1033 | ret = read_ubi_volume(PART_KERNEL_NAME, (void *)data_load_addr, 0);
|
| 1034 | + if (ret == ENODEV) |
| 1035 | + ret = read_ubi_volume(PART_FIT_NAME, (void *)data_load_addr, 0); |
991 | 1036 | if (ret)
|
992 | 1037 | return ret;
|
993 | 1038 |
|
@@ -1067,6 +1112,9 @@ int mtd_upgrade_image(const void *data, size_t size)
|
1067 | 1112 | } else {
|
1068 | 1113 | ret = parse_image_ram(data, size, mtd->erasesize, &ii);
|
1069 | 1114 |
|
| 1115 | + if (ii.header_type == HEADER_FIT) |
| 1116 | + return write_ubi_fit_image(data, size, mtd); |
| 1117 | + |
1070 | 1118 | if (!ret && ii.type == IMAGE_UBI2 &&
|
1071 | 1119 | !IS_ENABLED(CONFIG_MTK_DUAL_BOOT))
|
1072 | 1120 | return mtd_update_generic(mtd, data, size, true);
|
|
0 commit comments