[U-Boot] [PATCH v2 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 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 loader/kernel
Kconfig | 2 ++ api/Kconfig | 9 +++++++++ api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- common/Kconfig | 9 +++++++++ include/config_distro_bootcmd.h | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 69 insertions(+), 1 deletion(-) 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 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API" + +config API + bool "Enable U-Boot API" + default n + help + This option enable the U-Boot API. + +endmenu

Am 17.01.2017 um 16:50 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
- bool "Enable U-Boot API"
- default n
- help
This option enable the U-Boot API.
"enables"
Should the help say, e.g., "userspace API" for clarity?
+endmenu
Otherwise looks okay, obviously.
Regards, Andreas

Hi Andreas,
On Tue, 17 Jan 2017 18:16:58 +0100 Andreas Färber afaerber@suse.de wrote:
Am 17.01.2017 um 16:50 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
- bool "Enable U-Boot API"
- default n
- help
This option enable the U-Boot API.
"enables"
I'll change that, thanks for reviewing.
Should the help say, e.g., "userspace API" for clarity?
I don't know, I'm for whatever is best.
+endmenu
Otherwise looks okay, obviously.
Regards, Andreas
-- SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)

On Tue, Jan 17, 2017 at 12:40 PM, Emmanuel Vadot manu@bidouilliste.com wrote:
Hi Andreas,
On Tue, 17 Jan 2017 18:16:58 +0100 Andreas Färber afaerber@suse.de wrote:
Am 17.01.2017 um 16:50 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
- bool "Enable U-Boot API"
- default n
- help
This option enable the U-Boot API.
"enables"
I'll change that, thanks for reviewing.
Should the help say, e.g., "userspace API" for clarity?
I don't know, I'm for whatever is best.
It isn't a userspace API, per se, since it isn't used after the kernel is loaded and booted. It's likely to lead to confusion if use use that term. The README file calls it "U-Boot machine/arch independent API for external apps" FWIW, so maybe some variation on that might make the help text better.
Warner Losh imp@freebsd.org
+endmenu
Otherwise looks okay, obviously.
Regards, Andreas
-- SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
-- Emmanuel Vadot manu@bidouilliste.com manu@freebsd.org

Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
+endmenu
2.11.0
Regards, Simon

On Fri, Jan 20, 2017 at 8:51 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
You can find complete documentation in the api directory. In brief, it allows the loaded binary to call back into the loader to do generic things like send network packets or read blocks from mass storage.
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
I'll leave that to Emmanuel.
Warner
+endmenu
2.11.0
Regards, Simon

On Sat, Jan 21, 2017 at 09:22:47PM -0700, Warner Losh wrote:
On Fri, Jan 20, 2017 at 8:51 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
You can find complete documentation in the api directory. In brief, it allows the loaded binary to call back into the loader to do generic things like send network packets or read blocks from mass storage.
Right. Can you re-word the "In brief.." slightly so it reads well under the 'help' section and point to api/README for more details please?
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
I'll leave that to Emmanuel.
There's two boards that enable API today but tools/moveconfig.py may be more overhead than just editing configs/PMC440_defconfig and configs/lsxhl_defconfig (and the respective include/configs/ files).

Hi Tom,
On Mon, 23 Jan 2017 09:51:59 -0500 Tom Rini trini@konsulko.com wrote:
On Sat, Jan 21, 2017 at 09:22:47PM -0700, Warner Losh wrote:
On Fri, Jan 20, 2017 at 8:51 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
You can find complete documentation in the api directory. In brief, it allows the loaded binary to call back into the loader to do generic things like send network packets or read blocks from mass storage.
Right. Can you re-word the "In brief.." slightly so it reads well under the 'help' section and point to api/README for more details please?
All right, I'll do that for v3.
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
I'll leave that to Emmanuel.
There's two boards that enable API today but tools/moveconfig.py may be more overhead than just editing configs/PMC440_defconfig and configs/lsxhl_defconfig (and the respective include/configs/ files).
-- Tom
Ah, I've missed those. Would it make more sense to submit a patch that handle adding CONFIG_API into Kconfig (and changing configs for those two board and remove from the whitelist) separate from the FreeBSD config sets of patches ?
Thanks,

On Mon, Jan 23, 2017 at 05:05:50PM +0100, Emmanuel Vadot wrote:
Hi Tom,
On Mon, 23 Jan 2017 09:51:59 -0500 Tom Rini trini@konsulko.com wrote:
On Sat, Jan 21, 2017 at 09:22:47PM -0700, Warner Losh wrote:
On Fri, Jan 20, 2017 at 8:51 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
You can find complete documentation in the api directory. In brief, it allows the loaded binary to call back into the loader to do generic things like send network packets or read blocks from mass storage.
Right. Can you re-word the "In brief.." slightly so it reads well under the 'help' section and point to api/README for more details please?
All right, I'll do that for v3.
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
I'll leave that to Emmanuel.
There's two boards that enable API today but tools/moveconfig.py may be more overhead than just editing configs/PMC440_defconfig and configs/lsxhl_defconfig (and the respective include/configs/ files).
Ah, I've missed those. Would it make more sense to submit a patch that handle adding CONFIG_API into Kconfig (and changing configs for those two board and remove from the whitelist) separate from the FreeBSD config sets of patches ?
It's up to you guys. I want to see this thread sorted out and changes required to support FreeBSD happily, out of the box, in. So API gets converted one way or another :)

On Fri, 20 Jan 2017 20:51:48 -0700 Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, 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
diff --git a/Kconfig b/Kconfig index 39a4d938d8..6a93d8820f 100644 --- a/Kconfig +++ b/Kconfig @@ -306,6 +306,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..88b4f6c4e5 --- /dev/null +++ b/api/Kconfig @@ -0,0 +1,9 @@ +menu "API"
+config API
bool "Enable U-Boot API"
default n
help
This option enable the U-Boot API.
Can you add a little detail about what the API is and what it is for?
Also, are you going to migrate all boards to use Kconfig for this option and drop it from the whitelist?
I don't understand your question about migration, currently no board are using it. As for the whitelist, if I understand correctly how it works it should be removed in the same patch.
+endmenu
2.11.0
Regards, Simon

Add a FreeBSD option that enable the API and enable the data cache command as it is 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 a04ee1084f..b719ccd888 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -389,4 +389,13 @@ config DISPLAY_BOARDINFO when U-Boot starts up. The board function checkboard() is called to do this.
+config FREEBSD + bool "Enable FreeBSD boot" + select API + select CMD_CACHE + default n + help + This option adds boot configuration that can run the FreeBSD + loader. + source "common/spl/Kconfig"

Hi,
On 17 January 2017 at 08:50, Emmanuel Vadot manu@bidouilliste.com wrote:
Add a FreeBSD option that enable the API and enable the data cache command as it is 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 a04ee1084f..b719ccd888 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -389,4 +389,13 @@ config DISPLAY_BOARDINFO when U-Boot starts up. The board function checkboard() is called to do this.
+config FREEBSD
bool "Enable FreeBSD boot"
select API
select CMD_CACHE
default n
help
This option adds boot configuration that can run the FreeBSD
loader.
What is the FreeBSD loader? Do you mean that U-Boot can boot FreeBSD?
source "common/spl/Kconfig"
2.11.0
Regards, Simon

Hello Simon,
On 21-01-17 04:51, Simon Glass wrote:
Hi,
On 17 January 2017 at 08:50, Emmanuel Vadot manu@bidouilliste.com wrote:
Add a FreeBSD option that enable the API and enable the data cache command as it is 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 a04ee1084f..b719ccd888 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -389,4 +389,13 @@ config DISPLAY_BOARDINFO when U-Boot starts up. The board function checkboard() is called to do this.
+config FREEBSD
bool "Enable FreeBSD boot"
select API
select CMD_CACHE
default n
help
This option adds boot configuration that can run the FreeBSD
loader.
What is the FreeBSD loader?
see https://www.freebsd.org/cgi/man.cgi?loader(8). Which is rather nice, FreeBSD uses the same loader independent of arch, so booting the previous kernel / kernel module stuff and rescue things are roughly the same on i386, amd64 and arm. The loader communicates with u-boot by its api.
Do you mean that U-Boot can boot FreeBSD?
Hence he meant what he wrote. Be able to run the FreeBSD _loader_. The FreeBSD loader will take care of booting FreeBSD.
Regards, Jeroen

On Fri, Jan 20, 2017 at 8:51 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, Emmanuel Vadot manu@bidouilliste.com wrote:
Add a FreeBSD option that enable the API and enable the data cache command as it is 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 a04ee1084f..b719ccd888 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -389,4 +389,13 @@ config DISPLAY_BOARDINFO when U-Boot starts up. The board function checkboard() is called to do this.
+config FREEBSD
bool "Enable FreeBSD boot"
select API
select CMD_CACHE
default n
help
This option adds boot configuration that can run the FreeBSD
loader.
What is the FreeBSD loader? Do you mean that U-Boot can boot FreeBSD?
No. The FreeBSD loader is loaded by u-boot and it loads the kernel, modules and sets up a number of environment variables.
Warner
source "common/spl/Kconfig"
2.11.0
Regards, Simon

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 | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD + flush_dcache_all(); + invalidate_icache_all(); +#endif + return err; }
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD + flush_dcache_all(); + invalidate_icache_all(); +#endif + return entry (argc, argv); }
diff --git a/cmd/elf.c b/cmd/elf.c index 5190cc6c0f..b2827fa042 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+#ifndef CONFIG_FREEBSD /* * QNX images require the data cache is disabled. * Data cache is already flushed, so just turn it off. @@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int dcache = dcache_status(); if (dcache) dcache_disable(); - +#else + flush_dcache_all(); + invalidate_icache_all(); +#endif /* * pass address parameter as argv[0] (aka command name), * and all remaining args */ ret = entry(argc, argv);
+#ifndef CONFIG_FREEBSD if (dcache) dcache_enable(); +#endif
return ret; }

On 17/01/2017 16:50, 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Is there any downside to doing the flush always? I would prefer to not conditionalize it on CONFIG_FREEBSD.
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return entry (argc, argv);
}
diff --git a/cmd/elf.c b/cmd/elf.c index 5190cc6c0f..b2827fa042 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+#ifndef CONFIG_FREEBSD /* * QNX images require the data cache is disabled. * Data cache is already flushed, so just turn it off. @@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int dcache = dcache_status(); if (dcache) dcache_disable();
Can FreeBSD boot with dcache disabled? Is there some way we can determine what payload we have from the elf header?
Alex

On Tue, 17 Jan 2017 21:13:51 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Is there any downside to doing the flush always? I would prefer to not conditionalize it on CONFIG_FREEBSD.
I don't think there is any downside.
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return entry (argc, argv);
}
diff --git a/cmd/elf.c b/cmd/elf.c index 5190cc6c0f..b2827fa042 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+#ifndef CONFIG_FREEBSD /* * QNX images require the data cache is disabled. * Data cache is already flushed, so just turn it off. @@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int dcache = dcache_status(); if (dcache) dcache_disable();
Can FreeBSD boot with dcache disabled? Is there some way we can determine what payload we have from the elf header?
Alex
FreeBSD can boot with dcache disabled (our loader and kernel can) I'm not sure I get your other question, sorry.

On 17/01/2017 21:45, Emmanuel Vadot wrote:
On Tue, 17 Jan 2017 21:13:51 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Is there any downside to doing the flush always? I would prefer to not conditionalize it on CONFIG_FREEBSD.
I don't think there is any downside.
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return entry (argc, argv);
}
diff --git a/cmd/elf.c b/cmd/elf.c index 5190cc6c0f..b2827fa042 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+#ifndef CONFIG_FREEBSD /* * QNX images require the data cache is disabled. * Data cache is already flushed, so just turn it off. @@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int dcache = dcache_status(); if (dcache) dcache_disable();
Can FreeBSD boot with dcache disabled? Is there some way we can determine what payload we have from the elf header?
Alex
FreeBSD can boot with dcache disabled (our loader and kernel can) I'm not sure I get your other question, sorry.
Your patch #ifdefs out the dcache_disable() if CONFIG_FREEBSD is set. So if you can boot just fine with dcache disabled, you can remove this hunk altogether FWIW.
All the other changes in this file are mere cache flushes - and they shouldn't hurt any u-boot api user and thus could be done unconditionally.
Alex

On Tue, 17 Jan 2017 21:58:31 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 21:45, Emmanuel Vadot wrote:
On Tue, 17 Jan 2017 21:13:51 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
Is there any downside to doing the flush always? I would prefer to not conditionalize it on CONFIG_FREEBSD.
I don't think there is any downside.
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
- flush_dcache_all();
- invalidate_icache_all();
+#endif
- return entry (argc, argv);
}
diff --git a/cmd/elf.c b/cmd/elf.c index 5190cc6c0f..b2827fa042 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret;
+#ifndef CONFIG_FREEBSD /* * QNX images require the data cache is disabled. * Data cache is already flushed, so just turn it off. @@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int dcache = dcache_status(); if (dcache) dcache_disable();
Can FreeBSD boot with dcache disabled? Is there some way we can determine what payload we have from the elf header?
Alex
FreeBSD can boot with dcache disabled (our loader and kernel can) I'm not sure I get your other question, sorry.
Your patch #ifdefs out the dcache_disable() if CONFIG_FREEBSD is set. So if you can boot just fine with dcache disabled, you can remove this hunk altogether FWIW.
Loading the kernel from our loader is much faster with dcache enabled (1 sec instead of 5/7 sec). I guess we can always flush the cache and only disable it for QNX, I'll check if there is a CONFIG_QNX or something like that.
All the other changes in this file are mere cache flushes - and they shouldn't hurt any u-boot api user and thus could be done unconditionally.
True, I can remove the #ifdefs on CONFIG_FREEBSD here.
Alex

Hi,
On 17 January 2017 at 08:50, Emmanuel Vadot manu@bidouilliste.com 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
flush_dcache_all();
invalidate_icache_all();
+#endif
It's not nice IMO to add OS-specific #ifdefs to generic code. Can you instead define a Kconfig option with a sensible name, and have FreeBSD define it?
return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
flush_dcache_all();
invalidate_icache_all();
+#endif
return entry (argc, argv);
}
Regards, Simon

Hi Simon,
On Fri, 20 Jan 2017 20:51:54 -0700 Simon Glass sjg@chromium.org wrote:
Hi,
On 17 January 2017 at 08:50, Emmanuel Vadot manu@bidouilliste.com 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.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com
api/api.c | 5 +++++ cmd/boot.c | 5 +++++ cmd/elf.c | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/api/api.c b/api/api.c index 8a1433af78..cc25deca09 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;
+#ifdef CONFIG_FREEBSD
flush_dcache_all();
invalidate_icache_all();
+#endif
It's not nice IMO to add OS-specific #ifdefs to generic code. Can you instead define a Kconfig option with a sensible name, and have FreeBSD define it?
In the same thread, Alexander Graf said that since this are just cache flush it doesn't even need to be FreeBSD/CONFIG specific so I'll do that on the v3.
return err;
}
diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..a1a91fbf0a 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,11 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { +#ifdef CONFIG_FREEBSD
flush_dcache_all();
invalidate_icache_all();
+#endif
return entry (argc, argv);
}
Regards, Simon

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=" \

On 17/01/2017 16:50, 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
If we can make the dcache disable part unconditional, I would just fold the CONFIG_FREEBSD part in here and only make the boot script hunk conditional on it.
Alex

On 17/01/2017 16:50, 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.
Is there any particular reason the EFI boot path doesn't work for you?
Configuring u-boot differently to be able to boot FreeBSD sounds a bit strange to me.
Alex

Hi Alexander,
On Tue, 17 Jan 2017 20:36:59 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Is there any particular reason the EFI boot path doesn't work for you?
Configuring u-boot differently to be able to boot FreeBSD sounds a bit strange to me.
Alex
EFI works fine for us, that's what we use for arm64 (pine64/rpi3 for example) because we want to only use EFI for arm64. For armv6/v7 we have legacy devices etc ... and even if EFI works (well honestly I have to fix our smbios code for it to work properly) we need to be able to boot without EFI support. With this series of patches is an EFI binary is found this is the one that would be loaded, so when the times comes we could make our releases with EFI bootloaders for ARM. In the meantimes we still need the U-Boot API for our loader.
Cheers,

On Tue, Jan 17, 2017 at 12:47 PM, Emmanuel Vadot manu@bidouilliste.com wrote:
Hi Alexander,
On Tue, 17 Jan 2017 20:36:59 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Is there any particular reason the EFI boot path doesn't work for you?
Configuring u-boot differently to be able to boot FreeBSD sounds a bit strange to me.
Alex
EFI works fine for us, that's what we use for arm64 (pine64/rpi3 for example) because we want to only use EFI for arm64. For armv6/v7 we have legacy devices etc ... and even if EFI works (well honestly I have to fix our smbios code for it to work properly) we need to be able to boot without EFI support. With this series of patches is an EFI binary is found this is the one that would be loaded, so when the times comes we could make our releases with EFI bootloaders for ARM. In the meantimes we still need the U-Boot API for our loader.
In addition, we have a long-term support branch (FreeBSD 11.x) that we need to support with the current setup since we use u-boot to load our tertiary loader which loads the kernel and related files (hence the need for the u-boot app API). It's something that's evolved over a number of years without proper upstreaming in the past. This series of patches lets us continue to use the tried and true paths, as well as setting the stage for a migration to EFI for the next major supported branch of FreeBSD (12.x, not due for a release for about a year or so). FreeBSD 11 support needs to continue past FreeBSD 12's release. Finally, as Emmanuel has said, there's still some rough edges to FreeBSD/arm's EFI support that need to be worked through in parallel before people will switch to the new way.
Warner Losh imp@freebsd.org

On 17/01/2017 20:57, Warner Losh wrote:
On Tue, Jan 17, 2017 at 12:47 PM, Emmanuel Vadot manu@bidouilliste.com wrote:
Hi Alexander,
On Tue, 17 Jan 2017 20:36:59 +0100 Alexander Graf agraf@suse.de wrote:
On 17/01/2017 16:50, 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.
Is there any particular reason the EFI boot path doesn't work for you?
Configuring u-boot differently to be able to boot FreeBSD sounds a bit strange to me.
Alex
EFI works fine for us, that's what we use for arm64 (pine64/rpi3 for example) because we want to only use EFI for arm64. For armv6/v7 we have legacy devices etc ... and even if EFI works (well honestly I have to fix our smbios code for it to work properly) we need to be able to boot without EFI support. With this series of patches is an EFI binary is found this is the one that would be loaded, so when the times comes we could make our releases with EFI bootloaders for ARM. In the meantimes we still need the U-Boot API for our loader.
In addition, we have a long-term support branch (FreeBSD 11.x) that we need to support with the current setup since we use u-boot to load our tertiary loader which loads the kernel and related files (hence the need for the u-boot app API). It's something that's evolved over a number of years without proper upstreaming in the past. This series of patches lets us continue to use the tried and true paths, as well as setting the stage for a migration to EFI for the next major supported branch of FreeBSD (12.x, not due for a release for about a year or so). FreeBSD 11 support needs to continue past FreeBSD 12's release. Finally, as Emmanuel has said, there's still some rough edges to FreeBSD/arm's EFI support that need to be worked through in parallel before people will switch to the new way.
Thanks a lot to both of you for the detailed description. That indeed makes a lot of sense altogether.
Alex
participants (7)
-
Alexander Graf
-
Andreas Färber
-
Emmanuel Vadot
-
Jeroen Hofstee
-
Simon Glass
-
Tom Rini
-
Warner Losh