From 65bd53b9b89b0a84d0f16db4adc3f53fa6ab3a3a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 16:40:36 +0000 Subject: [PATCH] imx8: load a plan9.ini at CONFADDR 0x40010000 --- sys/src/9/imx8/main.c | 127 ++++++++++++++++++++++++++++++----- sys/src/9/imx8/mem.h | 4 ++ sys/src/boot/reform/boot.txt | 6 +- 3 files changed, 118 insertions(+), 19 deletions(-) diff --git a/sys/src/9/imx8/main.c b/sys/src/9/imx8/main.c index d83dca421..6196e3aa8 100644 --- a/sys/src/9/imx8/main.c +++ b/sys/src/9/imx8/main.c @@ -14,6 +14,114 @@ Conf conf; +#define MAXCONF 64 +static char *confname[MAXCONF]; +static char *confval[MAXCONF]; +static int nconf; + +void +bootargsinit(void) +{ + int i, j, n; + char *cp, *line[MAXCONF], *p, *q; + + /* + * parse configuration args from dos file plan9.ini + */ + cp = BOOTARGS; /* where b.com leaves its config */ + cp[BOOTARGSLEN-1] = 0; + + /* + * Strip out '\r', change '\t' -> ' '. + */ + p = cp; + for(q = cp; *q; q++){ + if(*q == -1) + break; + if(*q == '\r') + continue; + if(*q == '\t') + *q = ' '; + *p++ = *q; + } + *p = 0; + + n = getfields(cp, line, MAXCONF, 1, "\n"); + for(i = 0; i < n; i++){ + if(*line[i] == '#') + continue; + cp = strchr(line[i], '='); + if(cp == nil) + continue; + *cp++ = '\0'; + for(j = 0; j < nconf; j++){ + if(cistrcmp(confname[j], line[i]) == 0) + break; + } + confname[j] = line[i]; + confval[j] = cp; + if(j == nconf) + nconf++; + } +} + +char* +getconf(char *name) +{ + int i; + + for(i = 0; i < nconf; i++) + if(cistrcmp(confname[i], name) == 0) + return confval[i]; + return nil; +} + +void +setconfenv(void) +{ + int i; + + for(i = 0; i < nconf; i++){ + if(confname[i][0] != '*') + ksetenv(confname[i], confval[i], 0); + ksetenv(confname[i], confval[i], 1); + } +} + +void +writeconf(void) +{ + char *p, *q; + int n; + + p = getconfenv(); + if(waserror()) { + free(p); + nexterror(); + } + + /* convert to name=value\n format */ + for(q=p; *q; q++) { + q += strlen(q); + *q = '='; + q += strlen(q); + *q = '\n'; + } + n = q - p + 1; + if(n >= BOOTARGSLEN) + error("kernel configuration too large"); + memmove(BOOTARGS, p, n); + memset(BOOTARGS+n, 0, BOOTARGSLEN-n); + poperror(); + free(p); +} + +int +isaconfig(char *, int, ISAConf *) +{ + return 0; +} + /* * starting place for first process */ @@ -31,6 +139,7 @@ init0(void) else ksetenv("service", "terminal", 0); ksetenv("console", "0", 0); + setconfenv(); poperror(); } kproc("alarm", alarmkproc, 0); @@ -161,6 +270,7 @@ main(void) return; } quotefmtinstall(); + bootargsinit(); meminit(); confinit(); xinit(); @@ -200,23 +310,6 @@ exit(int) smccall(&u); } -int -isaconfig(char *, int, ISAConf *) -{ - return 0; -} - -char* -getconf(char *) -{ - return nil; -} - -void -writeconf(void) -{ -} - static void rebootjump(void *entry, void *code, ulong size) { diff --git a/sys/src/9/imx8/mem.h b/sys/src/9/imx8/mem.h index 2831aa0f0..117722bc1 100644 --- a/sys/src/9/imx8/mem.h +++ b/sys/src/9/imx8/mem.h @@ -64,6 +64,10 @@ #define MACHADDR(n) (KTZERO-((n)+1)*MACHSIZE) #define CONFADDR (VDRAM + 0x10000) /* 0x40010000 */ + +#define BOOTARGS ((char*)CONFADDR) +#define BOOTARGSLEN 0x10000 + #define REBOOTADDR (VDRAM-KZERO + 0x20000) /* 0x40020000 */ #define UZERO 0ULL /* user segment */ diff --git a/sys/src/boot/reform/boot.txt b/sys/src/boot/reform/boot.txt index 738fd305d..1fdc0f533 100644 --- a/sys/src/boot/reform/boot.txt +++ b/sys/src/boot/reform/boot.txt @@ -1,2 +1,4 @@ -load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} ${prefix}9reform.u -bootm ${kernel_addr_r} +mw.b 0x40010000 0x0 0x10000 +load ${devtype} ${devnum}:${bootpart} 0x40010000 ${prefix}plan9.ini +load ${devtype} ${devnum}:${bootpart} 0x40100000 ${prefix}9reform.u +bootm 0x40100000