uboot-2025: add mtdlayout support
This commit is contained in:
@@ -248,6 +248,14 @@ config MTK_ROOTDISK_OVERRIDE
|
|||||||
|
|
||||||
endif # MEDIATEK_BOOTMENU
|
endif # MEDIATEK_BOOTMENU
|
||||||
|
|
||||||
|
config MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
bool "Enable multi mtd layout support"
|
||||||
|
select SYS_MTDPARTS_RUNTIME
|
||||||
|
select CMD_SHOW_MTD_LAYOUT
|
||||||
|
depends on !MTK_BOOTMENU_MMC
|
||||||
|
depends on !MTK_DUAL_BOOT
|
||||||
|
default n
|
||||||
|
|
||||||
menuconfig MTK_SECURE_BOOT
|
menuconfig MTK_SECURE_BOOT
|
||||||
bool "Enable secure boot framework"
|
bool "Enable secure boot framework"
|
||||||
select FIT_SIGNATURE
|
select FIT_SIGNATURE
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ ifdef CONFIG_MMC
|
|||||||
obj-$(CONFIG_MEDIATEK_BOOTMENU) += mmc_helper.o
|
obj-$(CONFIG_MEDIATEK_BOOTMENU) += mmc_helper.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
obj-$(CONFIG_MEDIATEK_MULTI_MTD_LAYOUT) += mtd_layout.o
|
||||||
|
|
||||||
obj-$(CONFIG_MEDIATEK_BOOTMENU) += cmd_mtkupgrade.o cmd_mtkload.o \
|
obj-$(CONFIG_MEDIATEK_BOOTMENU) += cmd_mtkupgrade.o cmd_mtkload.o \
|
||||||
cmd_mtkboardboot.o cmd_mtkautoboot.o \
|
cmd_mtkboardboot.o cmd_mtkautoboot.o \
|
||||||
cmd_mtkbootconf.o
|
cmd_mtkbootconf.o
|
||||||
|
|||||||
@@ -635,7 +635,8 @@ static int mount_ubi(struct mtd_info *mtd, bool create)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = ubi_init();
|
ubi_exit();
|
||||||
|
ret = ubi_part(mtd->name, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@@ -787,6 +788,45 @@ static int read_ubi_volume(const char *volume, void *buff, size_t size)
|
|||||||
return ubi_volume_read((char *)volume, buff, 0, size);
|
return ubi_volume_read((char *)volume, buff, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
static int write_ubi2_tar_image_separate(const void *data, size_t size,
|
||||||
|
struct mtd_info *mtd_kernel, struct mtd_info *mtd_rootfs)
|
||||||
|
{
|
||||||
|
const void *kernel_data, *rootfs_data;
|
||||||
|
size_t kernel_size, rootfs_size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = parse_tar_image(data, size, &kernel_data, &kernel_size,
|
||||||
|
&rootfs_data, &rootfs_size);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = mount_ubi(mtd_kernel, true);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = update_ubi_volume(PART_KERNEL_NAME, -1, kernel_data, kernel_size);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = mount_ubi(mtd_rootfs, true);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* Remove this volume first in case of no enough PEBs */
|
||||||
|
remove_ubi_volume(PART_ROOTFS_DATA_NAME);
|
||||||
|
|
||||||
|
ret = update_ubi_volume(PART_ROOTFS_NAME, -1, rootfs_data, rootfs_size);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = create_ubi_volume(PART_ROOTFS_DATA_NAME, 0, -1, true);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int write_ubi1_tar_image(const void *data, size_t size,
|
static int write_ubi1_tar_image(const void *data, size_t size,
|
||||||
struct mtd_info *mtd_kernel,
|
struct mtd_info *mtd_kernel,
|
||||||
struct mtd_info *mtd_ubi)
|
struct mtd_info *mtd_ubi)
|
||||||
@@ -1496,10 +1536,18 @@ int mtd_upgrade_image(const void *data, size_t size)
|
|||||||
struct owrt_image_info ii;
|
struct owrt_image_info ii;
|
||||||
struct mtd_info *mtd;
|
struct mtd_info *mtd;
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
const char *ubi_flash_part = PART_UBI_NAME;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CMD_UBI
|
#ifdef CONFIG_CMD_UBI
|
||||||
struct mtd_info *mtd_kernel;
|
struct mtd_info *mtd_kernel;
|
||||||
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
struct mtd_info *mtd_ubikernel, *mtd_ubirootfs;
|
||||||
|
const char *ubi_kernel_part;
|
||||||
|
const char *ubi_rootfs_part;
|
||||||
|
#endif
|
||||||
#endif /* CONFIG_CMD_UBI */
|
#endif /* CONFIG_CMD_UBI */
|
||||||
|
|
||||||
gen_mtd_probe_devices();
|
gen_mtd_probe_devices();
|
||||||
@@ -1511,7 +1559,13 @@ int mtd_upgrade_image(const void *data, size_t size)
|
|||||||
else
|
else
|
||||||
mtd_kernel = NULL;
|
mtd_kernel = NULL;
|
||||||
|
|
||||||
mtd = get_mtd_device_nm(PART_UBI_NAME);
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
ubi_flash_part = env_get("factory_part");
|
||||||
|
if (!ubi_flash_part)
|
||||||
|
ubi_flash_part = PART_UBI_NAME;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mtd = get_mtd_device_nm(ubi_flash_part);
|
||||||
if (!IS_ERR_OR_NULL(mtd)) {
|
if (!IS_ERR_OR_NULL(mtd)) {
|
||||||
put_mtd_device(mtd);
|
put_mtd_device(mtd);
|
||||||
|
|
||||||
@@ -1534,9 +1588,24 @@ int mtd_upgrade_image(const void *data, size_t size)
|
|||||||
return mtd_update_generic(mtd, data, size, true);
|
return mtd_update_generic(mtd, data, size, true);
|
||||||
|
|
||||||
if (!ret && ii.type == IMAGE_TAR &&
|
if (!ret && ii.type == IMAGE_TAR &&
|
||||||
!IS_ENABLED(CONFIG_MTK_DUAL_BOOT_ITB_IMAGE))
|
!IS_ENABLED(CONFIG_MTK_DUAL_BOOT_ITB_IMAGE)) {
|
||||||
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
ubi_kernel_part = env_get("sysupgrade_kernel_ubipart");
|
||||||
|
ubi_rootfs_part = env_get("sysupgrade_rootfs_ubipart");
|
||||||
|
if (ubi_kernel_part && ubi_rootfs_part) {
|
||||||
|
mtd_ubikernel = get_mtd_device_nm(ubi_kernel_part);
|
||||||
|
mtd_ubirootfs = get_mtd_device_nm(ubi_rootfs_part);
|
||||||
|
if (!IS_ERR_OR_NULL(mtd_ubikernel) && !IS_ERR_OR_NULL(mtd_ubirootfs)) {
|
||||||
|
put_mtd_device(mtd_ubikernel);
|
||||||
|
put_mtd_device(mtd_ubirootfs);
|
||||||
|
return write_ubi2_tar_image_separate(data, size, mtd_ubikernel, mtd_ubirootfs);
|
||||||
|
} else {
|
||||||
|
return -ENOTSUPP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return write_ubi2_tar_image(data, size, mtd);
|
return write_ubi2_tar_image(data, size, mtd);
|
||||||
|
}
|
||||||
if (!ret && ii.type == IMAGE_ITB)
|
if (!ret && ii.type == IMAGE_ITB)
|
||||||
return write_ubi_itb_image(data, size, mtd);
|
return write_ubi_itb_image(data, size, mtd);
|
||||||
}
|
}
|
||||||
@@ -1565,6 +1634,9 @@ int mtd_boot_image(bool do_boot)
|
|||||||
{
|
{
|
||||||
#if defined(CONFIG_CMD_UBI) || !defined(CONFIG_MTK_DUAL_BOOT)
|
#if defined(CONFIG_CMD_UBI) || !defined(CONFIG_MTK_DUAL_BOOT)
|
||||||
struct mtd_info *mtd;
|
struct mtd_info *mtd;
|
||||||
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
const char *ubi_boot_part = PART_UBI_NAME;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CMD_UBI
|
#ifdef CONFIG_CMD_UBI
|
||||||
@@ -1582,7 +1654,13 @@ int mtd_boot_image(bool do_boot)
|
|||||||
else
|
else
|
||||||
mtd_kernel = NULL;
|
mtd_kernel = NULL;
|
||||||
|
|
||||||
mtd = get_mtd_device_nm(PART_UBI_NAME);
|
#ifdef CONFIG_MEDIATEK_MULTI_MTD_LAYOUT
|
||||||
|
ubi_boot_part = env_get("ubi_boot_part");
|
||||||
|
if (!ubi_boot_part)
|
||||||
|
ubi_boot_part = PART_UBI_NAME;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mtd = get_mtd_device_nm(ubi_boot_part);
|
||||||
if (!IS_ERR_OR_NULL(mtd)) {
|
if (!IS_ERR_OR_NULL(mtd)) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|||||||
82
uboot-mtk-20250711/board/mediatek/common/mtd_layout.c
Normal file
82
uboot-mtk-20250711/board/mediatek/common/mtd_layout.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <command.h>
|
||||||
|
#include <env.h>
|
||||||
|
#include <mtd_node.h>
|
||||||
|
#include <linux/mtd/mtd.h>
|
||||||
|
#include <linux/string.h>
|
||||||
|
#include <dm/ofnode.h>
|
||||||
|
|
||||||
|
static ofnode ofnode_get_mtd_layout(const char *layout_label)
|
||||||
|
{
|
||||||
|
ofnode node, layout;
|
||||||
|
const char *label;
|
||||||
|
|
||||||
|
node = ofnode_path("/mtd-layout");
|
||||||
|
if (!ofnode_valid(node)) {
|
||||||
|
return ofnode_null();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ofnode_get_child_count(node)) {
|
||||||
|
return ofnode_null();
|
||||||
|
}
|
||||||
|
|
||||||
|
ofnode_for_each_subnode(layout, node) {
|
||||||
|
label = ofnode_read_string(layout, "label");
|
||||||
|
if (!strcmp(layout_label, label)) {
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ofnode_null();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_mtd_layout_label(void)
|
||||||
|
{
|
||||||
|
const char *layout_label = NULL;
|
||||||
|
|
||||||
|
if (gd->flags & GD_FLG_ENV_READY)
|
||||||
|
layout_label = env_get("mtd_layout_label");
|
||||||
|
|
||||||
|
if (!layout_label)
|
||||||
|
layout_label = "default";
|
||||||
|
|
||||||
|
return layout_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void board_mtdparts_default(const char **mtdids, const char **mtdparts)
|
||||||
|
{
|
||||||
|
const char *ids = NULL;
|
||||||
|
const char *parts = NULL;
|
||||||
|
const char *boot_part = NULL;
|
||||||
|
const char *factory_part = NULL;
|
||||||
|
const char *sysupgrade_kernel_ubipart = NULL;
|
||||||
|
const char *sysupgrade_rootfs_ubipart = NULL;
|
||||||
|
const char *cmdline = NULL;
|
||||||
|
ofnode layout_node;
|
||||||
|
|
||||||
|
layout_node = ofnode_get_mtd_layout(get_mtd_layout_label());
|
||||||
|
|
||||||
|
if (ofnode_valid(layout_node)) {
|
||||||
|
ids = ofnode_read_string(layout_node, "mtdids");
|
||||||
|
parts = ofnode_read_string(layout_node, "mtdparts");
|
||||||
|
boot_part = ofnode_read_string(layout_node, "boot_part");
|
||||||
|
factory_part = ofnode_read_string(layout_node, "factory_part");
|
||||||
|
sysupgrade_kernel_ubipart = ofnode_read_string(layout_node, "sysupgrade_kernel_ubipart");
|
||||||
|
sysupgrade_rootfs_ubipart = ofnode_read_string(layout_node, "sysupgrade_rootfs_ubipart");
|
||||||
|
cmdline = ofnode_read_string(layout_node, "cmdline");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ids && parts) {
|
||||||
|
*mtdids = ids;
|
||||||
|
*mtdparts = parts;
|
||||||
|
//printf("%s: mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
env_set("bootargs", cmdline);
|
||||||
|
env_set("ubi_boot_part", boot_part);
|
||||||
|
env_set("factory_part", factory_part);
|
||||||
|
env_set("sysupgrade_kernel_ubipart", sysupgrade_kernel_ubipart);
|
||||||
|
env_set("sysupgrade_rootfs_ubipart", sysupgrade_rootfs_ubipart);
|
||||||
|
}
|
||||||
@@ -3124,4 +3124,9 @@ config CMD_GL_BTN
|
|||||||
default n
|
default n
|
||||||
select POLLER
|
select POLLER
|
||||||
|
|
||||||
|
config CMD_SHOW_MTD_LAYOUT
|
||||||
|
bool "Show mtd layout command"
|
||||||
|
depends on OF_LIBFDT
|
||||||
|
default n
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -240,6 +240,8 @@ obj-$(CONFIG_CMD_SCP03) += scp03.o
|
|||||||
|
|
||||||
obj-$(CONFIG_CMD_GL_BTN) += glbtn.o led_blink.o
|
obj-$(CONFIG_CMD_GL_BTN) += glbtn.o led_blink.o
|
||||||
|
|
||||||
|
obj-$(CONFIG_CMD_SHOW_MTD_LAYOUT) += showlayout.o
|
||||||
|
|
||||||
obj-$(CONFIG_HUSH_SELECTABLE) += cli.o
|
obj-$(CONFIG_HUSH_SELECTABLE) += cli.o
|
||||||
|
|
||||||
obj-$(CONFIG_CMD_SPAWN) += spawn.o
|
obj-$(CONFIG_CMD_SPAWN) += spawn.o
|
||||||
|
|||||||
31
uboot-mtk-20250711/cmd/showlayout.c
Normal file
31
uboot-mtk-20250711/cmd/showlayout.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <command.h>
|
||||||
|
#include <dm/ofnode.h>
|
||||||
|
|
||||||
|
static int do_showlayout(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||||
|
{
|
||||||
|
ofnode node, layout;
|
||||||
|
|
||||||
|
node = ofnode_path("/mtd-layout");
|
||||||
|
|
||||||
|
if (ofnode_valid(node) && ofnode_get_child_count(node)) {
|
||||||
|
ofnode_for_each_subnode(layout, node) {
|
||||||
|
printf("mtd label: %s, mtdids: %s, mtdparts: %s\n",
|
||||||
|
ofnode_read_string(layout, "label"),
|
||||||
|
ofnode_read_string(layout, "mtdids"),
|
||||||
|
ofnode_read_string(layout, "mtdparts"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("get mtd layout failed!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return CMD_RET_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
U_BOOT_CMD(
|
||||||
|
showlayout, 2, 0, do_showlayout,
|
||||||
|
"Show mtd layout",
|
||||||
|
""
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user