[U-Boot] [PATCH 0/5] stm32mp1: add support of M4 coprocessor firmware

Activate remoteproc and add the M4 coprocessor support of firmware in stm32mp157 U-Boot.
The M4 firmware can be loaded manually (with remoteproc command) or automatically (with config selected in FIT including the M4 firmware with extlinux for example).
Patrick Delaunay (5): stm32mp1: Add remoteproc support for m4 coprocessor image: add new "copro" image type stm32mp1: Add copro image support for M4 firmware stm32mp1: add example files for FIT generation stm32mp1: update README for remoteproc support
arch/arm/dts/stm32mp157a-dk1.dts | 6 ++ arch/arm/dts/stm32mp157c-ed1.dts | 6 ++ arch/arm/dts/stm32mp157c.dtsi | 20 ++++++ board/st/stm32mp1/README | 36 +++++++++- board/st/stm32mp1/extlinux.conf | 20 ++++++ board/st/stm32mp1/fit_copro_kernel_dtb.its | 103 +++++++++++++++++++++++++++++ board/st/stm32mp1/fit_kernel_dtb.its | 82 +++++++++++++++++++++++ board/st/stm32mp1/stm32mp1.c | 24 +++++++ common/image.c | 1 + configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_optee_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + drivers/remoteproc/stm32_copro.c | 2 +- include/image.h | 1 + 14 files changed, 301 insertions(+), 3 deletions(-) create mode 100644 board/st/stm32mp1/extlinux.conf create mode 100644 board/st/stm32mp1/fit_copro_kernel_dtb.its create mode 100644 board/st/stm32mp1/fit_kernel_dtb.its

Alignment with kernel patch proposal for binding:
[PATCH v4 0/8] stm32 m4 remoteproc on STM32MP157c https://lkml.org/lkml/2019/5/14/159
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
arch/arm/dts/stm32mp157a-dk1.dts | 6 ++++++ arch/arm/dts/stm32mp157c-ed1.dts | 6 ++++++ arch/arm/dts/stm32mp157c.dtsi | 20 ++++++++++++++++++++ configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_optee_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + drivers/remoteproc/stm32_copro.c | 2 +- 7 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/arch/arm/dts/stm32mp157a-dk1.dts b/arch/arm/dts/stm32mp157a-dk1.dts index adb2464..330b8d0 100644 --- a/arch/arm/dts/stm32mp157a-dk1.dts +++ b/arch/arm/dts/stm32mp157a-dk1.dts @@ -241,6 +241,12 @@ status = "okay"; };
+&m4_rproc { + mboxes = <&ipcc 0>, <&ipcc 1>, <&ipcc 2>; + mbox-names = "vq0", "vq1", "shutdown"; + status = "okay"; +}; + &pwr { pwr-supply = <&vdd>; }; diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed1.dts index 11981d6..31f448b 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -201,6 +201,12 @@ status = "okay"; };
+&m4_rproc { + mboxes = <&ipcc 0>, <&ipcc 1>, <&ipcc 2>; + mbox-names = "vq0", "vq1", "shutdown"; + status = "okay"; +}; + &pwr { pwr-supply = <&vdd>; }; diff --git a/arch/arm/dts/stm32mp157c.dtsi b/arch/arm/dts/stm32mp157c.dtsi index d15fba0..d851929 100644 --- a/arch/arm/dts/stm32mp157c.dtsi +++ b/arch/arm/dts/stm32mp157c.dtsi @@ -1363,4 +1363,24 @@ status = "disabled"; }; }; + + mlahb { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + dma-ranges = <0x00000000 0x38000000 0x10000>, + <0x10000000 0x10000000 0x60000>, + <0x30000000 0x30000000 0x60000>; + + m4_rproc: m4@10000000 { + compatible = "st,stm32mp1-m4"; + reg = <0x10000000 0x40000>, + <0x30000000 0x40000>, + <0x38000000 0x10000>; + resets = <&rcc MCU_R>; + st,syscfg-holdboot = <&rcc 0x10C 0x1>; + st,syscfg-tz = <&rcc 0x000 0x1>; + status = "disabled"; + }; + }; }; diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 27b8525..4ef9c0b 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -32,6 +32,7 @@ CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y diff --git a/configs/stm32mp15_optee_defconfig b/configs/stm32mp15_optee_defconfig index 0565e5e..d3e990e 100644 --- a/configs/stm32mp15_optee_defconfig +++ b/configs/stm32mp15_optee_defconfig @@ -23,6 +23,7 @@ CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 844cbcd..c4d2516 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -22,6 +22,7 @@ CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y diff --git a/drivers/remoteproc/stm32_copro.c b/drivers/remoteproc/stm32_copro.c index de3b972..ad941f6 100644 --- a/drivers/remoteproc/stm32_copro.c +++ b/drivers/remoteproc/stm32_copro.c @@ -243,7 +243,7 @@ static const struct dm_rproc_ops stm32_copro_ops = { };
static const struct udevice_id stm32_copro_ids[] = { - {.compatible = "st,stm32mp1-rproc"}, + {.compatible = "st,stm32mp1-m4"}, {} };

Define new image type for coprocessor images. It is used in FIT to identify the files loaded with remoteproc command (elf or bin).
Signed-off-by: Loic Pallardy loic.pallardy@st.com Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
common/image.c | 1 + include/image.h | 1 + 2 files changed, 2 insertions(+)
diff --git a/common/image.c b/common/image.c index 4958831..f65c3e9 100644 --- a/common/image.c +++ b/common/image.c @@ -174,6 +174,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_PMMC, "pmmc", "TI Power Management Micro-Controller Firmware",}, { IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" }, { IH_TYPE_MTKIMAGE, "mtk_image", "MediaTek BootROM loadable Image" }, + { IH_TYPE_COPRO, "copro", "Coprocessor Image"}, { -1, "", "", }, };
diff --git a/include/image.h b/include/image.h index 27d7cb9..64a694f 100644 --- a/include/image.h +++ b/include/image.h @@ -283,6 +283,7 @@ enum { IH_TYPE_MTKIMAGE, /* MediaTek BootROM loadable Image */ IH_TYPE_IMX8MIMAGE, /* Freescale IMX8MBoot Image */ IH_TYPE_IMX8IMAGE, /* Freescale IMX8Boot Image */ + IH_TYPE_COPRO, /* Coprocessor Image for remoteproc*/
IH_TYPE_COUNT, /* Number of image types */ };

On Fri, 2 Aug 2019 at 07:07, Patrick Delaunay patrick.delaunay@st.com wrote:
Define new image type for coprocessor images. It is used in FIT to identify the files loaded with remoteproc command (elf or bin).
Signed-off-by: Loic Pallardy loic.pallardy@st.com Signed-off-by: Patrick Delaunay patrick.delaunay@st.com
common/image.c | 1 + include/image.h | 1 + 2 files changed, 2 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Implements copro image loading with FIT. Once image is loaded with remoteproc, the M4 coprocessor is automatically started.
Signed-off-by: Loic Pallardy loic.pallardy@st.com Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
board/st/stm32mp1/stm32mp1.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index b99c6c0..629fb63 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -17,6 +17,7 @@ #include <mtd.h> #include <mtd_node.h> #include <phy.h> +#include <remoteproc.h> #include <reset.h> #include <syscon.h> #include <usb.h> @@ -770,3 +771,26 @@ int ft_board_setup(void *blob, bd_t *bd) return 0; } #endif + +static void board_copro_image_process(ulong fw_image, size_t fw_size) +{ + int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ + + if (!rproc_is_initialized()) + if (rproc_init()) { + printf("Remote Processor %d initialization failed\n", + id); + return; + } + + ret = rproc_load(id, fw_image, fw_size); + printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n", + id, fw_image, fw_size, ret ? " Failed!" : " Success!"); + + if (!ret) { + rproc_start(id); + env_set("copro_state", "booted"); + } +} + +U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);

Add example of its files to generate FIT to start kernel on ev1 or dk2 board with - only kernel and dtb = fit_copro_kernel_dtb.its - kernel, M4 copro firmware and dtb = it_copro_kernel_dtb.its
Add extlinux example to manage config in generated FIT.
Signed-off-by: Loic Pallardy loic.pallardy@st.com Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
board/st/stm32mp1/extlinux.conf | 20 ++++++ board/st/stm32mp1/fit_copro_kernel_dtb.its | 103 +++++++++++++++++++++++++++++ board/st/stm32mp1/fit_kernel_dtb.its | 82 +++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 board/st/stm32mp1/extlinux.conf create mode 100644 board/st/stm32mp1/fit_copro_kernel_dtb.its create mode 100644 board/st/stm32mp1/fit_kernel_dtb.its
diff --git a/board/st/stm32mp1/extlinux.conf b/board/st/stm32mp1/extlinux.conf new file mode 100644 index 0000000..2b46328 --- /dev/null +++ b/board/st/stm32mp1/extlinux.conf @@ -0,0 +1,20 @@ +# Generic Distro Configuration for STM32MP157 +menu title Select the boot mode +TIMEOUT 20 +DEFAULT stm32mp157c-ev1 + +LABEL stm32mp157c-ev1 + KERNEL /fit_kernel_dtb.itb#ev1 + APPEND root=/dev/mmcblk0p6 rootwait rw earlyprintk console=ttyS3,115200 + +LABEL stm32mp157c-ev1-m4 + KERNEL /fit_copro_kernel_dtb.itb#ev1-m4 + APPEND root=/dev/mmcblk0p6 rootwait rw earlyprintk console=ttyS3,115200 + +LABEL stm32mp157c-dk2 + KERNEL /fit_kernel_dtb.itb#dk2 + APPEND root=/dev/mmcblk0p6 rootwait rw earlyprintk console=ttyS3,115200 + +LABEL stm32mp157c-dk2-m4 + KERNEL /fit_copro_kernel_dtb.itb#dk2-m4 + APPEND root=/dev/mmcblk0p6 rootwait rw earlyprintk console=ttyS3,115200 diff --git a/board/st/stm32mp1/fit_copro_kernel_dtb.its b/board/st/stm32mp1/fit_copro_kernel_dtb.its new file mode 100644 index 0000000..3e08fd9 --- /dev/null +++ b/board/st/stm32mp1/fit_copro_kernel_dtb.its @@ -0,0 +1,103 @@ +/* + * Compilation: + * mkimage -f fit_copro_kernel_dtb.its fit_copro_kernel_dtb.itb + */ + +/dts-v1/; +/ { + description = "U-Boot fitImage for stm32mp157"; + #address-cells = <1>; + + images { + + copro { + description = "M4 copro"; + data = /incbin/("rproc-m4-fw.elf"); + type = "copro"; + arch = "arm"; + compression = "none"; + load = <0xC0800000>; + hash-1 { + algo = "sha1"; + }; + }; + + kernel { + description = "Linux kernel"; + data = /incbin/("zImage"); + type = "kernel"; + arch = "arm"; + os = "linux"; + compression = "none"; + load = <0xC0008000>; + entry = <0xC0008000>; + hash-1 { + algo = "sha1"; + }; + }; + + fdt-dk2 { + description = "FDT dk2"; + data = /incbin/("stm32mp157c-dk2.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + hash-1 { + algo = "sha1"; + }; + }; + + fdt-ev1 { + description = "FDT ev1"; + data = /incbin/("stm32mp157c-ev1.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + hash-1 { + algo = "sha1"; + }; + }; + }; + + configurations { + default = "dk2-m4"; + + dk2-m4 { + description = "dk2-m4"; + loadables = "copro"; + kernel = "kernel"; + fdt = "fdt-dk2"; + hash-1 { + algo = "sha1"; + }; + }; + + dk2 { + description = "dk2"; + kernel = "kernel"; + fdt = "fdt-dk2"; + hash-1 { + algo = "sha1"; + }; + }; + + ev1-m4 { + description = "ev1-m4"; + loadables = "copro"; + kernel = "kernel"; + fdt = "fdt-ev1"; + hash-1 { + algo = "sha1"; + }; + }; + + ev1 { + description = "ev1"; + kernel = "kernel"; + fdt = "fdt-ev1"; + hash-1 { + algo = "sha1"; + }; + }; + }; +}; diff --git a/board/st/stm32mp1/fit_kernel_dtb.its b/board/st/stm32mp1/fit_kernel_dtb.its new file mode 100644 index 0000000..18d03eb --- /dev/null +++ b/board/st/stm32mp1/fit_kernel_dtb.its @@ -0,0 +1,82 @@ +/* + * Compilation: + * mkimage -f fit_kernel_dtb.its fit_kernel_dtb.itb + * + * Files in linux build dir: + * - arch/arm/boot/zImage + * - arch/arm/boot/dts/stm32mp157c-dk2.dtb + * - arch/arm/boot/dts/stm32mp157c-ev1.dtb + * + * load mmc 0:4 $kernel_addr_r fit_kernel_dtb.itb + * bootm $kernel_addr_r + * bootm $kernel_addr_r#dk2 + * bootm $kernel_addr_r#ev1 + * + * or use extlinux.conf in this directory + */ + +/dts-v1/; +/ { + description = "U-Boot fitImage for stm32mp157"; + #address-cells = <1>; + + images { + kernel { + description = "Linux kernel"; + data = /incbin/("zImage"); + type = "kernel"; + arch = "arm"; + os = "linux"; + compression = "none"; + load = <0xC0008000>; + entry = <0xC0008000>; + hash-1 { + algo = "sha1"; + }; + }; + + fdt-dk2 { + description = "FDT dk2"; + data = /incbin/("stm32mp157c-dk2.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + hash-1 { + algo = "sha1"; + }; + }; + + fdt-ev1 { + description = "FDT ev1"; + data = /incbin/("stm32mp157c-ev1.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + hash-1 { + algo = "sha1"; + }; + }; + }; + + configurations { + default = "dk2"; + + dk2 { + description = "dk2"; + kernel = "kernel"; + fdt = "fdt-dk2"; + hash-1 { + algo = "sha1"; + }; + }; + + ev1 { + description = "ev1"; + kernel = "kernel"; + fdt = "fdt-ev1"; + hash-1 { + algo = "sha1"; + }; + }; + }; +};

Add information for remoteproc usage to load firmware in M4 coprocessor on stm32mp157.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
board/st/stm32mp1/README | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/board/st/stm32mp1/README b/board/st/stm32mp1/README index 428357c..c807e08 100644 --- a/board/st/stm32mp1/README +++ b/board/st/stm32mp1/README @@ -139,7 +139,6 @@ the supported device trees for stm32mp157 are:
# make DEVICE_TREE=<name> all
- example: a) trusted boot on ev1 # export KBUILD_OUTPUT=stm32mp15_trusted @@ -190,7 +189,7 @@ the supported device trees for stm32mp157 are: 6. Switch Setting for Boot Mode ===============================
-You can select the boot mode, on the board ed1 with the switch SW1 +You can select the boot mode, on the board with one switch :
- on the daugther board ed1 with the switch SW1 : BOOT0, BOOT1, BOOT2
@@ -358,3 +357,36 @@ on bank 0 to access to internal OTP: 4 check env update STM32MP> print ethaddr ethaddr=12:34:56:78:9a:bc + +10. Coprocessor firmware +======================== + +U-Boot can boot the coprocessor before the kernel (coprocessor early boot). + +A/ Manuallly by using rproc commands (update the bootcmd) + Configurations + # env set name_copro "rproc-m4-fw.elf" + # env set dev_copro 0 + # env set loadaddr_copro 0xC1000000 + + Load binary from bootfs partition (number 4) on SDCard (mmc 0) + # ext4load mmc 0:4 ${loadaddr_copro} ${name_copro} + => ${filesize} updated with the size of the loaded file + + Start M4 firmware with remote proc command + # rproc init + # rproc load ${dev_copro} ${loadaddr_copro} ${filesize} + # rproc start ${dev_copro} + +B/ Automatically by using FIT feature and generic DISTRO bootcmd + + see examples in this directory : + + Generate FIT including kernel + device tree + M4 firmware + with cfg with M4 boot + $> mkimage -f fit_copro_kernel_dtb.its fit_copro_kernel_dtb.itb + + Then using DISTRO configuration file: see extlinux.conf to select + the correct configuration + => stm32mp157c-ev1-m4 + => stm32mp157c-dk2-m4
participants (2)
-
Patrick Delaunay
-
Simon Glass