wok diff linld/stuff/src/LINLD.CPP @ rev 19538
linld: add 'linld <kernel> <cmdline>' syntax
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Dec 02 12:37:59 2016 +0100 (2016-12-02) |
parents | bb42796dcd3b |
children | e428345df29a |
line diff
1.1 --- a/linld/stuff/src/LINLD.CPP Tue Nov 22 21:19:01 2016 +0100 1.2 +++ b/linld/stuff/src/LINLD.CPP Fri Dec 02 12:37:59 2016 +0100 1.3 @@ -5,28 +5,6 @@ 1.4 #include "crtl.h" 1.5 #include "common.h" 1.6 1.7 -static struct image_himem image; 1.8 -static const char msg_cmdline[] = "Error reading cl=@file"; 1.9 -static char* read_cmdline_or_die(const char* fn) { 1.10 - image.errmsg = msg_cmdline; 1.11 - open_image(fn, &image); 1.12 - u16 size=image.size; 1.13 - char *cmdline_buf; 1.14 - if(size>=PAGE_SIZE || 1.15 - !(cmdline_buf=(char *)malloc(size)) || 1.16 - read(image.fd, cmdline_buf, size) != size) 1.17 - die(msg_cmdline); 1.18 - // Strip any trailing cr/lf 1.19 - char *p=cmdline_buf+size; 1.20 - char c='\0'; 1.21 - do { 1.22 - // Replace all other cr/lfs with spaces 1.23 - if(*--p>=' ') c=' '; 1.24 - else *p = c; 1.25 - } while (p>cmdline_buf); 1.26 - return cmdline_buf; 1.27 -} 1.28 - 1.29 const char* kernel_name = "bzImage"; 1.30 const char* initrd_name; 1.31 const char* cmdline = "auto"; 1.32 @@ -40,13 +18,14 @@ 1.33 die("Syntax:" NL 1.34 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL 1.35 "vga mode: ask,extended,normal or dec/oct/hex number" NL 1.36 + "-f force" NL 1.37 "Defaults:" NL 1.38 "\timage=bzImage" NL 1.39 "\tinitrd,vga,root=(void)" NL 1.40 "\tmem=256m" NL 1.41 "\tcl=auto" NL 1.42 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL 1.43 - "Use cl=@filename to take cmdline from file" 1.44 + "Use cl=@filename to get it from a file" 1.45 #if 1 1.46 NL NL "Examples:" NL 1.47 "\tlinld initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\"" 1.48 @@ -55,59 +34,88 @@ 1.49 ); 1.50 } 1.51 1.52 +static char _cmdline[256]; 1.53 int main(int argc, char *argv[]) { 1.54 // Believe it or not - this enables A20 1.55 // on my box! Must be DOS in HMA... -vda 1.56 puts("LINLD v" VERSION_STR "+"); 1.57 1.58 - // Parse command line 1.59 - 1.60 if(argc<2) { 1.61 dosyntax: 1.62 syntax(); 1.63 } 1.64 - {for(int i=1;i<argc;i++) { 1.65 - char *s=argv[i]; 1.66 + 1.67 + // Parse command line 1.68 + {for (char i=0;;) { 1.69 + char *s=*++argv; 1.70 + i++; 1.71 + if (!s) { 1.72 + puts(load_kernel()); 1.73 + load_initrd(); 1.74 + boot_kernel(); 1.75 + } 1.76 if(strhead(s,"image=") == 0) { 1.77 - kernel_name=s+6; 1.78 + s+=6; 1.79 + kernel_name=s; 1.80 } 1.81 else if(strhead(s,"initrd=") == 0) { 1.82 - initrd_name = s+7; 1.83 + s+=7; 1.84 + initrd_name=s; 1.85 + } 1.86 + else if((*(u16 *)s|0x2002) == 0x662F) { // -F /f 1.87 + extern int skip_xmmalloc; 1.88 + skip_xmmalloc++; 1.89 + } 1.90 + else if(strhead(s,"vga=") == 0) { 1.91 + s+=4; 1.92 + vid_mode = strtol(s); // support normal, extended & ask 1.93 } 1.94 else if(strhead(s,"cl=") == 0) { 1.95 - cmdline=s+3; 1.96 - if (cmdline[0] == '@') { 1.97 - cmdline=read_cmdline_or_die(cmdline+1); 1.98 + cmdline=s+=3; 1.99 + if (*s == '@') { 1.100 + static struct image_himem image; 1.101 + char c; 1.102 + 1.103 + s++; 1.104 + image.errmsg = "Error in cl=@file"; 1.105 + open_image(s, &image); 1.106 + cmdline=s=(char *)malloc_or_die(image.size); 1.107 + s+=image.size; 1.108 + read(image.fd, (void *)cmdline, image.size); 1.109 + // Strip any trailing cr/lf 1.110 + c='\0'; 1.111 + do { 1.112 + // Replace all other cr/lfs with spaces 1.113 + s--; 1.114 + if(*s>=' ') c=' '; 1.115 + else *s = c; 1.116 + } while (s>cmdline); 1.117 puts("Kernel command line:"); 1.118 puts(cmdline); 1.119 } 1.120 } 1.121 - else if(strhead(s,"vga=") == 0) { 1.122 - s+=4; 1.123 - const char c = *s|0x20; 1.124 - if (c == 'a') vid_mode = -3; 1.125 - else if (c == 'e') vid_mode = -2; 1.126 - else if (c == 'n') vid_mode = -1; 1.127 - else vid_mode = strtol(s); 1.128 - } 1.129 else if(strhead(s,"root=") == 0) { 1.130 - root_dev = strtol(s+5); 1.131 + s+=5; 1.132 + root_dev = strtol(s); 1.133 + goto addincmdline; 1.134 } 1.135 else if(strhead(s,"mem=") == 0) { 1.136 - topmem = strtol(s+4); 1.137 + s+=4; 1.138 + topmem = strtol(s); 1.139 + goto addincmdline; 1.140 } 1.141 - else if(strhead(s,"-f") == 0) { 1.142 - extern int skip_xmmalloc; 1.143 - skip_xmmalloc++; 1.144 + else if(cmdline == (const char *) _cmdline) { 1.145 +addincmdline: 1.146 + strcatb(_cmdline,*argv); 1.147 } 1.148 - else 1.149 - goto dosyntax; 1.150 + else if(i == 1 && fileattr(s) != -1) { 1.151 + kernel_name = s; 1.152 + cmdline = (const char *) _cmdline; 1.153 + } 1.154 + else 1.155 + goto dosyntax; 1.156 }} 1.157 1.158 - puts(load_kernel()); 1.159 - load_initrd(); 1.160 - boot_kernel(); 1.161 - 1.162 // Let compiler be happy 1.163 - return _AX; 1.164 + // return _AX; 1.165 }