wok annotate linld/stuff/src/TAZBOOT.CPP @ rev 21801

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