wok-current view 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 source
1 // This file is distributed under GPL
2 //
3 // LINLD main() lives here
5 #include "crtl.h"
6 #include "common.h"
8 static struct image_himem image;
9 static const char msg_cmdline[] = "Error reading cl=@file";
10 static char* read_cmdline_or_die(const char* fn) {
11 image.errmsg = msg_cmdline;
12 open_image(fn, &image);
13 u16 size=image.size;
14 char *cmdline_buf;
15 if(size>=PAGE_SIZE ||
16 !(cmdline_buf=(char *)malloc(size)) ||
17 read(image.fd, cmdline_buf, size) != size)
18 die(msg_cmdline);
19 // Strip any trailing cr/lf
20 char *p=cmdline_buf+size;
21 char c='\0';
22 do {
23 // Replace all other cr/lfs with spaces
24 if(*--p>=' ') c=' ';
25 else *p = c;
26 } while (p>cmdline_buf);
27 return cmdline_buf;
28 }
30 const char* kernel_name = "bzImage";
31 const char* initrd_name;
32 const char* cmdline = "auto";
33 u16 root_dev;
34 u16 vid_mode; // -3 = ask
35 // -2 = Extended VGA
36 // -1 = Normal VGA
37 // n = as "n" was pressed
39 inline void syntax() {
40 die("Syntax:" NL
41 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
42 "vga mode: ask,extended,normal or dec/oct/hex number" NL
43 "Defaults:" NL
44 "\timage=bzImage" NL
45 "\tinitrd,vga,root=(void)" NL
46 "\tmem=256m" NL
47 "\tcl=auto" NL
48 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
49 "Use cl=@filename to take cmdline from file"
50 #if 1
51 NL NL "Examples:" NL
52 "\tlinld initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
53 NL NL "\tlinld image=memtest"
54 #endif
55 );
56 }
58 int main(int argc, char *argv[]) {
59 // Believe it or not - this enables A20
60 // on my box! Must be DOS in HMA... -vda
61 puts("LINLD v" VERSION_STR "+");
63 // Parse command line
65 if(argc<2) {
66 dosyntax:
67 syntax();
68 }
69 {for(int i=1;i<argc;i++) {
70 char *s=argv[i];
71 if(strhead(s,"image=") == 0) {
72 kernel_name=s+6;
73 }
74 else if(strhead(s,"initrd=") == 0) {
75 initrd_name = s+7;
76 }
77 else if(strhead(s,"cl=") == 0) {
78 cmdline=s+3;
79 if (cmdline[0] == '@') {
80 cmdline=read_cmdline_or_die(cmdline+1);
81 puts("Kernel command line:");
82 puts(cmdline);
83 }
84 }
85 else if(strhead(s,"vga=") == 0) {
86 s+=4;
87 const char c = *s|0x20;
88 if (c == 'a') vid_mode = -3;
89 else if (c == 'e') vid_mode = -2;
90 else if (c == 'n') vid_mode = -1;
91 else vid_mode = strtol(s);
92 }
93 else if(strhead(s,"root=") == 0) {
94 root_dev = strtol(s+5);
95 }
96 else if(strhead(s,"mem=") == 0) {
97 topmem = strtol(s+4);
98 }
99 else if(strhead(s,"-f") == 0) {
100 extern int skip_xmmalloc;
101 skip_xmmalloc++;
102 }
103 else
104 goto dosyntax;
105 }}
107 puts(load_kernel());
108 load_initrd();
109 boot_kernel();
111 // Let compiler be happy
112 return _AX;
113 }