From c472031cf2d05808b2d13cc1f4d747f452ecd99b Mon Sep 17 00:00:00 2001 From: mhorne Date: Fri, 20 Nov 2020 15:21:10 +0000 Subject: [PATCH] riscv: always initialize the static kernel environment Ensure we initialize the static environment when not booting via loader(8), and provide a static buffer if this is the case. This fixes two issues. First, performing the initialization ensures that kenv variables set in the kernel's config file are honored. Previously, any new or overridden values were ignored. Second, providing the static buffer allows variables to be set in the device tree's bootargs property of the chosen node. This can be set by u-boot or by QEMU's '-append' flag. Attempting to this prior to this change resulted in an early panic, since the static environment had no buffer backing it. Submitted by: syrinx (earlier version) Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D25034 --- sys/riscv/riscv/machdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index 550d440cddc..841bfeda891 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -130,6 +130,8 @@ cpuset_t all_harts; extern int *end; +static char static_kenv[PAGE_SIZE]; + static void cpu_startup(void *dummy) { @@ -836,6 +838,8 @@ parse_metadata(void) kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); if (kern_envp != NULL) init_static_kenv(kern_envp, 0); + else + init_static_kenv(static_kenv, sizeof(static_kenv)); #ifdef DDB ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t); ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t); -- 2.45.2