[U-Boot] [PATCH v3 0/4] 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 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 (3): kconfig: Add API kconfig file kconfig: Add a FREEBSD option distro_bootcmd: Add command to run FreeBSD
Warner Losh (1): api: FreeBSD: flush cache before starting
Kconfig | 2 ++ api/Kconfig | 9 +++++++++ api/api.c | 5 +++++ cmd/boot.c | 4 ++++ cmd/elf.c | 5 +++++ common/Kconfig | 9 +++++++++ include/config_distro_bootcmd.h | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+) 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 cb19ce6f87..2073d933d9 100644 --- a/Kconfig +++ b/Kconfig @@ -307,6 +307,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

Am 26.01.2017 um 17:46 schrieb Emmanuel Vadot:
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
No patch in this series updates the two boards Tom pointed out.
Regards, Andreas

On Thu, 26 Jan 2017 18:17:47 +0100 Andreas Färber afaerber@suse.de wrote:
Am 26.01.2017 um 17:46 schrieb Emmanuel Vadot:
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
No patch in this series updates the two boards Tom pointed out.
Regards, Andreas
Once CONFIG_API is available I'll update the two boards. I don't think it make sense to convert them in the same patch series for FreeBSD.
Cheers,

Am 26.01.2017 um 18:45 schrieb Emmanuel Vadot:
On Thu, 26 Jan 2017 18:17:47 +0100 Andreas Färber afaerber@suse.de wrote:
Am 26.01.2017 um 17:46 schrieb Emmanuel Vadot:
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
No patch in this series updates the two boards Tom pointed out.
Once CONFIG_API is available I'll update the two boards.
Unless I'm misreading something, it is available since this patch.
I don't think it make sense to convert them in the same patch series for FreeBSD.
Personally I would expect this to be done in this patch that converts the pre-existing option. It's really small as is and so are the requested cleanups. (This patch/commit does not mention FreeBSD once, and, once merged, Git history will not tell what patchset it came from.)
Cheers, Andreas

On Thu, Jan 26, 2017 at 07:00:23PM +0100, Andreas Färber wrote:
Am 26.01.2017 um 18:45 schrieb Emmanuel Vadot:
On Thu, 26 Jan 2017 18:17:47 +0100 Andreas Färber afaerber@suse.de wrote:
Am 26.01.2017 um 17:46 schrieb Emmanuel Vadot:
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
No patch in this series updates the two boards Tom pointed out.
Once CONFIG_API is available I'll update the two boards.
Unless I'm misreading something, it is available since this patch.
I don't think it make sense to convert them in the same patch series for FreeBSD.
Personally I would expect this to be done in this patch that converts the pre-existing option. It's really small as is and so are the requested cleanups. (This patch/commit does not mention FreeBSD once, and, once merged, Git history will not tell what patchset it came from.)
Right. The expectation would be that since this patch introduces API into Kconfig, and it's a really easy conversion, we convert the two boards in question as well. If it doesn't apply cleanly when I'm applying it's easy enough that I'll just fix it. Thanks!

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 | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..2fe19d354b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,13 @@ config BOARD_EARLY_INIT_F
endmenu
+config FREEBSD + bool "Enable FreeBSD boot" + select API + select CMD_CACHE + default n + help + This options adds boot configuration that can run the FreeBSD + loader. + source "common/spl/Kconfig"

On 01/26/2017 05:46 PM, Emmanuel Vadot wrote:
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 | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..2fe19d354b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,13 @@ config BOARD_EARLY_INIT_F
endmenu
+config FREEBSD
- bool "Enable FreeBSD boot"
- select API
- select CMD_CACHE
- default n
- help
This options adds boot configuration that can run the FreeBSD
The help text should be more descriptive and actually tell users what the option really does. Since the only thing CONFIG_FREEBSD does now is to enable distro boot support for it, maybe even rename the the option into CONFIG_DISTRO_FREEBSD.
Alex

On Thu, 26 Jan 2017 18:08:49 +0100 Alexander Graf agraf@suse.de wrote:
On 01/26/2017 05:46 PM, Emmanuel Vadot wrote:
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 | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..2fe19d354b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,13 @@ config BOARD_EARLY_INIT_F
endmenu
+config FREEBSD
- bool "Enable FreeBSD boot"
- select API
- select CMD_CACHE
- default n
- help
This options adds boot configuration that can run the FreeBSD
The help text should be more descriptive and actually tell users what the option really does.
Ok will do that.
Since the only thing CONFIG_FREEBSD does now is to enable distro boot support for it, maybe even rename the the option into CONFIG_DISTRO_FREEBSD.
We might want to support uImage/FIT at one point (I'm currently looking at this) so CONFIG_FREEBSD will make more sense. But we can rename the option later if needed, I don't know which way is better.

On 01/26/2017 06:44 PM, Emmanuel Vadot wrote:
On Thu, 26 Jan 2017 18:08:49 +0100 Alexander Graf agraf@suse.de wrote:
On 01/26/2017 05:46 PM, Emmanuel Vadot wrote:
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 | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..2fe19d354b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,13 @@ config BOARD_EARLY_INIT_F
endmenu
+config FREEBSD
- bool "Enable FreeBSD boot"
- select API
- select CMD_CACHE
- default n
- help
This options adds boot configuration that can run the FreeBSD
The help text should be more descriptive and actually tell users what the option really does.
Ok will do that.
Since the only thing CONFIG_FREEBSD does now is to enable distro boot support for it, maybe even rename the the option into CONFIG_DISTRO_FREEBSD.
We might want to support uImage/FIT at one point (I'm currently looking at this) so CONFIG_FREEBSD will make more sense. But we can rename the option later if needed, I don't know which way is better.
What do you need to change for uImage / FIT support? Does that have to be conditionalized?
Alex

Am 26.01.2017 um 18:53 schrieb Alexander Graf:
On 01/26/2017 06:44 PM, Emmanuel Vadot wrote:
On Thu, 26 Jan 2017 18:08:49 +0100 Alexander Graf agraf@suse.de wrote:
On 01/26/2017 05:46 PM, Emmanuel Vadot wrote:
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 | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index 9067d1e277..2fe19d354b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -430,4 +430,13 @@ config BOARD_EARLY_INIT_F endmenu +config FREEBSD
- bool "Enable FreeBSD boot"
- select API
- select CMD_CACHE
- default n
- help
This options adds boot configuration that can run the FreeBSD
The help text should be more descriptive and actually tell users what the option really does.
Ok will do that.
Since the only thing CONFIG_FREEBSD does now is to enable distro boot support for it, maybe even rename the the option into CONFIG_DISTRO_FREEBSD.
We might want to support uImage/FIT at one point (I'm currently looking at this) so CONFIG_FREEBSD will make more sense. But we can rename the option later if needed, I don't know which way is better.
What do you need to change for uImage / FIT support? Does that have to be conditionalized?
Or going further, is there a strict reason the distro changes need to be conditionalized at all? As long as they're properly guarded with checks for file existence it would only cost little boot time on a Linux system.
If you think of systems where you place U-Boot onto the SD card along your OS code then for sure it's possible for FreeBSD to enable this CONFIG_FREEBSD option during its build; but if you think of devices where U-Boot is in flash then it seems weird to flash different U-Boot variants dependent on what operating system you plan to run.
Regards, Andreas

On 01/26/2017 05:46 PM, Emmanuel Vadot wrote:
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
Also, please make this patch 4/4 so that the set is well bisectable.
Alex

From: Warner Losh imp@freebsd.org
FreeBSD loader(8) just loaded code to some random location that may contain stale icache entries. FreeBSD Kernel needs the icache and dcache flushed. Before running either one of them, flush the icache and dcache.
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 Thu, Jan 26, 2017 at 05:46:11PM +0100, Emmanuel Vadot wrote:
From: Warner Losh imp@freebsd.org
FreeBSD loader(8) just loaded code to some random location that may contain stale icache entries. FreeBSD Kernel needs the icache and dcache flushed. Before running either one of them, flush the icache and dcache.
This could probably be expanded to note that in general it's just always a good idea to flush icache/dcache prior to running whatever we're about to run. This isn't so much a FreeBSD thing as a generic thing.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Reviewed-by: Tom Rini trini@konsulko.com

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 9ecaf38a33..0f5d38534a 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -153,6 +153,36 @@ #define SCAN_DEV_FOR_EFI #endif
+#ifdef CONFIG_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 @@ -326,6 +356,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" \ @@ -369,6 +400,7 @@ "run scan_dev_for_scripts; " \ "done;" \ SCAN_DEV_FOR_EFI \ + SCAN_DEV_FOR_FREEBSD \ "\0" \ \ "scan_dev_for_boot_part=" \
participants (4)
-
Alexander Graf
-
Andreas Färber
-
Emmanuel Vadot
-
Tom Rini