[U-Boot] [PATCH v4 0/5] Add FreeBSD kconfig options

This series of patches add the needed bits for booting the FreeBSD loader and kernel. FreeBSD loader and kernel needs the U-Boot API and dcache/icache flushed for it to run so add this operation in go/bootelf command and when closing the API. Also add some some boot command that locate and run the FreeBSD loader if found.
Changes in v4: Convert boards to CONFIG_API Change commit log for patch 3 to be not FreeBSD specific and add Reviewed-By Change patch order.
Changes in v3: Always flush icache/dcache if enabled for bootelf/go commands Correct some typos Point to api/README in the help of Kconfig API
Changes in v2: Remove SYS_DCACHE_OFF option Flush dcache/icache in go/boot command Flush dcache/icache in API closedev
Emmanuel Vadot (4): kconfig: Add API kconfig file api: Convert to Kconfig distro_bootcmd: Add command to run FreeBSD kconfig: Add a DISTRO_FREEBSD option
Warner Losh (1): api: bootelf: go: flush cache before starting
Kconfig | 2 ++ api/Kconfig | 9 +++++++++ api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ common/Kconfig | 11 +++++++++++ configs/PMC440_defconfig | 1 + configs/lsxhl_defconfig | 1 + include/config_distro_bootcmd.h | 32 ++++++++++++++++++++++++++++++++ include/configs/PMC440.h | 2 -- include/configs/lsxl.h | 5 ----- scripts/config_whitelist.txt | 1 - 12 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 api/Kconfig

Add kconfig file to enable API support
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com --- Kconfig | 2 ++ api/Kconfig | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 api/Kconfig
diff --git a/Kconfig b/Kconfig index 8f9ea97f3d..2a65f07044 100644 --- a/Kconfig +++ b/Kconfig @@ -308,6 +308,8 @@ config ARCH_FIXUP_FDT_MEMORY
endmenu # Boot images
+source "api/Kconfig" + source "common/Kconfig"
source "cmd/Kconfig" diff --git a/api/Kconfig b/api/Kconfig new file mode 100644 index 0000000000..16731d3b4b --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API" + +config API + bool "Enable U-Boot API" + default n + help + This option enables the U-Boot API. See api/README for more information. + +endmenu

On Tue, Jan 31, 2017 at 12:17:04PM +0100, Emmanuel Vadot wrote:
Add kconfig file to enable API support
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Reviewed-by: Tom Rini trini@konsulko.com

On 31 January 2017 at 03:17, Emmanuel Vadot manu@bidouilliste.com wrote:
Add kconfig file to enable API support
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Kconfig | 2 ++ api/Kconfig | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 api/Kconfig
Reviewed-by: Simon Glass sjg@chromium.org
Change log?

On Tue, Jan 31, 2017 at 12:17:04PM +0100, Emmanuel Vadot wrote:
Add kconfig file to enable API support
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Now that we have a Kconfig for the API, convert the two boards that are using this to Kconfig and remove CONFIG_API from the whitelist.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com --- configs/PMC440_defconfig | 1 + configs/lsxhl_defconfig | 1 + include/configs/PMC440.h | 2 -- include/configs/lsxl.h | 5 ----- scripts/config_whitelist.txt | 1 - 5 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/configs/PMC440_defconfig b/configs/PMC440_defconfig index 0bcc5866af..7380ba7b21 100644 --- a/configs/PMC440_defconfig +++ b/configs/PMC440_defconfig @@ -24,3 +24,4 @@ CONFIG_SYS_NS16550=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_OF_LIBFDT=y +CONFIG_API=y diff --git a/configs/lsxhl_defconfig b/configs/lsxhl_defconfig index 75bd46da2f..4d974f1e16 100644 --- a/configs/lsxhl_defconfig +++ b/configs/lsxhl_defconfig @@ -23,3 +23,4 @@ CONFIG_SYS_NS16550=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_OF_LIBFDT=y +CONFIG_API=y diff --git a/include/configs/PMC440.h b/include/configs/PMC440.h index 5ea82f8e4d..59ba79e43b 100644 --- a/include/configs/PMC440.h +++ b/include/configs/PMC440.h @@ -385,6 +385,4 @@ #define CONFIG_KGDB_BAUDRATE 230400 /* speed to run kgdb serial port */ #endif
-#define CONFIG_API 1 - #endif /* __CONFIG_H */ diff --git a/include/configs/lsxl.h b/include/configs/lsxl.h index 7ec82cd4bb..ad1adcec8c 100644 --- a/include/configs/lsxl.h +++ b/include/configs/lsxl.h @@ -38,11 +38,6 @@ #define CONFIG_SYS_NO_FLASH
/* - * Enable u-boot API for standalone programs. - */ -#define CONFIG_API - -/* * Commands configuration */ #define CONFIG_CMD_ENV diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index 37ce51a77f..0019ac72aa 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -102,7 +102,6 @@ CONFIG_APBH_DMA_BURST8 CONFIG_APER_0_BASE CONFIG_APER_1_BASE CONFIG_APER_SIZE -CONFIG_API CONFIG_APUS_FAST_EXCEPT CONFIG_AP_SH4A_4A CONFIG_ARCH_ADPAG101P

On Tue, Jan 31, 2017 at 12:17:05PM +0100, Emmanuel Vadot wrote:
Now that we have a Kconfig for the API, convert the two boards that are using this to Kconfig and remove CONFIG_API from the whitelist.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Reviewed-by: Tom Rini trini@konsulko.com

On 31 January 2017 at 03:17, Emmanuel Vadot manu@bidouilliste.com wrote:
Now that we have a Kconfig for the API, convert the two boards that are using this to Kconfig and remove CONFIG_API from the whitelist.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
configs/PMC440_defconfig | 1 + configs/lsxhl_defconfig | 1 + include/configs/PMC440.h | 2 -- include/configs/lsxl.h | 5 ----- scripts/config_whitelist.txt | 1 - 5 files changed, 2 insertions(+), 8 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, Jan 31, 2017 at 12:17:05PM +0100, Emmanuel Vadot wrote:
Now that we have a Kconfig for the API, convert the two boards that are using this to Kconfig and remove CONFIG_API from the whitelist.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com --- api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 100644 --- a/api/api.c +++ b/api/api.c @@ -290,6 +290,11 @@ static int API_dev_close(va_list ap) if (!err) di->state = DEV_STA_CLOSED;
+ if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); + return err; }
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..b66ae67fcb 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,10 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { + if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); return entry (argc, argv); }
diff --git a/cmd/elf.c b/cmd/elf.c index e4c6535111..e98a798203 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,11 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+ if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); + /* * pass address parameter as argv[0] (aka command name), * and all remaining args

On 31 January 2017 at 03:17, Emmanuel Vadot manu@bidouilliste.com wrote:
From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, Jan 31, 2017 at 12:17:06PM +0100, Emmanuel Vadot wrote:
From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Simon Glass sjg@chromium.org
api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 100644 --- a/api/api.c +++ b/api/api.c @@ -290,6 +290,11 @@ static int API_dev_close(va_list ap) if (!err) di->state = DEV_STA_CLOSED;
- if (dcache_status())
flush_dcache_all();
- if (icache_status())
invalidate_icache_all();
So this runs into a problem. Building for sandbox, or many many other platforms gives us: undefined reference to `dcache_status' undefined reference to `flush_dcache_all' undefined reference to `icache_status' undefined reference to `invalidate_icache_all'
At the high level, we have a few problems. We don't have a global "has icache" and "has dcache" support CONFIG symbol. We also have a few instances of weak functions that end up being no-ops in these cases, but it's not quite correct to use them in this case, possibly. For example, PowerPC does have dcache support and functions but no flush_dcache_all (and only sometimes a flush_dcache() that looks like it would be _all()), and same for icache.

On 02/08/2017 04:00 PM, Tom Rini wrote:
On Tue, Jan 31, 2017 at 12:17:06PM +0100, Emmanuel Vadot wrote:
From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Simon Glass sjg@chromium.org
api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 100644 --- a/api/api.c +++ b/api/api.c @@ -290,6 +290,11 @@ static int API_dev_close(va_list ap) if (!err) di->state = DEV_STA_CLOSED;
- if (dcache_status())
flush_dcache_all();
- if (icache_status())
invalidate_icache_all();
So this runs into a problem. Building for sandbox, or many many other platforms gives us: undefined reference to `dcache_status' undefined reference to `flush_dcache_all' undefined reference to `icache_status' undefined reference to `invalidate_icache_all'
At the high level, we have a few problems. We don't have a global "has icache" and "has dcache" support CONFIG symbol. We also have a few instances of weak functions that end up being no-ops in these cases, but it's not quite correct to use them in this case, possibly. For example, PowerPC does have dcache support and functions but no flush_dcache_all (and only sometimes a flush_dcache() that looks like it would be _all()), and same for icache.
Well, if we want to keep the API consistent (which I think we do) we should probably fix that :). It's quite a good chunk of unpleasant work though...
Alex

On Wed, 8 Feb 2017 10:00:54 -0500 Tom Rini trini@konsulko.com wrote:
On Tue, Jan 31, 2017 at 12:17:06PM +0100, Emmanuel Vadot wrote:
From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Simon Glass sjg@chromium.org
api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 100644 --- a/api/api.c +++ b/api/api.c @@ -290,6 +290,11 @@ static int API_dev_close(va_list ap) if (!err) di->state = DEV_STA_CLOSED;
- if (dcache_status())
flush_dcache_all();
- if (icache_status())
invalidate_icache_all();
So this runs into a problem. Building for sandbox, or many many other platforms gives us: undefined reference to `dcache_status' undefined reference to `flush_dcache_all' undefined reference to `icache_status' undefined reference to `invalidate_icache_all'
At the high level, we have a few problems. We don't have a global "has icache" and "has dcache" support CONFIG symbol. We also have a few instances of weak functions that end up being no-ops in these cases, but it's not quite correct to use them in this case, possibly. For example, PowerPC does have dcache support and functions but no flush_dcache_all (and only sometimes a flush_dcache() that looks like it would be _all()), and same for icache.
-- Tom
Hi Tom,
Will depending on CONFIG_CMD_CACHE will be acceptable ? This is the easiest fix that I can think of.

On Fri, Feb 10, 2017 at 01:07:40PM +0100, Emmanuel Vadot wrote:
On Wed, 8 Feb 2017 10:00:54 -0500 Tom Rini trini@konsulko.com wrote:
On Tue, Jan 31, 2017 at 12:17:06PM +0100, Emmanuel Vadot wrote:
From: Warner Losh imp@freebsd.org
Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.
Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Reviewed-by: Simon Glass sjg@chromium.org
api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ 3 files changed, 14 insertions(+)
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 100644 --- a/api/api.c +++ b/api/api.c @@ -290,6 +290,11 @@ static int API_dev_close(va_list ap) if (!err) di->state = DEV_STA_CLOSED;
- if (dcache_status())
flush_dcache_all();
- if (icache_status())
invalidate_icache_all();
So this runs into a problem. Building for sandbox, or many many other platforms gives us: undefined reference to `dcache_status' undefined reference to `flush_dcache_all' undefined reference to `icache_status' undefined reference to `invalidate_icache_all'
At the high level, we have a few problems. We don't have a global "has icache" and "has dcache" support CONFIG symbol. We also have a few instances of weak functions that end up being no-ops in these cases, but it's not quite correct to use them in this case, possibly. For example, PowerPC does have dcache support and functions but no flush_dcache_all (and only sometimes a flush_dcache() that looks like it would be _all()), and same for icache.
Hi Tom,
Will depending on CONFIG_CMD_CACHE will be acceptable ? This is the easiest fix that I can think of.
That will continue to bring in the PowerPC side of the problem. I'll see about doing a little research to confirm what I said about the cache functions on PowerPC and we can move from there.

Add commands that scans for the FreeBSD loader and run it if found. FreeBSD has two loader: ubldr which is an ELF binary and ubldr.bin which is a PIE binary.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com --- include/config_distro_bootcmd.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index 0e01e8240d..2d8e99d24e 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -149,6 +149,36 @@ #define SCAN_DEV_FOR_EFI #endif
+#ifdef CONFIG_DISTRO_FREEBSD +#define BOOTENV_SHARED_FREEBSD \ + "boot_freebsd_binary=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} ubldr.bin; " \ + "go ${kernel_addr_r}\0" \ + \ + "boot_freebsd_elf=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} ubldr; " \ + "bootelf ${kernel_addr_r}\0" \ + \ + "scan_dev_for_freebsd=" \ + "if test -e ${devtype} ${devnum}:${distro_bootpart} " \ + "ubldr.bin; then " \ + "echo Found FreeBSD U-Boot Loader (bin);" \ + "run boot_freebsd_binary; " \ + "echo FREEBSD FAILED: continuing...; " \ + "elif test -e ${devtype} ${devnum}:${distro_bootpart} " \ + "ubldr; then " \ + "echo Found FreeBSD U-Boot Loader (elf);" \ + "run boot_freebsd_elf; " \ + "echo FREEBSD FAILED: continuing...; " \ + "fi;\0" +#define SCAN_DEV_FOR_FREEBSD "run scan_dev_for_freebsd;" +#else +#define BOOTENV_SHARED_FREEBSD +#define SCAN_DEV_FOR_FREEBSD +#endif + #ifdef CONFIG_CMD_SATA #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata) #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV @@ -322,6 +352,7 @@ BOOTENV_SHARED_IDE \ BOOTENV_SHARED_UBIFS \ BOOTENV_SHARED_EFI \ + BOOTENV_SHARED_FREEBSD \ "boot_prefixes=/ /boot/\0" \ "boot_scripts=boot.scr.uimg boot.scr\0" \ "boot_script_dhcp=boot.scr.uimg\0" \ @@ -365,6 +396,7 @@ "run scan_dev_for_scripts; " \ "done;" \ SCAN_DEV_FOR_EFI \ + SCAN_DEV_FOR_FREEBSD \ "\0" \ \ "scan_dev_for_boot_part=" \

On Tue, Jan 31, 2017 at 12:17:07PM +0100, Emmanuel Vadot wrote:
Add commands that scans for the FreeBSD loader and run it if found. FreeBSD has two loader: ubldr which is an ELF binary and ubldr.bin which is a PIE binary.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Reviewed-by: Tom Rini trini@konsulko.com

On 31 January 2017 at 03:17, Emmanuel Vadot manu@bidouilliste.com wrote:
Add commands that scans for the FreeBSD loader and run it if found. FreeBSD has two loader: ubldr which is an ELF binary and ubldr.bin which is a PIE binary.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
include/config_distro_bootcmd.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Add a FreeBSD option that enables the API and the data cache command as both are needed to boot the FreeBSD loader.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com --- common/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..a24cfa996a 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,15 @@ config BOARD_EARLY_INIT_F
endmenu
+config DISTRO_FREEBSD + bool "Enable FreeBSD boot" + select API + select CMD_CACHE + default n + help + This options adds boot configuration that can run the FreeBSD + loader. When enabled the distro_bootcmd will be expanded to + include scan_dev_for_freebsd which search for the FreeBSD loader + and if found run it. + source "common/spl/Kconfig"

On 31/01/2017 12:17, Emmanuel Vadot wrote:
This series of patches add the needed bits for booting the FreeBSD loader and kernel. FreeBSD loader and kernel needs the U-Boot API and dcache/icache flushed for it to run so add this operation in go/bootelf command and when closing the API. Also add some some boot command that locate and run the FreeBSD loader if found.
LGTM :)
Reviewed-by: Alexander Graf agraf@suse.de
Alex
participants (4)
-
Alexander Graf
-
Emmanuel Vadot
-
Simon Glass
-
Tom Rini