mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] kvx: add elf bootm support
@ 2020-06-23 19:35 Clement Leger
  2020-06-23 19:35 ` [PATCH 1/4] common: bootm: allow letting IH_ARCH undefined Clement Leger
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Clement Leger @ 2020-06-23 19:35 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Clement Leger

This serie adds support for elf bootm support on KVX architecture.
First patches are allowing to build elf support for KVX and then bootm
support is added to KVX.

Clement Leger (4):
  common: bootm: allow letting IH_ARCH undefined
  common: Kconfig: remove MIPS dependency
  kvx: add D-cache inval and I-cache sync
  kvx: add support for elf loading using bootm

 arch/kvx/Kconfig                   |   5 ++
 arch/kvx/configs/generic_defconfig |   3 +-
 arch/kvx/include/asm/bootm.h       |  11 +++
 arch/kvx/include/asm/cache.h       |  24 ++++++
 arch/kvx/include/asm/elf.h         |   3 +
 arch/kvx/lib/Makefile              |   2 +-
 arch/kvx/lib/bootm.c               | 134 +++++++++++++++++++++++++++++
 common/Kconfig                     |   3 +-
 common/bootm.c                     |   2 +-
 include/image.h                    |   2 +
 10 files changed, 184 insertions(+), 5 deletions(-)
 create mode 100644 arch/kvx/include/asm/bootm.h
 create mode 100644 arch/kvx/include/asm/cache.h
 create mode 100644 arch/kvx/lib/bootm.c

-- 
2.17.1


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

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

* [PATCH 1/4] common: bootm: allow letting IH_ARCH undefined
  2020-06-23 19:35 [PATCH 0/4] kvx: add elf bootm support Clement Leger
@ 2020-06-23 19:35 ` Clement Leger
  2020-06-23 19:35 ` [PATCH 2/4] common: Kconfig: remove MIPS dependency Clement Leger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Clement Leger @ 2020-06-23 19:35 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Clement Leger

Some architecture might not want to support uImage. To do so, allow
IH_ARCH to be let undefined.

Signed-off-by: Clement Leger <cleger@kalray.eu>
---
 common/bootm.c  | 2 +-
 include/image.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 4110d8d6e..bea73fac3 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -510,7 +510,7 @@ static int bootm_open_os_uimage(struct image_data *data)
 
 	uimage_print_contents(data->os);
 
-	if (data->os->header.ih_arch != IH_ARCH) {
+	if (IH_ARCH == IH_ARCH_INVALID || data->os->header.ih_arch != IH_ARCH) {
 		printf("Unsupported Architecture 0x%x\n",
 		       data->os->header.ih_arch);
 		return -EINVAL;
diff --git a/include/image.h b/include/image.h
index 88b628bc7..0a7832f13 100644
--- a/include/image.h
+++ b/include/image.h
@@ -101,6 +101,8 @@
 #define IH_ARCH IH_ARCH_AVR32
 #elif defined(CONFIG_LINUX)
 #define IH_ARCH IH_ARCH_LINUX
+#else
+#define IH_ARCH IH_ARCH_INVALID
 #endif
 
 /*
-- 
2.17.1


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

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

* [PATCH 2/4] common: Kconfig: remove MIPS dependency
  2020-06-23 19:35 [PATCH 0/4] kvx: add elf bootm support Clement Leger
  2020-06-23 19:35 ` [PATCH 1/4] common: bootm: allow letting IH_ARCH undefined Clement Leger
@ 2020-06-23 19:35 ` Clement Leger
  2020-06-24  6:06   ` Ahmad Fatoum
  2020-06-23 19:35 ` [PATCH 3/4] kvx: add D-cache inval and I-cache sync Clement Leger
  2020-06-23 19:35 ` [PATCH 4/4] kvx: add support for elf loading using bootm Clement Leger
  3 siblings, 1 reply; 12+ messages in thread
From: Clement Leger @ 2020-06-23 19:35 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Clement Leger

There is no reason anymore to limit the use of elf on mips since there
is no elf specific support needed in architectures. Remove this
dependency and drop COMPILE_TEST config.

Signed-off-by: Clement Leger <cleger@kalray.eu>
---
 common/Kconfig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index f150092af..a3a290ad3 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -38,8 +38,7 @@ config BLOCK_WRITE
 	bool
 
 config ELF
-	bool "ELF Support" if COMPILE_TEST
-	depends on MIPS || COMPILE_TEST
+	bool
 
 config FILETYPE
 	bool
-- 
2.17.1


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

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

* [PATCH 3/4] kvx: add D-cache inval and I-cache sync
  2020-06-23 19:35 [PATCH 0/4] kvx: add elf bootm support Clement Leger
  2020-06-23 19:35 ` [PATCH 1/4] common: bootm: allow letting IH_ARCH undefined Clement Leger
  2020-06-23 19:35 ` [PATCH 2/4] common: Kconfig: remove MIPS dependency Clement Leger
@ 2020-06-23 19:35 ` Clement Leger
  2020-06-24  6:12   ` Ahmad Fatoum
  2020-06-23 19:35 ` [PATCH 4/4] kvx: add support for elf loading using bootm Clement Leger
  3 siblings, 1 reply; 12+ messages in thread
From: Clement Leger @ 2020-06-23 19:35 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Clement Leger

Before booting, we must make sure the I-cache is synchronized with the
D-cache to execute loaded instructions. In order to do that, add a
function which execute a fence to ensure every memory accesses have
been committed out of processor pipeline to memory and then invalidate
I-cache to reload from memory. Moreover add a D-cache invalidation
routine to cleanup cache before booting.

Signed-off-by: Clement Leger <cleger@kalray.eu>
---
 arch/kvx/include/asm/cache.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 arch/kvx/include/asm/cache.h

diff --git a/arch/kvx/include/asm/cache.h b/arch/kvx/include/asm/cache.h
new file mode 100644
index 000000000..efda37ebd
--- /dev/null
+++ b/arch/kvx/include/asm/cache.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2019 Kalray Inc.
+ */
+
+#ifndef __KVX_CACHE_H
+#define __KVX_CACHE_H
+
+#include <linux/types.h>
+
+static inline void sync_dcache_icache(void)
+{
+	__builtin_kvx_fence();
+	__builtin_kvx_iinval();
+	__builtin_kvx_barrier();
+}
+
+static inline void dcache_inval(void)
+{
+	__builtin_kvx_fence();
+	__builtin_kvx_dinval();
+}
+
+#endif /* __KVX_CACHE_H */
-- 
2.17.1


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

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

* [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-23 19:35 [PATCH 0/4] kvx: add elf bootm support Clement Leger
                   ` (2 preceding siblings ...)
  2020-06-23 19:35 ` [PATCH 3/4] kvx: add D-cache inval and I-cache sync Clement Leger
@ 2020-06-23 19:35 ` Clement Leger
  2020-06-24  6:17   ` Ahmad Fatoum
  3 siblings, 1 reply; 12+ messages in thread
From: Clement Leger @ 2020-06-23 19:35 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Clement Leger

From: Clement Leger <clement.leger@kalray.eu>

In order to boot elfs files, add bootm command support for kvx. This support
can boot elf files using bootm elf support. initrd and device-tree handling
is also included and loads them after the elf file load address.

Signed-off-by: Clement Leger <cleger@kalray.eu>
---
 arch/kvx/Kconfig                   |   5 ++
 arch/kvx/configs/generic_defconfig |   3 +-
 arch/kvx/include/asm/bootm.h       |  11 +++
 arch/kvx/include/asm/elf.h         |   3 +
 arch/kvx/lib/Makefile              |   2 +-
 arch/kvx/lib/bootm.c               | 134 +++++++++++++++++++++++++++++
 6 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 arch/kvx/include/asm/bootm.h
 create mode 100644 arch/kvx/lib/bootm.c

diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 5463bb4f1..3327021e1 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -1,9 +1,14 @@
 config KVX
 	bool
 	select 64BIT
+	select BOOTM
+	select BOOTM_ELF
+	select BOOTM_OFTREE
+	select BOOTM_INITRD
 	select CLKDEV_LOOKUP
 	select COMMON_CLK
 	select COMMON_CLK_OF_PROVIDER
+	select ELF
 	select FLEXIBLE_BOOTARGS
 	select GENERIC_FIND_NEXT_BIT
 	select LIBFDT
diff --git a/arch/kvx/configs/generic_defconfig b/arch/kvx/configs/generic_defconfig
index f9ff773a0..816217174 100644
--- a/arch/kvx/configs/generic_defconfig
+++ b/arch/kvx/configs/generic_defconfig
@@ -1,7 +1,8 @@
 CONFIG_AUTO_COMPLETE=y
 CONFIG_BAUDRATE=115200
-# CONFIG_BOOTM is not set
 CONFIG_CLOCKSOURCE_KVX=y
+CONFIG_CMD_BOOT=y
+CONFIG_CMD_BOOTM=y
 CONFIG_CMD_CMP=y
 CONFIG_CMD_OF_DUMP=y
 CONFIG_CMD_POWEROFF=y
diff --git a/arch/kvx/include/asm/bootm.h b/arch/kvx/include/asm/bootm.h
new file mode 100644
index 000000000..7ad7e2e87
--- /dev/null
+++ b/arch/kvx/include/asm/bootm.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Kalray Inc.
+ */
+
+#ifndef _ASM_KVX_BOOTM_H
+#define _ASM_KVX_BOOTM_H
+
+#define LINUX_BOOT_PARAM_MAGIC 0x31564752414E494CULL
+
+#endif /* _ASM_KVX_BOOTM_H */
diff --git a/arch/kvx/include/asm/elf.h b/arch/kvx/include/asm/elf.h
index 7cc09d7ba..2975ad1b9 100644
--- a/arch/kvx/include/asm/elf.h
+++ b/arch/kvx/include/asm/elf.h
@@ -11,6 +11,9 @@
  */
 #include <linux/types.h>
 
+#define EM_KVX		256
+
+#define ELF_ARCH	EM_KVX
 #define ELF_CLASS	ELFCLASS32
 #define ELF_DATA	ELFDATA2MSB
 
diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
index 352e7034a..6e56462da 100644
--- a/arch/kvx/lib/Makefile
+++ b/arch/kvx/lib/Makefile
@@ -3,4 +3,4 @@
 # Copyright (C) 2019 Kalray Inc.
 #
 
-obj-y	+= cpuinfo.o board.o dtb.o poweroff.o
+obj-y	+= cpuinfo.o board.o dtb.o poweroff.o bootm.o
diff --git a/arch/kvx/lib/bootm.c b/arch/kvx/lib/bootm.c
new file mode 100644
index 000000000..02bd0b5cf
--- /dev/null
+++ b/arch/kvx/lib/bootm.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2019 Kalray Inc.
+ */
+
+#include <elf.h>
+#include <boot.h>
+#include <init.h>
+#include <bootm.h>
+#include <binfmt.h>
+#include <common.h>
+#include <libfile.h>
+#include <linux/kernel.h>
+
+#include <asm/cache.h>
+#include <asm/bootm.h>
+
+typedef void __noreturn (*boot_func_entry)(unsigned long, void *);
+
+static int do_boot_entry(struct image_data *data, boot_func_entry entry,
+			 void *fdt_load_addr)
+{
+	printf("starting elf (entry at %p)\n", entry);
+
+	if (data->dryrun)
+		return 0;
+
+	shutdown_barebox();
+
+	/* flushes instruction and clear dcache caches before execution */
+	sync_dcache_icache();
+	dcache_inval();
+
+	/**
+	 * Parameters passing
+	 * r0: boot magic
+	 * r1: device tree pointer
+	 */
+	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
+
+	/* should never return ! */
+	panic("Returned from boot program !\n");
+
+	return -EINVAL;
+}
+
+static int do_boot_elf(struct image_data *data, struct elf_image *elf)
+{
+	int ret;
+	void *fdt;
+	boot_func_entry entry;
+	unsigned long load_addr, initrd_address;
+
+	/* load initrd after the elf */
+	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
+	if (bootm_has_initrd(data)) {
+		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
+			initrd_address = data->initrd_address;
+		else
+			initrd_address = load_addr;
+
+		printf("Loading initrd at 0x%lx\n", initrd_address);
+		ret = bootm_load_initrd(data, initrd_address);
+		if (ret) {
+			printf("Failed to load initrd\n");
+			return ret;
+		}
+
+		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
+			load_addr += resource_size(data->initrd_res);
+			load_addr = PAGE_ALIGN(load_addr);
+		}
+	}
+
+	fdt = bootm_get_devicetree(data);
+	if (IS_ERR(fdt)) {
+		printf("Failed to load dtb\n");
+		return PTR_ERR(fdt);
+	}
+
+	printf("Loading device tree at %lx\n", load_addr);
+	/* load device tree after the initrd if any */
+	ret = bootm_load_devicetree(data, fdt, load_addr);
+	if (ret) {
+		printf("Failed to load device tree: %d\n", ret);
+		goto err_free_fdt;
+	}
+
+	entry = (boot_func_entry) data->os_address;
+
+	ret = do_boot_entry(data, entry, fdt);
+
+err_free_fdt:
+	free(fdt);
+
+	return ret;
+}
+
+static int do_bootm_elf(struct image_data *data)
+{
+	int ret;
+
+	ret = bootm_load_os(data, data->os_address);
+	if (ret)
+		return ret;
+
+	return do_boot_elf(data, data->elf);
+}
+
+static struct image_handler elf_handler = {
+	.name = "ELF",
+	.bootm = do_bootm_elf,
+	.filetype = filetype_elf,
+};
+
+static struct binfmt_hook binfmt_elf_hook = {
+	.type = filetype_elf,
+	.exec = "bootm",
+};
+
+static int kvx_register_image_handler(void)
+{
+	register_image_handler(&elf_handler);
+
+	binfmt_register(&binfmt_elf_hook);
+
+	return 0;
+}
+
+late_initcall(kvx_register_image_handler);
-- 
2.17.1


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

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

* Re: [PATCH 2/4] common: Kconfig: remove MIPS dependency
  2020-06-23 19:35 ` [PATCH 2/4] common: Kconfig: remove MIPS dependency Clement Leger
@ 2020-06-24  6:06   ` Ahmad Fatoum
  0 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2020-06-24  6:06 UTC (permalink / raw)
  To: Clement Leger, Sascha Hauer, barebox

Hello Clement,

On 6/23/20 9:35 PM, Clement Leger wrote:
> There is no reason anymore to limit the use of elf on mips since there
> is no elf specific support needed in architectures. Remove this
> dependency and drop COMPILE_TEST config.
> 
> Signed-off-by: Clement Leger <cleger@kalray.eu>
> ---
>  common/Kconfig | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index f150092af..a3a290ad3 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -38,8 +38,7 @@ config BLOCK_WRITE
>  	bool
>  
>  config ELF
> -	bool "ELF Support" if COMPILE_TEST

With this line removed, you don't have a prompt symbol anymore to select it while COMPILE_TESTing.
Please reinstate. The depends can be dropped.

> -	depends on MIPS || COMPILE_TEST
> +	bool
>  
>  config FILETYPE
>  	bool
> 

-- 
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] 12+ messages in thread

* Re: [PATCH 3/4] kvx: add D-cache inval and I-cache sync
  2020-06-23 19:35 ` [PATCH 3/4] kvx: add D-cache inval and I-cache sync Clement Leger
@ 2020-06-24  6:12   ` Ahmad Fatoum
  0 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2020-06-24  6:12 UTC (permalink / raw)
  To: Clement Leger, Sascha Hauer, barebox



On 6/23/20 9:35 PM, Clement Leger wrote:
> Before booting, we must make sure the I-cache is synchronized with the
> D-cache to execute loaded instructions. In order to do that, add a
> function which execute a fence to ensure every memory accesses have
> been committed out of processor pipeline to memory and then invalidate
> I-cache to reload from memory. Moreover add a D-cache invalidation
> routine to cleanup cache before booting.
> 
> Signed-off-by: Clement Leger <cleger@kalray.eu>
> ---
>  arch/kvx/include/asm/cache.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644 arch/kvx/include/asm/cache.h
> 
> diff --git a/arch/kvx/include/asm/cache.h b/arch/kvx/include/asm/cache.h
> new file mode 100644
> index 000000000..efda37ebd
> --- /dev/null
> +++ b/arch/kvx/include/asm/cache.h
> @@ -0,0 +1,24 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2019 Kalray Inc.
> + */
> +
> +#ifndef __KVX_CACHE_H
> +#define __KVX_CACHE_H
> +
> +#include <linux/types.h>
> +
> +static inline void sync_dcache_icache(void)
> +{
> +	__builtin_kvx_fence();
> +	__builtin_kvx_iinval();
> +	__builtin_kvx_barrier();
> +}

ARCH=arm calls this sync_caches_for_execution. Using the same name
sounds like a good idea IMHO.

> +
> +static inline void dcache_inval(void)
> +{
> +	__builtin_kvx_fence();
> +	__builtin_kvx_dinval();
> +}
> +
> +#endif /* __KVX_CACHE_H */
> 

-- 
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] 12+ messages in thread

* Re: [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-23 19:35 ` [PATCH 4/4] kvx: add support for elf loading using bootm Clement Leger
@ 2020-06-24  6:17   ` Ahmad Fatoum
  2020-06-24  7:15     ` Clément Leger
  0 siblings, 1 reply; 12+ messages in thread
From: Ahmad Fatoum @ 2020-06-24  6:17 UTC (permalink / raw)
  To: Clement Leger, Sascha Hauer, barebox

On 6/23/20 9:35 PM, Clement Leger wrote:
> From: Clement Leger <clement.leger@kalray.eu>
> 
> In order to boot elfs files, add bootm command support for kvx. This support
> can boot elf files using bootm elf support. initrd and device-tree handling
> is also included and loads them after the elf file load address.
> 
> Signed-off-by: Clement Leger <cleger@kalray.eu>
> ---
>  arch/kvx/Kconfig                   |   5 ++
>  arch/kvx/configs/generic_defconfig |   3 +-
>  arch/kvx/include/asm/bootm.h       |  11 +++
>  arch/kvx/include/asm/elf.h         |   3 +
>  arch/kvx/lib/Makefile              |   2 +-
>  arch/kvx/lib/bootm.c               | 134 +++++++++++++++++++++++++++++
>  6 files changed, 156 insertions(+), 2 deletions(-)
>  create mode 100644 arch/kvx/include/asm/bootm.h
>  create mode 100644 arch/kvx/lib/bootm.c
> 
> diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
> index 5463bb4f1..3327021e1 100644
> --- a/arch/kvx/Kconfig
> +++ b/arch/kvx/Kconfig
> @@ -1,9 +1,14 @@
>  config KVX
>  	bool
>  	select 64BIT
> +	select BOOTM
> +	select BOOTM_ELF
> +	select BOOTM_OFTREE
> +	select BOOTM_INITRD
>  	select CLKDEV_LOOKUP
>  	select COMMON_CLK
>  	select COMMON_CLK_OF_PROVIDER
> +	select ELF
>  	select FLEXIBLE_BOOTARGS
>  	select GENERIC_FIND_NEXT_BIT
>  	select LIBFDT
> diff --git a/arch/kvx/configs/generic_defconfig b/arch/kvx/configs/generic_defconfig
> index f9ff773a0..816217174 100644
> --- a/arch/kvx/configs/generic_defconfig
> +++ b/arch/kvx/configs/generic_defconfig
> @@ -1,7 +1,8 @@
>  CONFIG_AUTO_COMPLETE=y
>  CONFIG_BAUDRATE=115200
> -# CONFIG_BOOTM is not set
>  CONFIG_CLOCKSOURCE_KVX=y
> +CONFIG_CMD_BOOT=y
> +CONFIG_CMD_BOOTM=y
>  CONFIG_CMD_CMP=y
>  CONFIG_CMD_OF_DUMP=y
>  CONFIG_CMD_POWEROFF=y
> diff --git a/arch/kvx/include/asm/bootm.h b/arch/kvx/include/asm/bootm.h
> new file mode 100644
> index 000000000..7ad7e2e87
> --- /dev/null
> +++ b/arch/kvx/include/asm/bootm.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2019 Kalray Inc.
> + */
> +
> +#ifndef _ASM_KVX_BOOTM_H
> +#define _ASM_KVX_BOOTM_H
> +
> +#define LINUX_BOOT_PARAM_MAGIC 0x31564752414E494CULL
> +
> +#endif /* _ASM_KVX_BOOTM_H */
> diff --git a/arch/kvx/include/asm/elf.h b/arch/kvx/include/asm/elf.h
> index 7cc09d7ba..2975ad1b9 100644
> --- a/arch/kvx/include/asm/elf.h
> +++ b/arch/kvx/include/asm/elf.h
> @@ -11,6 +11,9 @@
>   */
>  #include <linux/types.h>
>  
> +#define EM_KVX		256
> +
> +#define ELF_ARCH	EM_KVX
>  #define ELF_CLASS	ELFCLASS32
>  #define ELF_DATA	ELFDATA2MSB
>  
> diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
> index 352e7034a..6e56462da 100644
> --- a/arch/kvx/lib/Makefile
> +++ b/arch/kvx/lib/Makefile
> @@ -3,4 +3,4 @@
>  # Copyright (C) 2019 Kalray Inc.
>  #
>  
> -obj-y	+= cpuinfo.o board.o dtb.o poweroff.o
> +obj-y	+= cpuinfo.o board.o dtb.o poweroff.o bootm.o
> diff --git a/arch/kvx/lib/bootm.c b/arch/kvx/lib/bootm.c
> new file mode 100644
> index 000000000..02bd0b5cf
> --- /dev/null
> +++ b/arch/kvx/lib/bootm.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * This file is subject to the terms and conditions of the GNU General Public
> + * License.  See the file "COPYING" in the main directory of this archive
> + * for more details.
> + *
> + * Copyright (C) 2019 Kalray Inc.
> + */
> +
> +#include <elf.h>
> +#include <boot.h>
> +#include <init.h>
> +#include <bootm.h>
> +#include <binfmt.h>
> +#include <common.h>
> +#include <libfile.h>
> +#include <linux/kernel.h>
> +
> +#include <asm/cache.h>
> +#include <asm/bootm.h>
> +
> +typedef void __noreturn (*boot_func_entry)(unsigned long, void *);
> +
> +static int do_boot_entry(struct image_data *data, boot_func_entry entry,
> +			 void *fdt_load_addr)
> +{
> +	printf("starting elf (entry at %p)\n", entry);
> +
> +	if (data->dryrun)
> +		return 0;
> +
> +	shutdown_barebox();
> +
> +	/* flushes instruction and clear dcache caches before execution */
> +	sync_dcache_icache();
> +	dcache_inval();

You already flushed out the dcache contents to the point of unification.
What do you gain by invalidating it?

> +
> +	/**
> +	 * Parameters passing
> +	 * r0: boot magic
> +	 * r1: device tree pointer
> +	 */
> +	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
> +
> +	/* should never return ! */
> +	panic("Returned from boot program !\n");
> +
> +	return -EINVAL;
> +}
> +
> +static int do_boot_elf(struct image_data *data, struct elf_image *elf)
> +{
> +	int ret;
> +	void *fdt;
> +	boot_func_entry entry;
> +	unsigned long load_addr, initrd_address;
> +
> +	/* load initrd after the elf */
> +	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
> +	if (bootm_has_initrd(data)) {
> +		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
> +			initrd_address = data->initrd_address;
> +		else
> +			initrd_address = load_addr;
> +
> +		printf("Loading initrd at 0x%lx\n", initrd_address);
> +		ret = bootm_load_initrd(data, initrd_address);
> +		if (ret) {
> +			printf("Failed to load initrd\n");
> +			return ret;
> +		}
> +
> +		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
> +			load_addr += resource_size(data->initrd_res);
> +			load_addr = PAGE_ALIGN(load_addr);
> +		}
> +	}
> +
> +	fdt = bootm_get_devicetree(data);
> +	if (IS_ERR(fdt)) {
> +		printf("Failed to load dtb\n");
> +		return PTR_ERR(fdt);
> +	}
> +
> +	printf("Loading device tree at %lx\n", load_addr);
> +	/* load device tree after the initrd if any */
> +	ret = bootm_load_devicetree(data, fdt, load_addr);
> +	if (ret) {
> +		printf("Failed to load device tree: %d\n", ret);
> +		goto err_free_fdt;
> +	}
> +
> +	entry = (boot_func_entry) data->os_address;
> +
> +	ret = do_boot_entry(data, entry, fdt);
> +
> +err_free_fdt:
> +	free(fdt);
> +
> +	return ret;
> +}
> +
> +static int do_bootm_elf(struct image_data *data)
> +{
> +	int ret;
> +
> +	ret = bootm_load_os(data, data->os_address);
> +	if (ret)
> +		return ret;
> +
> +	return do_boot_elf(data, data->elf);
> +}
> +
> +static struct image_handler elf_handler = {
> +	.name = "ELF",
> +	.bootm = do_bootm_elf,
> +	.filetype = filetype_elf,
> +};
> +
> +static struct binfmt_hook binfmt_elf_hook = {
> +	.type = filetype_elf,
> +	.exec = "bootm",
> +};
> +
> +static int kvx_register_image_handler(void)
> +{
> +	register_image_handler(&elf_handler);
> +
> +	binfmt_register(&binfmt_elf_hook);
> +
> +	return 0;
> +}
> +
> +late_initcall(kvx_register_image_handler);
> 

-- 
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] 12+ messages in thread

* Re: [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-24  6:17   ` Ahmad Fatoum
@ 2020-06-24  7:15     ` Clément Leger
  2020-06-29  8:15       ` Ahmad Fatoum
  0 siblings, 1 reply; 12+ messages in thread
From: Clément Leger @ 2020-06-24  7:15 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Barebox List

Hi Ahmad,

----- On 24 Jun, 2020, at 08:17, Ahmad Fatoum a.fatoum@pengutronix.de wrote:

> On 6/23/20 9:35 PM, Clement Leger wrote:
>> From: Clement Leger <clement.leger@kalray.eu>
>> 
>> In order to boot elfs files, add bootm command support for kvx. This support
>> can boot elf files using bootm elf support. initrd and device-tree handling
>> is also included and loads them after the elf file load address.
>> 
>> Signed-off-by: Clement Leger <cleger@kalray.eu>
>> ---
>>  arch/kvx/Kconfig                   |   5 ++
>>  arch/kvx/configs/generic_defconfig |   3 +-
>>  arch/kvx/include/asm/bootm.h       |  11 +++
>>  arch/kvx/include/asm/elf.h         |   3 +
>>  arch/kvx/lib/Makefile              |   2 +-
>>  arch/kvx/lib/bootm.c               | 134 +++++++++++++++++++++++++++++
>>  6 files changed, 156 insertions(+), 2 deletions(-)
>>  create mode 100644 arch/kvx/include/asm/bootm.h
>>  create mode 100644 arch/kvx/lib/bootm.c
>> 
>> diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
>> index 5463bb4f1..3327021e1 100644
>> --- a/arch/kvx/Kconfig
>> +++ b/arch/kvx/Kconfig
>> @@ -1,9 +1,14 @@
>>  config KVX
>>  	bool
>>  	select 64BIT
>> +	select BOOTM
>> +	select BOOTM_ELF
>> +	select BOOTM_OFTREE
>> +	select BOOTM_INITRD
>>  	select CLKDEV_LOOKUP
>>  	select COMMON_CLK
>>  	select COMMON_CLK_OF_PROVIDER
>> +	select ELF
>>  	select FLEXIBLE_BOOTARGS
>>  	select GENERIC_FIND_NEXT_BIT
>>  	select LIBFDT
>> diff --git a/arch/kvx/configs/generic_defconfig
>> b/arch/kvx/configs/generic_defconfig
>> index f9ff773a0..816217174 100644
>> --- a/arch/kvx/configs/generic_defconfig
>> +++ b/arch/kvx/configs/generic_defconfig
>> @@ -1,7 +1,8 @@
>>  CONFIG_AUTO_COMPLETE=y
>>  CONFIG_BAUDRATE=115200
>> -# CONFIG_BOOTM is not set
>>  CONFIG_CLOCKSOURCE_KVX=y
>> +CONFIG_CMD_BOOT=y
>> +CONFIG_CMD_BOOTM=y
>>  CONFIG_CMD_CMP=y
>>  CONFIG_CMD_OF_DUMP=y
>>  CONFIG_CMD_POWEROFF=y
>> diff --git a/arch/kvx/include/asm/bootm.h b/arch/kvx/include/asm/bootm.h
>> new file mode 100644
>> index 000000000..7ad7e2e87
>> --- /dev/null
>> +++ b/arch/kvx/include/asm/bootm.h
>> @@ -0,0 +1,11 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (C) 2019 Kalray Inc.
>> + */
>> +
>> +#ifndef _ASM_KVX_BOOTM_H
>> +#define _ASM_KVX_BOOTM_H
>> +
>> +#define LINUX_BOOT_PARAM_MAGIC 0x31564752414E494CULL
>> +
>> +#endif /* _ASM_KVX_BOOTM_H */
>> diff --git a/arch/kvx/include/asm/elf.h b/arch/kvx/include/asm/elf.h
>> index 7cc09d7ba..2975ad1b9 100644
>> --- a/arch/kvx/include/asm/elf.h
>> +++ b/arch/kvx/include/asm/elf.h
>> @@ -11,6 +11,9 @@
>>   */
>>  #include <linux/types.h>
>>  
>> +#define EM_KVX		256
>> +
>> +#define ELF_ARCH	EM_KVX
>>  #define ELF_CLASS	ELFCLASS32
>>  #define ELF_DATA	ELFDATA2MSB
>>  
>> diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
>> index 352e7034a..6e56462da 100644
>> --- a/arch/kvx/lib/Makefile
>> +++ b/arch/kvx/lib/Makefile
>> @@ -3,4 +3,4 @@
>>  # Copyright (C) 2019 Kalray Inc.
>>  #
>>  
>> -obj-y	+= cpuinfo.o board.o dtb.o poweroff.o
>> +obj-y	+= cpuinfo.o board.o dtb.o poweroff.o bootm.o
>> diff --git a/arch/kvx/lib/bootm.c b/arch/kvx/lib/bootm.c
>> new file mode 100644
>> index 000000000..02bd0b5cf
>> --- /dev/null
>> +++ b/arch/kvx/lib/bootm.c
>> @@ -0,0 +1,134 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * This file is subject to the terms and conditions of the GNU General Public
>> + * License.  See the file "COPYING" in the main directory of this archive
>> + * for more details.
>> + *
>> + * Copyright (C) 2019 Kalray Inc.
>> + */
>> +
>> +#include <elf.h>
>> +#include <boot.h>
>> +#include <init.h>
>> +#include <bootm.h>
>> +#include <binfmt.h>
>> +#include <common.h>
>> +#include <libfile.h>
>> +#include <linux/kernel.h>
>> +
>> +#include <asm/cache.h>
>> +#include <asm/bootm.h>
>> +
>> +typedef void __noreturn (*boot_func_entry)(unsigned long, void *);
>> +
>> +static int do_boot_entry(struct image_data *data, boot_func_entry entry,
>> +			 void *fdt_load_addr)
>> +{
>> +	printf("starting elf (entry at %p)\n", entry);
>> +
>> +	if (data->dryrun)
>> +		return 0;
>> +
>> +	shutdown_barebox();
>> +
>> +	/* flushes instruction and clear dcache caches before execution */
>> +	sync_dcache_icache();
>> +	dcache_inval();
> 
> You already flushed out the dcache contents to the point of unification.
> What do you gain by invalidating it?

Indeed, this is not strictly necessary, it just allow to boot the elf without a
dirty D-cache. But actually, the booted program should invalidate its D-cache
before fetching any data to avoid using cached data. I can remove it since
this is only for some buggy programs.

> 
>> +
>> +	/**
>> +	 * Parameters passing
>> +	 * r0: boot magic
>> +	 * r1: device tree pointer
>> +	 */
>> +	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
>> +
>> +	/* should never return ! */
>> +	panic("Returned from boot program !\n");
>> +
>> +	return -EINVAL;
>> +}
>> +
>> +static int do_boot_elf(struct image_data *data, struct elf_image *elf)
>> +{
>> +	int ret;
>> +	void *fdt;
>> +	boot_func_entry entry;
>> +	unsigned long load_addr, initrd_address;
>> +
>> +	/* load initrd after the elf */
>> +	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
>> +	if (bootm_has_initrd(data)) {
>> +		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
>> +			initrd_address = data->initrd_address;
>> +		else
>> +			initrd_address = load_addr;
>> +
>> +		printf("Loading initrd at 0x%lx\n", initrd_address);
>> +		ret = bootm_load_initrd(data, initrd_address);
>> +		if (ret) {
>> +			printf("Failed to load initrd\n");
>> +			return ret;
>> +		}
>> +
>> +		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
>> +			load_addr += resource_size(data->initrd_res);
>> +			load_addr = PAGE_ALIGN(load_addr);
>> +		}
>> +	}
>> +
>> +	fdt = bootm_get_devicetree(data);
>> +	if (IS_ERR(fdt)) {
>> +		printf("Failed to load dtb\n");
>> +		return PTR_ERR(fdt);
>> +	}
>> +
>> +	printf("Loading device tree at %lx\n", load_addr);
>> +	/* load device tree after the initrd if any */
>> +	ret = bootm_load_devicetree(data, fdt, load_addr);
>> +	if (ret) {
>> +		printf("Failed to load device tree: %d\n", ret);
>> +		goto err_free_fdt;
>> +	}
>> +
>> +	entry = (boot_func_entry) data->os_address;
>> +
>> +	ret = do_boot_entry(data, entry, fdt);
>> +
>> +err_free_fdt:
>> +	free(fdt);
>> +
>> +	return ret;
>> +}
>> +
>> +static int do_bootm_elf(struct image_data *data)
>> +{
>> +	int ret;
>> +
>> +	ret = bootm_load_os(data, data->os_address);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return do_boot_elf(data, data->elf);
>> +}
>> +
>> +static struct image_handler elf_handler = {
>> +	.name = "ELF",
>> +	.bootm = do_bootm_elf,
>> +	.filetype = filetype_elf,
>> +};
>> +
>> +static struct binfmt_hook binfmt_elf_hook = {
>> +	.type = filetype_elf,
>> +	.exec = "bootm",
>> +};
>> +
>> +static int kvx_register_image_handler(void)
>> +{
>> +	register_image_handler(&elf_handler);
>> +
>> +	binfmt_register(&binfmt_elf_hook);
>> +
>> +	return 0;
>> +}
>> +
>> +late_initcall(kvx_register_image_handler);
>> 
> 
> --
> 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] 12+ messages in thread

* Re: [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-24  7:15     ` Clément Leger
@ 2020-06-29  8:15       ` Ahmad Fatoum
  2020-06-29  8:23         ` Clément Leger
  0 siblings, 1 reply; 12+ messages in thread
From: Ahmad Fatoum @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Clément Leger; +Cc: Barebox List

Hello,

On 6/24/20 9:15 AM, Clément Leger wrote:
>> You already flushed out the dcache contents to the point of unification.
>> What do you gain by invalidating it?
> 
> Indeed, this is not strictly necessary, it just allow to boot the elf without a
> dirty D-cache. But actually, the booted program should invalidate its D-cache
> before fetching any data to avoid using cached data. I can remove it since
> this is only for some buggy programs.

Why would use of cached data hurt here? If you keep the MMU throughout, you
should only need to invalidate the data cache when doing DMA. Am I missing
something?

Either way, I've no preference (except for naming it the same as on ARM,
see previous mail).

Cheers
Ahmad

> 
>>
>>> +
>>> +	/**
>>> +	 * Parameters passing
>>> +	 * r0: boot magic
>>> +	 * r1: device tree pointer
>>> +	 */
>>> +	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
>>> +
>>> +	/* should never return ! */
>>> +	panic("Returned from boot program !\n");
>>> +
>>> +	return -EINVAL;
>>> +}
>>> +
>>> +static int do_boot_elf(struct image_data *data, struct elf_image *elf)
>>> +{
>>> +	int ret;
>>> +	void *fdt;
>>> +	boot_func_entry entry;
>>> +	unsigned long load_addr, initrd_address;
>>> +
>>> +	/* load initrd after the elf */
>>> +	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
>>> +	if (bootm_has_initrd(data)) {
>>> +		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
>>> +			initrd_address = data->initrd_address;
>>> +		else
>>> +			initrd_address = load_addr;
>>> +
>>> +		printf("Loading initrd at 0x%lx\n", initrd_address);
>>> +		ret = bootm_load_initrd(data, initrd_address);
>>> +		if (ret) {
>>> +			printf("Failed to load initrd\n");
>>> +			return ret;
>>> +		}
>>> +
>>> +		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
>>> +			load_addr += resource_size(data->initrd_res);
>>> +			load_addr = PAGE_ALIGN(load_addr);
>>> +		}
>>> +	}
>>> +
>>> +	fdt = bootm_get_devicetree(data);
>>> +	if (IS_ERR(fdt)) {
>>> +		printf("Failed to load dtb\n");
>>> +		return PTR_ERR(fdt);
>>> +	}
>>> +
>>> +	printf("Loading device tree at %lx\n", load_addr);
>>> +	/* load device tree after the initrd if any */
>>> +	ret = bootm_load_devicetree(data, fdt, load_addr);
>>> +	if (ret) {
>>> +		printf("Failed to load device tree: %d\n", ret);
>>> +		goto err_free_fdt;
>>> +	}
>>> +
>>> +	entry = (boot_func_entry) data->os_address;
>>> +
>>> +	ret = do_boot_entry(data, entry, fdt);
>>> +
>>> +err_free_fdt:
>>> +	free(fdt);
>>> +
>>> +	return ret;
>>> +}
>>> +
>>> +static int do_bootm_elf(struct image_data *data)
>>> +{
>>> +	int ret;
>>> +
>>> +	ret = bootm_load_os(data, data->os_address);
>>> +	if (ret)
>>> +		return ret;
>>> +
>>> +	return do_boot_elf(data, data->elf);
>>> +}
>>> +
>>> +static struct image_handler elf_handler = {
>>> +	.name = "ELF",
>>> +	.bootm = do_bootm_elf,
>>> +	.filetype = filetype_elf,
>>> +};
>>> +
>>> +static struct binfmt_hook binfmt_elf_hook = {
>>> +	.type = filetype_elf,
>>> +	.exec = "bootm",
>>> +};
>>> +
>>> +static int kvx_register_image_handler(void)
>>> +{
>>> +	register_image_handler(&elf_handler);
>>> +
>>> +	binfmt_register(&binfmt_elf_hook);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +late_initcall(kvx_register_image_handler);
>>>
>>
>> --
>> 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 |
> 

-- 
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] 12+ messages in thread

* Re: [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-29  8:15       ` Ahmad Fatoum
@ 2020-06-29  8:23         ` Clément Leger
  2020-06-29  8:29           ` Ahmad Fatoum
  0 siblings, 1 reply; 12+ messages in thread
From: Clément Leger @ 2020-06-29  8:23 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Barebox List

Hi Ahmad

----- On 29 Jun, 2020, at 10:15, Ahmad Fatoum a.fatoum@pengutronix.de wrote:

> Hello,
> 
> On 6/24/20 9:15 AM, Clément Leger wrote:
>>> You already flushed out the dcache contents to the point of unification.
>>> What do you gain by invalidating it?
>> 
>> Indeed, this is not strictly necessary, it just allow to boot the elf without a
>> dirty D-cache. But actually, the booted program should invalidate its D-cache
>> before fetching any data to avoid using cached data. I can remove it since
>> this is only for some buggy programs.
> 
> Why would use of cached data hurt here? If you keep the MMU throughout, you
> should only need to invalidate the data cache when doing DMA. Am I missing
> something?

You are actually right, since barebox loaded the program by itself, the D-cache
contains the expected data even for the loaded program.
BTW, MMU is not enabled yet in barebox.

> 
> Either way, I've no preference (except for naming it the same as on ARM,
> see previous mail).

Sorry, I missed the points you made on my previous patchset, my mailer marked
all the mail has read :/. I will make another more through review.

Regards,

Clément

> 
> Cheers
> Ahmad
> 
>> 
>>>
>>>> +
>>>> +	/**
>>>> +	 * Parameters passing
>>>> +	 * r0: boot magic
>>>> +	 * r1: device tree pointer
>>>> +	 */
>>>> +	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
>>>> +
>>>> +	/* should never return ! */
>>>> +	panic("Returned from boot program !\n");
>>>> +
>>>> +	return -EINVAL;
>>>> +}
>>>> +
>>>> +static int do_boot_elf(struct image_data *data, struct elf_image *elf)
>>>> +{
>>>> +	int ret;
>>>> +	void *fdt;
>>>> +	boot_func_entry entry;
>>>> +	unsigned long load_addr, initrd_address;
>>>> +
>>>> +	/* load initrd after the elf */
>>>> +	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
>>>> +	if (bootm_has_initrd(data)) {
>>>> +		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
>>>> +			initrd_address = data->initrd_address;
>>>> +		else
>>>> +			initrd_address = load_addr;
>>>> +
>>>> +		printf("Loading initrd at 0x%lx\n", initrd_address);
>>>> +		ret = bootm_load_initrd(data, initrd_address);
>>>> +		if (ret) {
>>>> +			printf("Failed to load initrd\n");
>>>> +			return ret;
>>>> +		}
>>>> +
>>>> +		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
>>>> +			load_addr += resource_size(data->initrd_res);
>>>> +			load_addr = PAGE_ALIGN(load_addr);
>>>> +		}
>>>> +	}
>>>> +
>>>> +	fdt = bootm_get_devicetree(data);
>>>> +	if (IS_ERR(fdt)) {
>>>> +		printf("Failed to load dtb\n");
>>>> +		return PTR_ERR(fdt);
>>>> +	}
>>>> +
>>>> +	printf("Loading device tree at %lx\n", load_addr);
>>>> +	/* load device tree after the initrd if any */
>>>> +	ret = bootm_load_devicetree(data, fdt, load_addr);
>>>> +	if (ret) {
>>>> +		printf("Failed to load device tree: %d\n", ret);
>>>> +		goto err_free_fdt;
>>>> +	}
>>>> +
>>>> +	entry = (boot_func_entry) data->os_address;
>>>> +
>>>> +	ret = do_boot_entry(data, entry, fdt);
>>>> +
>>>> +err_free_fdt:
>>>> +	free(fdt);
>>>> +
>>>> +	return ret;
>>>> +}
>>>> +
>>>> +static int do_bootm_elf(struct image_data *data)
>>>> +{
>>>> +	int ret;
>>>> +
>>>> +	ret = bootm_load_os(data, data->os_address);
>>>> +	if (ret)
>>>> +		return ret;
>>>> +
>>>> +	return do_boot_elf(data, data->elf);
>>>> +}
>>>> +
>>>> +static struct image_handler elf_handler = {
>>>> +	.name = "ELF",
>>>> +	.bootm = do_bootm_elf,
>>>> +	.filetype = filetype_elf,
>>>> +};
>>>> +
>>>> +static struct binfmt_hook binfmt_elf_hook = {
>>>> +	.type = filetype_elf,
>>>> +	.exec = "bootm",
>>>> +};
>>>> +
>>>> +static int kvx_register_image_handler(void)
>>>> +{
>>>> +	register_image_handler(&elf_handler);
>>>> +
>>>> +	binfmt_register(&binfmt_elf_hook);
>>>> +
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +late_initcall(kvx_register_image_handler);
>>>>
>>>
>>> --
>>> 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 |
>> 
> 
> --
> 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] 12+ messages in thread

* Re: [PATCH 4/4] kvx: add support for elf loading using bootm
  2020-06-29  8:23         ` Clément Leger
@ 2020-06-29  8:29           ` Ahmad Fatoum
  0 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2020-06-29  8:29 UTC (permalink / raw)
  To: Clément Leger; +Cc: Barebox List

Hello Clement,

On 6/29/20 10:23 AM, Clément Leger wrote:
> Hi Ahmad
> 
> ----- On 29 Jun, 2020, at 10:15, Ahmad Fatoum a.fatoum@pengutronix.de wrote:
> 
>> Hello,
>>
>> On 6/24/20 9:15 AM, Clément Leger wrote:
>>>> You already flushed out the dcache contents to the point of unification.
>>>> What do you gain by invalidating it?
>>>
>>> Indeed, this is not strictly necessary, it just allow to boot the elf without a
>>> dirty D-cache. But actually, the booted program should invalidate its D-cache
>>> before fetching any data to avoid using cached data. I can remove it since
>>> this is only for some buggy programs.
>>
>> Why would use of cached data hurt here? If you keep the MMU throughout, you
>> should only need to invalidate the data cache when doing DMA. Am I missing
>> something?
> 
> You are actually right, since barebox loaded the program by itself, the D-cache
> contains the expected data even for the loaded program.
> BTW, MMU is not enabled yet in barebox.

Ah, I assumed the MMU would have been enabled, so that MMIO isn't cached/speculated
into. If the MMU is not enabled, you should only need to invalidate if the cache
contents are indeterminate on reset.

> 
>>
>> Either way, I've no preference (except for naming it the same as on ARM,
>> see previous mail).
> 
> Sorry, I missed the points you made on my previous patchset, my mailer marked
> all the mail has read :/. I will make another more through review.

No worries.

Cheers
Ahmad

> 
> Regards,
> 
> Clément
> 
>>
>> Cheers
>> Ahmad
>>
>>>
>>>>
>>>>> +
>>>>> +	/**
>>>>> +	 * Parameters passing
>>>>> +	 * r0: boot magic
>>>>> +	 * r1: device tree pointer
>>>>> +	 */
>>>>> +	entry(LINUX_BOOT_PARAM_MAGIC, (void *) fdt_load_addr);
>>>>> +
>>>>> +	/* should never return ! */
>>>>> +	panic("Returned from boot program !\n");
>>>>> +
>>>>> +	return -EINVAL;
>>>>> +}
>>>>> +
>>>>> +static int do_boot_elf(struct image_data *data, struct elf_image *elf)
>>>>> +{
>>>>> +	int ret;
>>>>> +	void *fdt;
>>>>> +	boot_func_entry entry;
>>>>> +	unsigned long load_addr, initrd_address;
>>>>> +
>>>>> +	/* load initrd after the elf */
>>>>> +	load_addr = PAGE_ALIGN((unsigned long) elf->high_addr);
>>>>> +	if (bootm_has_initrd(data)) {
>>>>> +		if (data->initrd_address != UIMAGE_INVALID_ADDRESS)
>>>>> +			initrd_address = data->initrd_address;
>>>>> +		else
>>>>> +			initrd_address = load_addr;
>>>>> +
>>>>> +		printf("Loading initrd at 0x%lx\n", initrd_address);
>>>>> +		ret = bootm_load_initrd(data, initrd_address);
>>>>> +		if (ret) {
>>>>> +			printf("Failed to load initrd\n");
>>>>> +			return ret;
>>>>> +		}
>>>>> +
>>>>> +		if (data->initrd_address == UIMAGE_INVALID_ADDRESS) {
>>>>> +			load_addr += resource_size(data->initrd_res);
>>>>> +			load_addr = PAGE_ALIGN(load_addr);
>>>>> +		}
>>>>> +	}
>>>>> +
>>>>> +	fdt = bootm_get_devicetree(data);
>>>>> +	if (IS_ERR(fdt)) {
>>>>> +		printf("Failed to load dtb\n");
>>>>> +		return PTR_ERR(fdt);
>>>>> +	}
>>>>> +
>>>>> +	printf("Loading device tree at %lx\n", load_addr);
>>>>> +	/* load device tree after the initrd if any */
>>>>> +	ret = bootm_load_devicetree(data, fdt, load_addr);
>>>>> +	if (ret) {
>>>>> +		printf("Failed to load device tree: %d\n", ret);
>>>>> +		goto err_free_fdt;
>>>>> +	}
>>>>> +
>>>>> +	entry = (boot_func_entry) data->os_address;
>>>>> +
>>>>> +	ret = do_boot_entry(data, entry, fdt);
>>>>> +
>>>>> +err_free_fdt:
>>>>> +	free(fdt);
>>>>> +
>>>>> +	return ret;
>>>>> +}
>>>>> +
>>>>> +static int do_bootm_elf(struct image_data *data)
>>>>> +{
>>>>> +	int ret;
>>>>> +
>>>>> +	ret = bootm_load_os(data, data->os_address);
>>>>> +	if (ret)
>>>>> +		return ret;
>>>>> +
>>>>> +	return do_boot_elf(data, data->elf);
>>>>> +}
>>>>> +
>>>>> +static struct image_handler elf_handler = {
>>>>> +	.name = "ELF",
>>>>> +	.bootm = do_bootm_elf,
>>>>> +	.filetype = filetype_elf,
>>>>> +};
>>>>> +
>>>>> +static struct binfmt_hook binfmt_elf_hook = {
>>>>> +	.type = filetype_elf,
>>>>> +	.exec = "bootm",
>>>>> +};
>>>>> +
>>>>> +static int kvx_register_image_handler(void)
>>>>> +{
>>>>> +	register_image_handler(&elf_handler);
>>>>> +
>>>>> +	binfmt_register(&binfmt_elf_hook);
>>>>> +
>>>>> +	return 0;
>>>>> +}
>>>>> +
>>>>> +late_initcall(kvx_register_image_handler);
>>>>>
>>>>
>>>> --
>>>> 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 |
>>>
>>
>> --
>> 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 |
> 

-- 
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] 12+ messages in thread

end of thread, other threads:[~2020-06-29  8:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 19:35 [PATCH 0/4] kvx: add elf bootm support Clement Leger
2020-06-23 19:35 ` [PATCH 1/4] common: bootm: allow letting IH_ARCH undefined Clement Leger
2020-06-23 19:35 ` [PATCH 2/4] common: Kconfig: remove MIPS dependency Clement Leger
2020-06-24  6:06   ` Ahmad Fatoum
2020-06-23 19:35 ` [PATCH 3/4] kvx: add D-cache inval and I-cache sync Clement Leger
2020-06-24  6:12   ` Ahmad Fatoum
2020-06-23 19:35 ` [PATCH 4/4] kvx: add support for elf loading using bootm Clement Leger
2020-06-24  6:17   ` Ahmad Fatoum
2020-06-24  7:15     ` Clément Leger
2020-06-29  8:15       ` Ahmad Fatoum
2020-06-29  8:23         ` Clément Leger
2020-06-29  8:29           ` Ahmad Fatoum

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