Index: sys/kern/kern_environment.c =================================================================== --- sys/kern/kern_environment.c (revision 198474) +++ sys/kern/kern_environment.c (working copy) @@ -60,6 +60,8 @@ static MALLOC_DEFINE(M_KENV, "kenv", "kernel envir /* pointer to the static environment */ char *kern_envp; +static int env_len; +static int env_pos; static char *kernenv_next(char *); /* dynamic environment variables */ @@ -208,6 +210,14 @@ done: return (error); } +void +init_static_kenv(char *buf, size_t len) +{ + kern_envp = buf; + env_len = len; + env_pos = 0; +} + /* * Setup the dynamic kernel environment. */ @@ -336,6 +346,26 @@ testenv(const char *name) return (0); } +static int +setenv_static(const char *name, const char *value) +{ + int len; + + if (env_pos >= env_len) + return (-1); + + /* Check space for x=y and two nuls */ + len = strlen(name) + strlen(value); + if (len + 3 < env_len - env_pos) { + len = sprintf(&kern_envp[env_pos], "%s=%s", name, value); + env_pos += len+1; + kern_envp[env_pos] = '\0'; + return (0); + } else + return (-1); + +} + /* * Set an environment variable by name. */ @@ -345,6 +375,9 @@ setenv(const char *name, const char *value) char *buf, *cp, *oldenv; int namelen, vallen, i; + if (dynamic_kenv == 0 && env_len > 0) + return (setenv_static(name, value)); + KENV_CHECK; namelen = strlen(name) + 1; Index: sys/mips/atheros/ar71xx_machdep.c =================================================================== --- sys/mips/atheros/ar71xx_machdep.c (revision 198474) +++ sys/mips/atheros/ar71xx_machdep.c (working copy) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -59,7 +60,43 @@ __FBSDID("$FreeBSD$"); extern int *edata; extern int *end; uint32_t ar711_base_mac[ETHER_ADDR_LEN]; +/* 4KB static data aread to keep a copy of the bootload env until + the dynamic kenv is setup */ +char boot1_env[4096]; +/* + * We get a string in from Redboot with the all the arguments together, + * "foo=bar bar=baz". Split them up and save in kenv. + */ +static void +parse_argv(char *str) +{ + char *n, *v; + + while ((v = strsep(&str, " ")) != NULL) { + if (*v == '\0') + continue; + if (*v == '-') { + while (*v != '\0') { + v++; + switch (*v) { + case 'a': boothowto |= RB_ASKNAME; break; + case 'd': boothowto |= RB_KDB; break; + case 'g': boothowto |= RB_GDB; break; + case 's': boothowto |= RB_SINGLE; break; + case 'v': boothowto |= RB_VERBOSE; break; + } + } + } else { + n = strsep(&v, "="); + if (v == NULL) + setenv(n, "1"); + else + setenv(n, v); + } + } +} + void platform_halt(void) { @@ -154,6 +191,7 @@ platform_start(__register_t a0 __unused, __registe platform_counter_freq = ar71xx_cpu_freq(); mips_timer_init_params(platform_counter_freq, 1); cninit(); + init_static_kenv(boot1_env, sizeof(boot1_env)); printf("platform frequency: %lld\n", platform_counter_freq); printf("arguments: \n"); @@ -164,8 +202,10 @@ platform_start(__register_t a0 __unused, __registe printf("Cmd line:"); if (MIPS_IS_VALID_PTR(argv)) { - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { printf(" %s", argv[i]); + parse_argv(argv[i]); + } } else printf ("argv is invalid"); @@ -173,8 +213,10 @@ platform_start(__register_t a0 __unused, __registe printf("Environment:\n"); if (MIPS_IS_VALID_PTR(envp)) { - for (i = 0; envp[i]; i+=2) + for (i = 0; envp[i]; i+=2) { printf(" %s = %s\n", envp[i], envp[i+1]); + setenv(envp[i], envp[i+1]); + } } else printf ("envp is invalid\n"); Index: sys/sys/systm.h =================================================================== --- sys/sys/systm.h (revision 198474) +++ sys/sys/systm.h (working copy) @@ -164,6 +164,7 @@ void critical_exit(void); void init_param1(void); void init_param2(long physpages); void init_param3(long kmempages); +void init_static_kenv(char *, size_t); void tablefull(const char *); int kvprintf(char const *, void (*)(int, void*), void *, int, __va_list) __printflike(1, 0);