]> git.lizzy.rs Git - plan9front.git/commitdiff
kernel: simplify /boot/boot: 28K down to less than 4K.
authorcinap_lenrek <cinap_lenrek@felloff.net>
Tue, 27 Jul 2021 18:21:08 +0000 (18:21 +0000)
committercinap_lenrek <cinap_lenrek@felloff.net>
Tue, 27 Jul 2021 18:21:08 +0000 (18:21 +0000)
- avoid print() format routines (saves alot of code)
- avoid useless opens of /dev/cons (already done by initcode)
- avoid useless binds of /env and /dev (already done by initcode)
- do bind of /shr in bootrc, it is not needed by us
- we'r pid 1 so kernel will print the exit message for us

sys/src/9/boot/aux.c [deleted file]
sys/src/9/boot/boot.c
sys/src/9/boot/boot.h [deleted file]
sys/src/9/boot/bootmkfile
sys/src/9/boot/bootrc
sys/src/9/boot/printstub.c [deleted file]

diff --git a/sys/src/9/boot/aux.c b/sys/src/9/boot/aux.c
deleted file mode 100644 (file)
index 2c7c64a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <../boot/boot.h>
-
-void
-fatal(char *s)
-{
-       char buf[ERRMAX];
-
-       buf[0] = '\0';
-       errstr(buf, sizeof buf);
-       fprint(2, "boot: %s: %s\n", s, buf);
-       exits(0);
-}
-
-int
-readfile(char *name, char *buf, int len)
-{
-       int f, n;
-
-       buf[0] = 0;
-       f = open(name, OREAD);
-       if(f < 0)
-               return -1;
-       n = read(f, buf, len-1);
-       if(n >= 0)
-               buf[n] = 0;
-       close(f);
-       return 0;
-}
-
-void
-run(char *file, ...)
-{
-       char buf[64];
-       Waitmsg *w;
-       int pid;
-
-       switch(pid = fork()){
-       case -1:
-               fatal("fork");
-       case 0:
-               exec(file, &file);
-               snprint(buf, sizeof buf, "can't exec %s", file);
-               fatal(buf);
-       default:
-               while((w = wait()) != nil)
-                       if(w->pid == pid)
-                               break;
-               if(w == nil){
-                       snprint(buf, sizeof buf, "wait returned nil running %s", file);
-                       free(w);
-                       fatal(buf);
-               }
-               free(w);
-       }
-}
-
-int
-writefile(char *name, char *buf, int len)
-{
-       int f, n;
-
-       f = open(name, OWRITE);
-       if(f < 0)
-               return -1;
-       n = write(f, buf, len);
-       close(f);
-       return (n != len) ? -1 : 0;
-}
-
-void
-setenv(char *name, char *val, int ec)
-{
-       int f;
-       char ename[64];
-
-       snprint(ename, sizeof ename, "#e%s/%s", ec ? "c" : "", name);
-       f = create(ename, 1, 0666);
-       if(f < 0){
-               fprint(2, "create %s: %r\n", ename);
-               return;
-       }
-       write(f, val, strlen(val));
-       close(f);
-}
index 621c70da92a089cc3f63d197781212c03aca7a73..a8e08f91a3d1c90bf6388e9b7b5b7a496d2336c5 100644 (file)
@@ -1,48 +1,34 @@
 #include <u.h>
 #include <libc.h>
-#include <auth.h>
-#include <fcall.h>
-#include "../boot/boot.h"
+
+char bin[] = "/bin";
+char root[] = "/root";
 
 void
-main(int argc, char *argv[])
+main(int, char *argv[])
 {
-       char cputype[64];
        char buf[32];
 
-       fmtinstall('r', errfmt);
-
-       bind("#c", "/dev", MREPL);
-       open("/dev/cons", OREAD);
-       open("/dev/cons", OWRITE);
-       open("/dev/cons", OWRITE);
-       /*
-        * init will reinitialize its namespace.
-        * #ec gets us plan9.ini settings (*var variables).
-        */
-       bind("#ec", "/env", MREPL);
-       bind("#e", "/env", MBEFORE|MCREATE);
-       bind("#s", "/srv", MREPL|MCREATE);
-       bind("#σ", "/shr", MREPL);
-
-       if(Debug){
-               int i;
+       /* setup the boot namespace */
+       bind("/boot", bin, MAFTER);
 
-               print("argc=%d\n", argc);
-               for(i = 0; i < argc; i++)
-                       print("%p %s ", argv[i], argv[i]);
-               print("\n");
+       if(fork() == 0){
+               execl("/bin/paqfs", "-qa", "-c", "8", "-m", root, "/boot/bootfs.paq", nil);
+               goto Err;
        }
-       USED(argc);
+       if(await(buf, sizeof(buf)) < 0)
+               goto Err;
 
-       readfile("#e/cputype", cputype, sizeof(cputype));
+       bind(root, "/", MAFTER);
+
+       buf[0] = '/';
+       buf[1+read(open("/env/cputype", OREAD|OCEXEC), buf+1, sizeof buf - 5)] = '\0';
+       strcat(buf, bin);
+       bind(buf, bin, MAFTER);
+       bind("/rc/bin", bin, MAFTER);
 
-       /* setup the boot namespace */
-       bind("/boot", "/bin", MAFTER);
-       run("/bin/paqfs", "-qa", "-c", "8", "-m" "/root", "/boot/bootfs.paq", nil);
-       bind("/root", "/", MAFTER);
-       snprint(buf, sizeof(buf), "/%s/bin", cputype);
-       bind(buf, "/bin", MAFTER);
-       bind("/rc/bin", "/bin", MAFTER);
        exec("/bin/bootrc", argv);
+Err:
+       errstr(buf, sizeof buf);
+       _exits(buf);
 }
diff --git a/sys/src/9/boot/boot.h b/sys/src/9/boot/boot.h
deleted file mode 100644 (file)
index c726228..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-enum {
-       Debug = 0,
-};
-
-extern void    fatal(char*);
-extern int     readfile(char*, char*, int);
-extern void    run(char*, ...);
-extern void    setenv(char*, char*, int);
-extern int     writefile(char*, char*, int);
index ceb468a54c5db175aa8411f6dc567c686cc60438..d34e54271bba81be1c1b6c310b9753d8b2029769 100644 (file)
@@ -1,24 +1,15 @@
-BOOTDIR=../boot
+boot.$O:       ../boot/boot.c
+       $CC -I../boot $CFLAGS ../boot/boot.c
 
-BOOTFILES=\
-       aux.$O\
-       boot.$O\
-       printstub.$O\
-
-$BOOTFILES:    $BOOTDIR/boot.h
-
-%.$O:  $BOOTDIR/%.c
-       $CC -I$BOOTDIR $CFLAGS $BOOTDIR/$stem.c
-
-boot:  $BOOTFILES
-       $LD -o $target $BOOTFILES
+boot:  boot.$O
+       $LD -o $target $prereq
 
 # look for proto file in order:
 #      1) $CONF.bootfs.proto           (config specific)
 #      2) bootfs.proto                 (kernel specific)
-#      3) $BOOTDIR/bootfs.proto        (default generic)
+#      3) ../boot/bootfs.proto         (default generic)
 #
-BOOTFSPROTO=`{for(i in $CONF.bootfs.proto bootfs.proto $BOOTDIR/bootfs.proto) test -r $i && echo $i && exit}
+BOOTFSPROTO=`{for(i in $CONF.bootfs.proto bootfs.proto ../boot/bootfs.proto) test -r $i && echo $i && exit}
 
 bootfs.paq:    $BOOTFSPROTO `{disk/mkfs -aos / $BOOTFSPROTO >[2]/dev/null}
        mkdir -p bootfs
index 7931855dd4e698931f4d450a8258b3857f3ff60b..c0823e6f4dcfcb5ce9ccdc3231ccb4802329aea7 100755 (executable)
@@ -8,6 +8,7 @@ mntgen -s mntexport /mnt/exportfs && chmod 666 /srv/mntexport
 bind /root /mnt/broot
 unmount /root
 
+bind -q '#σ' /shr
 bind -q '#d' /fd
 bind -q '#p' /proc
 for(i in ¶ P S f æ t b m)
diff --git a/sys/src/9/boot/printstub.c b/sys/src/9/boot/printstub.c
deleted file mode 100644 (file)
index 49dc0f8..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <u.h>
-#include <libc.h>
-
-static Lock fmtl;
-
-void
-_fmtlock(void)
-{
-       lock(&fmtl);
-}
-
-void
-_fmtunlock(void)
-{
-       unlock(&fmtl);
-}
-
-int
-_efgfmt(Fmt*)
-{
-       return -1;
-}