wok view syslinux/stuff/iso2exe/boot.c @ rev 15771

fpm2: add icon
author Dominique Corbex <domcox@slitaz.org>
date Tue Jan 07 22:29:24 2014 +0100 (2014-01-07)
parents bf8be127c60b
children 647e4ebbbcae
line source
1 #include <asm/limits.h>
2 #include <sys/types.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include "iso9660.h"
7 #include "bootlinux.h"
8 #include "libdos.h"
10 static void usage(char *iso)
11 {
12 printf("Usage: %s [[@commands]|[kernel=<bzimage>] \
13 [initrd=<rootfs>[,<rootfs2>...]] [iso=<isofile>] ...]\n\n\
14 Defaults: %s @tazboot.cmd or %s kernel=bzImage auto\n\n\
15 Examples for tazboot.cmd:\n\n\
16 iso=\\isos\\slitaz-4.0.iso\n\
17 kernel=boot/bzImage\n\
18 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
19 rw root=/dev/null vga=normal autologin\n\n\
20 kernel=\\slitaz\\vmlinuz\n\
21 root=/dev/sda5 ro\n",iso,iso,iso);
22 exit(1);
23 }
25 static void bootiso(char **iso)
26 {
27 char *init = "rdinit=/init.exe", *mode="menu";
28 char c, *s, rootfs[16], cmdline[256];
29 int fd, restart;
30 unsigned long magic;
32 if (isoreset(*iso) || isoopen("boot")) return;
33 if (iso[1] && !strcmp(mode = iso[1], "text"))
34 init = "";
35 for (c = 0, restart = 1; isoreaddir(restart) == 0; restart = 0) {
36 if (strncmp(isofilename, "rootfs", 6) || c > s[6]) continue;
37 strcpy(rootfs, isofilename);
38 c = s[6];
39 }
40 if (isoopen(mode))
41 isoopen("bzImage");
42 if (loadkernel() < 0x20630)
43 init = ""; // Does not support multiple initramfs
44 isoopen(rootfs);
45 loadinitrd();
46 lseek(isofd, 24, SEEK_SET);
47 read(isofd, &magic, 4);
48 isofilesize = magic & 0xFFFF;
49 isofileofs = 0x7EE0 - isofilesize;
50 loadinitrd();
51 close(isofd);
52 sprintf(cmdline,"rw root=/dev/null %s iso=%s magic=%lu mode=%s",
53 init, *iso, magic, mode);
54 bootlinux(cmdline);
55 }
57 static int stricmp(char *ref, char *s)
58 {
59 char c;
60 while (*ref) {
61 c = *s++;
62 if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
63 c -= *ref++;
64 if (c) return c;
65 }
66 return 0;
67 }
69 static char *iso;
70 static int fakeopen(char *file)
71 {
72 if (iso) {
73 isoreset(iso);
74 return isoopen(file);
75 }
76 close(isofd);
77 isofd = open(file, O_RDONLY);
78 if (isofd != -1) {
79 isofileofs = 0;
80 isofilesize = LONG_MAX;
81 }
82 return isofd;
83 }
85 static char args[2048];
86 int main(int argc, char *argv[])
87 {
88 char *kernel, *initrd, *cmdline, *cmdfile, *s;
90 argv[0] = progname();
91 bootiso(argv); // iso ? parsing is /init.exe stuff !
92 if (argc == 2)
93 bootiso(argv + 1);
95 chdirname(*argv);
96 cmdfile = "tazboot.cmd";
97 kernel = "bzImage";
98 initrd = NULL;
99 cmdline = "auto";
100 if (argc > 1) {
101 if (argv[1][0] == '@')
102 cmdfile = argv[1] + 1;
103 else {
104 cmdfile = NULL;
105 #asm
106 push ds
107 pop es
108 mov si, #0x82
109 mov di, #_args
110 mov cx, #0x7E/2
111 rep
112 seg cs
113 movsw
114 #endasm
115 }
116 }
117 if (cmdfile) {
118 int fd;
119 fd = open(cmdfile, O_RDONLY);;
120 if (fd != -1) {
121 read(fd, args, sizeof(args));
122 close(fd);
123 for (s = args; s < args + sizeof(args) -1; s++) {
124 if (*s == '\r') *s++ = ' ';
125 if (*s == '\n') *s = ' ';
126 }
127 }
128 }
129 for (s = args; s < args + sizeof(args); s++) {
130 if (*s == ' ') continue;
131 if (stricmp("kernel=", s) == 0)
132 kernel = s + 7;
133 else if (stricmp("initrd=", s) == 0)
134 initrd = s + 7;
135 else if (stricmp("iso=", s) == 0)
136 iso = s + 4;
137 else {
138 cmdline = s;
139 break;
140 }
141 while (*s && *s != ' ') s++;
142 *s = 0;
143 }
144 if (fakeopen(kernel) == -1)
145 usage(argv[0]);
146 loadkernel();
147 if (initrd) {
148 char *p, *q = initrd;
149 while (1) {
150 char c;
151 for (p = q; *p && *p != ','; p++);
152 c = *p;
153 *p = 0;
154 if (fakeopen(q) != -1)
155 loadinitrd();
156 if (c == 0)
157 break;
158 q = ++p;
159 }
160 }
161 bootlinux(cmdline);
162 }