[U-Boot] [PATCH v5 11/16] cmd: gpt: update write command to support GPT over MTD
Patrick Delaunay
patrick.delaunay at st.com
Thu Apr 13 09:52:49 UTC 2017
support gpt write for MTD device
> gpt write nand 0
> gpt write nor 0
And verify is not yet supported for MTD device
Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
Reviewed-by: Christophe KERELLO <christophe.kerello at st.com>
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
cmd/gpt.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 67 insertions(+), 4 deletions(-)
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 2363b34..24211fe 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -19,6 +19,7 @@
#include <linux/ctype.h>
#include <div64.h>
#include <memalign.h>
+#include <linux/mtd/mtd.h>
/**
* extract_env(): Expand env name from string format '&{env_name}'
@@ -399,6 +400,41 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part)
return ret;
}
+#ifdef CONFIG_EFI_PARTITION_MTD
+static int gpt_default_mtd(struct mtd_info *mtd_info, const char *str_part)
+{
+ int ret;
+ char *str_disk_guid;
+ u8 part_count = 0;
+ disk_partition_t *partitions = NULL;
+ unsigned int lba = lldiv(mtd_info->size, MTD_LBA_SIZE);
+
+ if (!str_part)
+ return -1;
+
+ /* fill partitions */
+ ret = set_gpt_info(lba, MTD_LBA_SIZE, str_part,
+ &str_disk_guid, &partitions, &part_count);
+ if (ret) {
+ print_gpt_info_err(ret);
+ return -1;
+ }
+
+ /* save partitions layout to disk */
+ ret = gpt_restore_mtd(mtd_info, str_disk_guid, partitions, part_count);
+ free(str_disk_guid);
+ free(partitions);
+
+ return ret;
+}
+
+static int gpt_verify_mtd(struct mtd_info *mtd_info, const char *str_part)
+{
+ printf("Verify no yet supported for MTD device\n");
+ return CMD_RET_FAILURE;
+}
+#endif
+
/**
* do_gpt(): Perform GPT operations
*
@@ -415,6 +451,10 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int dev = 0;
char *ep;
struct blk_desc *blk_dev_desc = NULL;
+#ifdef CONFIG_EFI_PARTITION_MTD
+ struct mtd_info *mtd_info = NULL;
+ char mtd_dev[16];
+#endif
if (argc < 4 || argc > 5)
return CMD_RET_USAGE;
@@ -425,17 +465,40 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return CMD_RET_USAGE;
}
blk_dev_desc = blk_get_dev(argv[2], dev);
- if (!blk_dev_desc) {
+ if (!blk_dev_desc)
+ ret = CMD_RET_FAILURE;
+#ifdef CONFIG_EFI_PARTITION_MTD
+ if (ret) {
+ ret = CMD_RET_SUCCESS;
+ sprintf(mtd_dev, "%s%d", argv[2], dev);
+ mtd_info = get_mtd_device_nm(mtd_dev);
+ if (IS_ERR(mtd_info))
+ ret = CMD_RET_FAILURE;
+ }
+#endif
+ if (ret) {
printf("%s: %s dev %d NOT available\n",
__func__, argv[2], dev);
- return CMD_RET_FAILURE;
+ return ret;
}
if ((strcmp(argv[1], "write") == 0) && (argc == 5)) {
printf("Writing GPT: ");
- ret = gpt_default(blk_dev_desc, argv[4]);
+ ret = CMD_RET_FAILURE;
+ if (blk_dev_desc)
+ ret = gpt_default(blk_dev_desc, argv[4]);
+#ifdef CONFIG_EFI_PARTITION_MTD
+ if (mtd_info)
+ ret = gpt_default_mtd(mtd_info, argv[4]);
+#endif
} else if ((strcmp(argv[1], "verify") == 0)) {
- ret = gpt_verify(blk_dev_desc, argv[4]);
+ ret = CMD_RET_FAILURE;
+ if (blk_dev_desc)
+ ret = gpt_verify(blk_dev_desc, argv[4]);
+#ifdef CONFIG_EFI_PARTITION_MTD
+ if (mtd_info)
+ ret = gpt_verify_mtd(mtd_info, argv[4]);
+#endif
printf("Verify GPT: ");
} else {
return CMD_RET_USAGE;
--
1.9.1
More information about the U-Boot
mailing list