mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: stm32mp: add bootm handler for images
@ 2019-10-01 15:18 Ahmad Fatoum
  2019-10-02  7:57 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2019-10-01 15:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

STM32 images are preceded by a fixed-size 256 byte header, which is
interpreted by the TF-A first stage bootloader and isn't executable
as ARM code.

To maintain the ability to network boot them, add a bootm handler that
skips the header.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-stm32mp/Makefile     |  2 +-
 arch/arm/mach-stm32mp/stm32image.c | 50 ++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-stm32mp/stm32image.c

diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile
index 16a218658ade..204cad608f56 100644
--- a/arch/arm/mach-stm32mp/Makefile
+++ b/arch/arm/mach-stm32mp/Makefile
@@ -1 +1 @@
-obj- := __dummy__.o
+obj-$(CONFIG_BOOTM) := stm32image.o
diff --git a/arch/arm/mach-stm32mp/stm32image.c b/arch/arm/mach-stm32mp/stm32image.c
new file mode 100644
index 000000000000..84975c5c3bf1
--- /dev/null
+++ b/arch/arm/mach-stm32mp/stm32image.c
@@ -0,0 +1,50 @@
+#define pr_fmt(fmt) "stm32image: " fmt
+
+#include <bootm.h>
+#include <common.h>
+#include <init.h>
+#include <memory.h>
+#include <linux/sizes.h>
+
+#define BAREBOX_STAGE2_OFFSET	256
+
+static int do_bootm_stm32image(struct image_data *data)
+{
+	void (*barebox)(void);
+	resource_size_t start, end;
+	int ret;
+
+	ret = memory_bank_first_find_space(&start, &end);
+	if (ret)
+		return ret;
+
+	ret = bootm_load_os(data, start);
+	if (ret)
+		return ret;
+
+	barebox = (void*)start + BAREBOX_STAGE2_OFFSET;
+
+	if (data->verbose)
+		printf("Loaded barebox image to 0x%08lx\n",
+		       (unsigned long)barebox);
+
+	shutdown_barebox();
+
+	barebox();
+
+	return -EIO;
+}
+
+static struct image_handler image_handler_stm32_image_v1_handler = {
+	.name = "STM32 image (v1)",
+	.bootm = do_bootm_stm32image,
+	.filetype = filetype_stm32_image_v1,
+};
+
+static int stm32mp_register_stm32image_image_handler(void)
+{
+	register_image_handler(&image_handler_stm32_image_v1_handler);
+
+	return 0;
+}
+late_initcall(stm32mp_register_stm32image_image_handler);
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ARM: stm32mp: add bootm handler for images
  2019-10-01 15:18 [PATCH] ARM: stm32mp: add bootm handler for images Ahmad Fatoum
@ 2019-10-02  7:57 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-10-02  7:57 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Tue, Oct 01, 2019 at 05:18:08PM +0200, Ahmad Fatoum wrote:
> STM32 images are preceded by a fixed-size 256 byte header, which is
> interpreted by the TF-A first stage bootloader and isn't executable
> as ARM code.
> 
> To maintain the ability to network boot them, add a bootm handler that
> skips the header.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  arch/arm/mach-stm32mp/Makefile     |  2 +-
>  arch/arm/mach-stm32mp/stm32image.c | 50 ++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/mach-stm32mp/stm32image.c

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-02  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 15:18 [PATCH] ARM: stm32mp: add bootm handler for images Ahmad Fatoum
2019-10-02  7:57 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox