stm32mp: stm32prog: add support of RAM target
authorPatrick Delaunay <patrick.delaunay@st.com>
Wed, 18 Mar 2020 08:25:03 +0000 (09:25 +0100)
committerPatrick Delaunay <patrick.delaunay@st.com>
Thu, 14 May 2020 07:02:12 +0000 (09:02 +0200)
Add support of RAM target in flashlayout to load kernel image
("system") and device tree ("filesystem") in DDR with DFU and
start these images.

The flashlayout.tsv is:

- 0x01 fsbl Binary none 0x00000000 tf-a.stm32
- 0x03 ssbl Binary none 0x00000000 u-boot.stm32
P 0x10 kernel System ram0 0xC2000000 uImage.bin
P 0x11 dtb FileSystem ram0 0xC4000000 dtb.bin

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h

index baf9b6bd1ea3e518755a7aa4c3dc337782e48699..6bebea7ad5e22c048d303823f30f57533eef1e8b 100644 (file)
@@ -47,6 +47,7 @@ static int do_stm32prog(cmd_tbl_t *cmdtp, int flag, int argc,
        bool reset = false;
        struct image_header_s header;
        struct stm32prog_data *data;
+       u32 uimage, dtb;
 
        if (argc < 3 ||  argc > 5)
                return CMD_RET_USAGE;
@@ -118,11 +119,38 @@ static int do_stm32prog(cmd_tbl_t *cmdtp, int flag, int argc,
                goto cleanup;
        }
 
+       uimage = data->uimage;
+       dtb = data->dtb;
+
        stm32prog_clean(data);
        free(stm32prog_data);
        stm32prog_data = NULL;
 
        puts("Download done\n");
+
+       if (uimage) {
+               char boot_addr_start[20];
+               char dtb_addr[20];
+               char *bootm_argv[5] = {
+                       "bootm", boot_addr_start, "-", dtb_addr, NULL
+               };
+               if (!dtb)
+                       bootm_argv[3] = env_get("fdtcontroladdr");
+               else
+                       snprintf(dtb_addr, sizeof(dtb_addr) - 1,
+                                "0x%x", dtb);
+
+               snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
+                        "0x%x", uimage);
+               printf("Booting kernel at %s - %s...\n\n\n",
+                      boot_addr_start, bootm_argv[3]);
+               /* Try bootm for legacy and FIT format image */
+               if (genimg_get_format((void *)uimage) != IMAGE_FORMAT_INVALID)
+                       do_bootm(cmdtp, 0, 4, bootm_argv);
+               else if CONFIG_IS_ENABLED(CMD_BOOTZ)
+                       do_bootz(cmdtp, 0, 4, bootm_argv);
+       }
+
        if (reset) {
                puts("Reset...\n");
                run_command("reset", 0);
index 0967bbc11ab0d9c2ad1ccf51e43ad4b9318aae84..cc303214cf6d5470ce7c567bfe7bdb31f5487080 100644 (file)
@@ -272,6 +272,9 @@ static int parse_ip(struct stm32prog_data *data,
        } else if (!strncmp(p, "spi-nand", 8)) {
                part->target = STM32PROG_SPI_NAND;
                len = 8;
+       } else if (!strncmp(p, "ram", 3)) {
+               part->target = STM32PROG_RAM;
+               len = 0;
        } else {
                result = -EINVAL;
        }
@@ -610,6 +613,11 @@ static int init_device(struct stm32prog_data *data,
                dev->mtd = mtd;
                break;
 #endif
+       case STM32PROG_RAM:
+               first_addr = gd->bd->bi_dram[0].start;
+               last_addr = first_addr + gd->bd->bi_dram[0].size;
+               dev->erase_size = 1;
+               break;
        default:
                stm32prog_err("unknown device type = %d", dev->target);
                return -ENODEV;
@@ -1022,7 +1030,11 @@ static int stm32prog_alt_add(struct stm32prog_data *data,
                          part->name, part->id,
                          size, multiplier, type);
 
-       if (part->part_type == RAW_IMAGE) {
+       if (part->target == STM32PROG_RAM) {
+               offset += snprintf(buf + offset, ALT_BUF_LEN - offset,
+                                  "ram 0x%llx 0x%llx",
+                                  part->addr, part->size);
+       } else if (part->part_type == RAW_IMAGE) {
                u64 dfu_size;
 
                if (part->dev->target == STM32PROG_MMC)
@@ -1073,6 +1085,10 @@ static int stm32prog_alt_add(struct stm32prog_data *data,
                get_mtd_by_target(devstr, part->target, part->dev_id);
                break;
 #endif
+       case STM32PROG_RAM:
+               sprintf(dfustr, "ram");
+               sprintf(devstr, "0");
+               break;
        default:
                stm32prog_err("invalid target: %d", part->target);
                return -ENODEV;
@@ -1440,6 +1456,13 @@ static void stm32prog_end_phase(struct stm32prog_data *data)
        if (!data->cur_part)
                return;
 
+       if (data->cur_part->target == STM32PROG_RAM) {
+               if (data->cur_part->part_type == PART_SYSTEM)
+                       data->uimage = data->cur_part->addr;
+               if (data->cur_part->part_type == PART_FILESYSTEM)
+                       data->dtb = data->cur_part->addr;
+       }
+
        if (CONFIG_IS_ENABLED(MMC) &&
            data->cur_part->part_id < 0) {
                char cmdbuf[60];
@@ -1569,6 +1592,10 @@ static int part_delete(struct stm32prog_data *data,
                }
                break;
 #endif
+       case STM32PROG_RAM:
+               printf("on ram: ");
+               memset((void *)(uintptr_t)part->addr, 0, (size_t)part->size);
+               break;
        default:
                ret = -1;
                stm32prog_err("%s (0x%x): erase invalid", part->name, part->id);
index c4fdb5b8c3896e15850038c1ebe78f4e09eee0cc..bae4e91c01dce0ddc0df8ec2415ea17633a5a952 100644 (file)
@@ -27,7 +27,8 @@ enum stm32prog_target {
        STM32PROG_MMC,
        STM32PROG_NAND,
        STM32PROG_NOR,
-       STM32PROG_SPI_NAND
+       STM32PROG_SPI_NAND,
+       STM32PROG_RAM
 };
 
 enum stm32prog_link_t {
@@ -136,6 +137,10 @@ struct stm32prog_data {
        u8      *buffer; /* size = USART_RAM_BUFFER_SIZE*/
        int     dfu_seq;
        u8      read_phase;
+
+       /* bootm information */
+       u32     uimage;
+       u32     dtb;
 };
 
 extern struct stm32prog_data *stm32prog_data;