wok view linld/stuff/src/LINLD.CPP @ rev 19571

linld: large image support with VCPI
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Dec 22 21:06:17 2016 +0100 (2016-12-22)
parents 7f92b23984dc
children 23fc786c04e8
line source
1 // This file is distributed under GPL
2 //
3 // LINLD main() lives here
5 #include "crtl.h"
6 #include "common.h"
8 const char* kernel_name = "bzImage";
9 const char* initrd_name;
10 const char* cmdline = "auto";
11 u16 root_dev;
12 u16 vid_mode; // -3 = ask
13 // -2 = Extended VGA
14 // -1 = Normal VGA
15 // n = as "n" was pressed
17 inline void syntax() {
18 die("Syntax:" NL
19 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
20 "vga mode: ask,extended,normal or dec/oct/hex number" NL
21 "-f force" NL
22 "Defaults:" NL
23 "\timage=bzImage" NL
24 "\tinitrd,vga,root=(void)" NL
25 "\tmem=256m" NL
26 "\tcl=auto" NL
27 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
28 "Use cl=@filename to get it from a file"
29 #if 1
30 NL NL "Examples:" NL
31 "\tlinld initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
32 NL NL "\tlinld image=memtest"
33 #endif
34 );
35 }
37 static char _cmdline[256];
38 int main(int argc, char *argv[]) {
40 (void) argc;
42 // Believe it or not - this enables A20
43 // on my box! Must be DOS in HMA... -vda
44 puts("LINLD v" VERSION_STR "+");
46 // Parse command line
47 if (argv[1]) {for (char i=0;;) {
48 char *s;
49 argv++;
50 s=*argv;
51 i++;
52 if (!s) {
53 puts(load_kernel());
54 load_initrd();
55 boot_kernel();
56 }
57 if(strhead(s,"image=") == 0) {
58 s+=6;
59 kernel_name=s;
60 }
61 else if(strhead(s,"initrd=") == 0) {
62 s+=7;
63 initrd_name=s;
64 }
65 else if((*(u16 *)s|0x2002) == 0x662F) { // -F /f
66 extern int skip_xmmalloc;
67 skip_xmmalloc++;
68 }
69 else if(strhead(s,"vga=") == 0) {
70 s+=4;
71 vid_mode = strtol(s); // support normal, extended & ask
72 }
73 else if(strhead(s,"cl=") == 0) {
74 cmdline=s+=3;
75 if (*s == '@') {
76 static struct image_himem image;
77 char c;
79 s++;
80 image.errmsg = "Error in cl=@file";
81 open_image(s, &image);
82 cmdline=s=(char *)malloc_or_die(image.size);
83 s+=image.size;
84 read(image.fd, (void *)cmdline, image.size);
85 // Strip any trailing cr/lf
86 c='\0';
87 do {
88 // Replace all other cr/lfs with spaces
89 s--;
90 if(*s>=' ') c=' ';
91 else *s = c;
92 } while (s>cmdline);
93 puts("Kernel command line:");
94 puts(cmdline);
95 }
96 }
97 else if(strhead(s,"root=") == 0) {
98 s+=5;
99 root_dev = strtol(s);
100 goto addincmdline;
101 }
102 else if(strhead(s,"mem=") == 0) {
103 s+=4;
104 topmem = strtol(s);
105 goto addincmdline;
106 }
107 else if(cmdline == (const char *) _cmdline) {
108 addincmdline:
109 strcatb(_cmdline,*argv);
110 }
111 else if(i == 1 && fileattr(s) != -1) {
112 kernel_name = s;
113 cmdline = (const char *) _cmdline;
114 }
115 else
116 break;
117 }}
118 syntax();
120 // Let compiler be happy
121 return _AX;
122 }