ref: 65bd53b9b89b0a84d0f16db4adc3f53fa6ab3a3a
parent: cd64b7129c81102c811b3df9a32ceb4004420f54
author: cinap_lenrek <[email protected]>
date: Sun Jul 10 12:40:36 EDT 2022
imx8: load a plan9.ini at CONFADDR 0x40010000
--- 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 @@
else
ksetenv("service", "terminal", 0);
ksetenv("console", "0", 0);
+ setconfenv();
poperror();
}
kproc("alarm", alarmkproc, 0);
@@ -161,6 +270,7 @@
return;
}
quotefmtinstall();
+ bootargsinit();
meminit();
confinit();
xinit();
@@ -198,23 +308,6 @@
if(m->machno == 0)
u.r0 = 0x84000009; /* SYSTEM RESET */
smccall(&u);
-}
-
-int
-isaconfig(char *, int, ISAConf *)
-{
- return 0;
-}
-
-char*
-getconf(char *)
-{
- return nil;
-}
-
-void
-writeconf(void)
-{
}
static void
--- 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 */
--- 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