wok view linld/stuff/src/TAZBOOT.CPP @ rev 23471
updated python-cheetah (2.4.3 -> 2.4.4)
author | Hans-G?nter Theisgen |
---|---|
date | Sun Apr 05 14:34:55 2020 +0100 (2020-04-05) |
parents | 53c1379e13fa |
children | 00ef8230cd61 |
line source
1 // This file is distributed under GPL
2 //
3 // TAZBOOT main() lives here
5 #include "crtl.h"
6 #include "crtlx.h"
7 #include "common.h"
8 #include "iso9660.h"
10 struct initrd_info {
11 u32 ofs;
12 u32 size;
13 };
14 #define MAXINITRD 10
15 static struct initrd_state {
16 struct initrd_info info[MAXINITRD];
17 u16 cnt;
18 } initrd_state;
20 static void next_chunk(struct image_himem *m)
21 {
22 m->chunk_size = 0;
23 if (m->state >= initrd_state.cnt) return;
24 struct initrd_info *i = &initrd_state.info[m->state];
25 m->chunk_size = i->size;
26 m->state++;
27 lseekset2(m->fd,&i->ofs);
28 }
30 static u32 isofilesize4round()
31 {
32 return (isofilesize+3)&-4;
33 }
35 static void addinitrd()
36 {
37 u16 *pcnt = &initrd_state.cnt;
38 if (*pcnt >= MAXINITRD) return;
39 struct initrd_info *i = &initrd_state.info[(*pcnt)++];
40 i->size = isofilesize;
41 i->ofs = isofileofs;
42 initrd.size += isofilesize4round();
43 }
45 static void load_initrds()
46 {
47 struct image_himem *m = &initrd;
48 if (!m->size) return;
49 m->next_chunk = next_chunk;
50 m->fd = isofd;
51 m->state = 0;
52 next_chunk(m);
53 load_initrd();
54 }
56 static char *isokernel()
57 {
58 struct image_himem *m = ±
59 m->chunk_size = m->size = isofilesize4round();
60 m->fd = isofd;
61 load_kernel();
62 return version_string;
63 }
65 static char buf_cmdline[4096];
66 const char *cmdline = (const char *) buf_cmdline+1;
67 static void bootiso(char **iso)
68 {
69 const char *init = " rdinit=/init.exe", *mode="menu";
70 char c;
71 static char rootfs[16], fallback[16], noauto;
72 unsigned long magic;
73 struct isostate *x=&isostate;
75 if (isoreset(*iso) == -1) return;
76 skip_alloc--;
77 base_himem = memtop() /2;
78 //if (base_himem >= _64m) base_himem = _64m;
79 if (* ((char *) &base_himem +3) >= 4) ((short *)&base_himem)[1] = _64m/_64k;
80 isoopen("boot");
81 if (iso[1] && !strcmp(mode = iso[1], "text"))
82 init = "";
83 if (isoopen(mode) == -1 || ++noauto == 0) // custom
84 isoopen("bzImage"); // SliTaz
85 magic = kver2ul(isokernel());
86 for (c = 0, x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
87 if (strstr(x->filename, ".gz"))
88 strcpy(fallback, x->filename);
89 if (strhead(x->filename, "rootfs") == -1
90 || c > x->filename[6]) continue;
91 c = x->filename[6];
92 strcpy(rootfs, x->filename);
93 }
95 strcatb(buf_cmdline,"autologin bootfrom=");
96 strcat(buf_cmdline,*iso);
97 if (magic < 0x20630)
98 init = ""; // Does not support multiple initramfs
100 if (noauto) {
101 char *s;
102 * (int *) buf_cmdline = 0;
103 iso++;
104 while ((s = *++iso) != NULL) {
105 if (strhead(s,"initrd=") == -1)
106 strcatb(buf_cmdline,s);
107 else if (isoopen(s+7) != -1)
108 addinitrd();
109 }
110 }
111 else if (magic != 0) {
112 static const unsigned long initrddesc = 18L;
114 if (isoopen("rootfs.gz") != -1 ||
115 isoopen(rootfs[0] ? rootfs : fallback) != -1) {
116 addinitrd();
117 }
118 if (*init) {
119 isolseek(&initrddesc);
120 read(x->fd, &x->filemod, 10); // + x->fileofs & x->filesize
121 magic = x->filemod;
122 x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
123 if (((short *) &x->fileofs)[1] == 0) addinitrd();
124 else init="";
125 }
126 strcat(buf_cmdline,init);
127 strcatb(buf_cmdline,"mode=");
128 strcat(buf_cmdline,mode);
129 strcatb(buf_cmdline,"magic=");
130 strcat(buf_cmdline,(char *)ultoa(magic));
131 }
132 load_initrds();
133 close(x->fd);
134 boot_kernel();
135 }
137 u32 root_dev;
138 u32 vid_mode;
139 u32 topmem;
140 u32 base_himem;
141 const char* kernel_name = "bzImage";
142 const char* initrd_name;
143 static char* iso;
145 int main(int argc, char *argv[])
146 {
147 ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k
149 if (argc < 2) {
150 try_default_args();
151 dousage:
152 die("Usage: tazboot [[@commands]|[-f][-b base_himem][kernel=<bzImage>] \
153 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] ...]\n\n\
154 Defaults: tazboot kernel=bzImage auto\n\n\
155 Examples for tazboot.cmd:\n\n\
156 bootfrom=\\isos\\slitaz-4.0.iso\n\
157 kernel=boot/bzImage\n\
158 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz,\\slitaz\\extrafs.gz\n\
159 vga=normal autologin\n\n\
160 kernel=\\slitaz\\elks\n\
161 root=/dev/bda1 ro\n");
162 }
163 bootiso(argv + 1); // iso ? parsing is /init.exe stuff !
164 for (int i=0;;) {
165 char *s;
166 next: argv++;
167 s=*argv;
168 i++;
169 if (!s) {
170 if (isoreset(iso) != -1) {
171 s = (char *) initrd_name;
172 if (isoopen((char *) kernel_name) != -1) {
173 isokernel();
174 }
175 if (s) {
176 do {
177 char *p, c;
178 for (p = s; *s && *s != ','; s++);
179 c = *s; *s = 0;
180 if (isoopen(p) != -1) {
181 addinitrd();
182 }
183 *s = c;
184 if (c) s++;
185 } while (*s);
186 load_initrds();
187 }
188 }
189 else {
190 load_kernel();
191 load_initrd();
192 }
193 boot_kernel();
194 }
195 #ifdef USE_ARGSTR
196 if ((*(u16 *)s|0x2002) == 0x662F) { // -F /f
197 skip_alloc--;
198 goto next;
199 }
200 if (argstr(s,"kernel/image|initrd|bootfrom/iso",&kernel_name) != -1);
201 else if (argnum(s,"root|vga|mem/-e|-b",&root_dev) != -1);
202 else if(i == 1 && fileexist(s) != -1) {
203 kernel_name = s;
204 }
205 else strcatb(buf_cmdline,*argv); // FIXME mem ?
206 }
207 #else
208 if (strhead(s,"initrd=") != -1) {
209 s += 7;
210 initrd_name = s;
211 }
212 else if (strhead(s,"bootfrom=") != -1) {
213 s += 9;
214 goto set_iso;
215 }
216 else if (strhead(s,"iso=") != -1) {
217 s += 4;
218 set_iso:
219 iso = s;
220 }
221 else if (strhead(s,"image=") != -1) {
222 goto set_kernel;
223 }
224 else if(strhead(s,"vga=") != -1) {
225 *(u16*)&vid_mode = (u16)strtol(s+4); // support normal, extended & ask
226 }
227 else if (strhead(s,"kernel=") != -1) {
228 s++;
229 set_kernel:
230 s += 6;
231 set_kernelz:
232 kernel_name = s;
233 }
234 else switch (*(u16 *)s|0x2002) {
235 case 0x662F: // -F /f
236 skip_alloc--;
237 goto next;
238 case 0x652F: // -E /e
239 s=*++argv;
240 goto set_topmem;
241 case 0x622F: // -B /b
242 argv++;
243 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
244 goto next;
245 default:
246 if(i == 1 && fileexist(s) != -1) {
247 goto set_kernelz;
248 }
249 else {
250 strcatb(buf_cmdline,*argv);
251 if(strhead(s,"root=") != -1) {
252 *(u16*)&root_dev = (u16)strtol(s+5);
253 }
254 if(strhead(s,"mem=") != -1) {
255 s += 4;
256 set_topmem:
257 ((u16 *)&topmem)[1] = (u16)(strtol(s)>>16);
258 }
259 }}
260 }
261 #endif
262 }