wok-current diff linld/stuff/src/LINLD.CPP @ rev 19515

linld: multi initrd support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 22 21:19:01 2016 +0100 (2016-11-22)
parents
children 7f92b23984dc
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linld/stuff/src/LINLD.CPP	Tue Nov 22 21:19:01 2016 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +// This file is distributed under GPL
     1.5 +//
     1.6 +// LINLD main() lives here
     1.7 +
     1.8 +#include "crtl.h"
     1.9 +#include "common.h"
    1.10 +
    1.11 +static struct image_himem image;
    1.12 +static const char msg_cmdline[] = "Error reading cl=@file";
    1.13 +static char* read_cmdline_or_die(const char* fn) {
    1.14 +    image.errmsg = msg_cmdline;
    1.15 +    open_image(fn, &image);
    1.16 +    u16 size=image.size;
    1.17 +    char *cmdline_buf;
    1.18 +    if(size>=PAGE_SIZE ||
    1.19 +       !(cmdline_buf=(char *)malloc(size)) ||
    1.20 +       read(image.fd, cmdline_buf, size) != size)
    1.21 +        die(msg_cmdline);
    1.22 +    // Strip any trailing cr/lf
    1.23 +    char *p=cmdline_buf+size;
    1.24 +    char c='\0';
    1.25 +    do {
    1.26 +        // Replace all other cr/lfs with spaces
    1.27 +        if(*--p>=' ') c=' ';
    1.28 +	else *p = c;
    1.29 +    } while (p>cmdline_buf);
    1.30 +    return cmdline_buf;
    1.31 +}
    1.32 +
    1.33 +const char* kernel_name = "bzImage";
    1.34 +const char* initrd_name;
    1.35 +const char* cmdline = "auto";
    1.36 +u16 root_dev;
    1.37 +u16 vid_mode;           // -3 = ask
    1.38 +                        // -2 = Extended VGA
    1.39 +                        // -1 = Normal VGA
    1.40 +                        //  n = as "n" was pressed
    1.41 +
    1.42 +inline void syntax() {
    1.43 +    die("Syntax:" NL
    1.44 +        "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
    1.45 +        "vga mode: ask,extended,normal or dec/oct/hex number" NL
    1.46 +        "Defaults:" NL
    1.47 +        "\timage=bzImage" NL
    1.48 +        "\tinitrd,vga,root=(void)" NL
    1.49 +        "\tmem=256m" NL
    1.50 +        "\tcl=auto" NL
    1.51 +        "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
    1.52 +        "Use cl=@filename to take cmdline from file"
    1.53 +#if 1
    1.54 +        NL NL "Examples:" NL
    1.55 +        "\tlinld initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
    1.56 +	NL NL "\tlinld image=memtest"
    1.57 +#endif
    1.58 +    );
    1.59 +}
    1.60 +
    1.61 +int main(int argc, char *argv[]) {
    1.62 +    // Believe it or not - this enables A20
    1.63 +    // on my box! Must be DOS in HMA...   -vda
    1.64 +    puts("LINLD v" VERSION_STR "+");
    1.65 +
    1.66 +    // Parse command line
    1.67 +
    1.68 +    if(argc<2) {
    1.69 +dosyntax:
    1.70 +        syntax();
    1.71 +    }
    1.72 +    {for(int i=1;i<argc;i++) {
    1.73 +	char *s=argv[i];
    1.74 +        if(strhead(s,"image=") == 0) {
    1.75 +            kernel_name=s+6;
    1.76 +        }
    1.77 +        else if(strhead(s,"initrd=") == 0) {
    1.78 +            initrd_name = s+7;
    1.79 +        }
    1.80 +        else if(strhead(s,"cl=") == 0) {
    1.81 +            cmdline=s+3;
    1.82 +            if (cmdline[0] == '@') {
    1.83 +                cmdline=read_cmdline_or_die(cmdline+1);
    1.84 +                puts("Kernel command line:");
    1.85 +                puts(cmdline);
    1.86 +            }
    1.87 +        }
    1.88 +        else if(strhead(s,"vga=") == 0) {
    1.89 +	    s+=4;
    1.90 +	    const char c = *s|0x20;
    1.91 +            if (c == 'a') vid_mode = -3;
    1.92 +            else if (c == 'e') vid_mode = -2;
    1.93 +            else if (c == 'n') vid_mode = -1;
    1.94 +            else vid_mode = strtol(s);
    1.95 +        }
    1.96 +        else if(strhead(s,"root=") == 0) {
    1.97 +            root_dev = strtol(s+5);
    1.98 +        }
    1.99 +        else if(strhead(s,"mem=") == 0) {
   1.100 +            topmem = strtol(s+4);
   1.101 +        }
   1.102 +        else if(strhead(s,"-f") == 0) {
   1.103 +            extern int skip_xmmalloc;
   1.104 +            skip_xmmalloc++;
   1.105 +        }
   1.106 +        else
   1.107 +            goto dosyntax;
   1.108 +    }}
   1.109 +
   1.110 +    puts(load_kernel());
   1.111 +    load_initrd();
   1.112 +    boot_kernel();
   1.113 +
   1.114 +    // Let compiler be happy
   1.115 +    return _AX;
   1.116 +}