mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init
@ 2019-12-10 22:03 Lucas Stach
  2019-12-10 22:03 ` [PATCH 2/4] ARM: zynq: zedboard: allow lowlevel init to be called as second stage Lucas Stach
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lucas Stach @ 2019-12-10 22:03 UTC (permalink / raw)
  To: barebox

Move the PS7 inititalization into its own function. This helps
readability and logically splits the FPGA toolchain generated
setup from the reset of the board init.

Also execute the PS7 setup after the lowlevel CPU init, as this
is the regular order used in the Barebox codebase.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 arch/arm/boards/avnet-zedboard/lowlevel.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/avnet-zedboard/lowlevel.c b/arch/arm/boards/avnet-zedboard/lowlevel.c
index 93e4da96ecd4..b50c36b28869 100644
--- a/arch/arm/boards/avnet-zedboard/lowlevel.c
+++ b/arch/arm/boards/avnet-zedboard/lowlevel.c
@@ -29,11 +29,8 @@
 
 extern char __dtb_zynq_zed_start[];
 
-ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
+static void avnet_zedboard_ps7_init(void)
 {
-
-	void *fdt = __dtb_zynq_zed_start + get_runtime_offset();
-
 	/* open sesame */
 	writel(0x0000DF0D, ZYNQ_SLCR_UNLOCK);
 
@@ -260,8 +257,16 @@ ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
 
 	/* lock up. secure, secure */
 	writel(0x0000767B, ZYNQ_SLCR_LOCK);
+}
+
+ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
+{
+
+	void *fdt = __dtb_zynq_zed_start + get_runtime_offset();
 
 	arm_cpu_lowlevel_init();
 
+	avnet_zedboard_ps7_init();
+
 	barebox_arm_entry(0, SZ_512M, fdt);
 }
-- 
2.23.0


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

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

* [PATCH 2/4] ARM: zynq: zedboard: allow lowlevel init to be called as second stage
  2019-12-10 22:03 [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Lucas Stach
@ 2019-12-10 22:03 ` Lucas Stach
  2019-12-10 22:03 ` [PATCH 3/4] filetype: add Zynq image type Lucas Stach
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Lucas Stach @ 2019-12-10 22:03 UTC (permalink / raw)
  To: barebox

If the code is already executing in DRAM, the PS7 init must not be
executed, as it initializes the DRAM controller.

As the OCM can be configured to an address which aliases with the DRAM
address space we can't reliably infer if we are running from OCM or
DRAM from the execution address. So instead of using the address, look
at the OCM mapping, as the BootROM leaves a quite unique mapping behind
with 192KB OCM mapped at the low address and 64KB mapped to the high
address.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 arch/arm/boards/avnet-zedboard/lowlevel.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boards/avnet-zedboard/lowlevel.c b/arch/arm/boards/avnet-zedboard/lowlevel.c
index b50c36b28869..9b90ef112b46 100644
--- a/arch/arm/boards/avnet-zedboard/lowlevel.c
+++ b/arch/arm/boards/avnet-zedboard/lowlevel.c
@@ -31,6 +31,16 @@ extern char __dtb_zynq_zed_start[];
 
 static void avnet_zedboard_ps7_init(void)
 {
+	/*
+	 * Read OCM mapping configuration, if only the upper 64 KByte are
+	 * mapped to the high address, it's very likely that we just got control
+	 * from the BootROM. If the mapping is changed something other than the
+	 * BootROM was running before us. Skip PS7 init to avoid cutting the
+	 * branch we are sitting on in that case.
+	 */
+	if ((readl(0xf8000910) & 0xf) != 0x8)
+		return;
+
 	/* open sesame */
 	writel(0x0000DF0D, ZYNQ_SLCR_UNLOCK);
 
-- 
2.23.0


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

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

* [PATCH 3/4] filetype: add Zynq image type
  2019-12-10 22:03 [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Lucas Stach
  2019-12-10 22:03 ` [PATCH 2/4] ARM: zynq: zedboard: allow lowlevel init to be called as second stage Lucas Stach
@ 2019-12-10 22:03 ` Lucas Stach
  2019-12-10 22:03 ` [PATCH 4/4] ARM: zynq: add Zynq image bootm handler Lucas Stach
  2019-12-11  8:52 ` [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Lucas Stach @ 2019-12-10 22:03 UTC (permalink / raw)
  To: barebox

Use the 2 invariant words (width detection and image identification)
from the Zynq image header to detect the filetype.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 common/filetype.c  | 4 ++++
 include/filetype.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 39fea45edff5..fd6e8e3d1c35 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -80,6 +80,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_ubootvar] = { "U-Boot environmemnt variable data",
 				"ubootvar" },
 	[filetype_stm32_image_v1] = { "STM32 image (v1)", "stm32-image-v1" },
+	[filetype_zynq_image] = { "Zynq image", "zynq-image" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -392,6 +393,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (is_imx_flash_header_v2(_buf))
 		return filetype_imx_image_v2;
 
+	if (buf[8] == 0xAA995566 && buf[9] == 0x584C4E58)
+		return filetype_zynq_image;
+
 	return filetype_unknown;
 }
 
diff --git a/include/filetype.h b/include/filetype.h
index 90a03de58105..db95fdaa0a5f 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -49,6 +49,7 @@ enum filetype {
 	filetype_layerscape_qspi_image,
 	filetype_ubootvar,
 	filetype_stm32_image_v1,
+	filetype_zynq_image,
 	filetype_max,
 };
 
-- 
2.23.0


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

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

* [PATCH 4/4] ARM: zynq: add Zynq image bootm handler
  2019-12-10 22:03 [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Lucas Stach
  2019-12-10 22:03 ` [PATCH 2/4] ARM: zynq: zedboard: allow lowlevel init to be called as second stage Lucas Stach
  2019-12-10 22:03 ` [PATCH 3/4] filetype: add Zynq image type Lucas Stach
@ 2019-12-10 22:03 ` Lucas Stach
  2019-12-11  8:52 ` [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Lucas Stach @ 2019-12-10 22:03 UTC (permalink / raw)
  To: barebox

This adds a bootm handler for the Zynq image, to allow second
stage booting of a unchanged Zynq boot image.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 arch/arm/mach-zynq/Makefile        |  2 +-
 arch/arm/mach-zynq/bootm-zynqimg.c | 49 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-zynq/bootm-zynqimg.c

diff --git a/arch/arm/mach-zynq/Makefile b/arch/arm/mach-zynq/Makefile
index 3252247d176d..c88ab4666f0f 100644
--- a/arch/arm/mach-zynq/Makefile
+++ b/arch/arm/mach-zynq/Makefile
@@ -1 +1 @@
-obj-y += zynq.o
+obj-y += zynq.o bootm-zynqimg.o
diff --git a/arch/arm/mach-zynq/bootm-zynqimg.c b/arch/arm/mach-zynq/bootm-zynqimg.c
new file mode 100644
index 000000000000..e903ab667905
--- /dev/null
+++ b/arch/arm/mach-zynq/bootm-zynqimg.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <bootm.h>
+#include <common.h>
+#include <init.h>
+#include <memory.h>
+
+static int do_bootm_zynqimage(struct image_data *data)
+{
+	resource_size_t start, end;
+	void (*barebox)(void);
+	u32 *header;
+	int ret;
+
+	ret = memory_bank_first_find_space(&start, &end);
+	if (ret)
+		return ret;
+
+	ret = bootm_load_os(data, start);
+	if (ret)
+		return ret;
+
+	header = (u32*)start;
+	barebox = (void*)start + header[12];
+
+	if (data->verbose)
+		printf("Loaded barebox image to 0x%08lx\n",
+		       (unsigned long)barebox);
+
+	shutdown_barebox();
+
+	barebox();
+
+	return -EIO;
+}
+
+static struct image_handler zynq_image_handler = {
+	.name = "Zynq image",
+	.bootm = do_bootm_zynqimage,
+	.filetype = filetype_zynq_image,
+};
+
+static int zynq_register_image_handler(void)
+{
+	register_image_handler(&zynq_image_handler);
+
+	return 0;
+}
+late_initcall(zynq_register_image_handler);
-- 
2.23.0


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

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

* Re: [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init
  2019-12-10 22:03 [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Lucas Stach
                   ` (2 preceding siblings ...)
  2019-12-10 22:03 ` [PATCH 4/4] ARM: zynq: add Zynq image bootm handler Lucas Stach
@ 2019-12-11  8:52 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2019-12-11  8:52 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Tue, Dec 10, 2019 at 11:03:19PM +0100, Lucas Stach wrote:
> Move the PS7 inititalization into its own function. This helps
> readability and logically splits the FPGA toolchain generated
> setup from the reset of the board init.
> 
> Also execute the PS7 setup after the lowlevel CPU init, as this
> is the regular order used in the Barebox codebase.
> 
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  arch/arm/boards/avnet-zedboard/lowlevel.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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] 5+ messages in thread

end of thread, other threads:[~2019-12-11  8:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 22:03 [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Lucas Stach
2019-12-10 22:03 ` [PATCH 2/4] ARM: zynq: zedboard: allow lowlevel init to be called as second stage Lucas Stach
2019-12-10 22:03 ` [PATCH 3/4] filetype: add Zynq image type Lucas Stach
2019-12-10 22:03 ` [PATCH 4/4] ARM: zynq: add Zynq image bootm handler Lucas Stach
2019-12-11  8:52 ` [PATCH 1/4] ARM: zynq: zedboard: split out PS7 init Sascha Hauer

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