29 #include <sys/types.h>
31 #include <sys/sysmacros.h>
36 #define DEFAULT_MAJOR_ROOT 0
37 #define DEFAULT_MINOR_ROOT 0
60 die(
"Unable to open `%s': %m", name);
66 die(
"Usage: build [-b] bootsect setup system [rootdev] [> image]");
71 unsigned int i,
c, sz, setup_sectors;
76 if (argc > 2 && !
strcmp(argv[1],
"-b")) {
80 if ((argc < 4) || (argc > 5))
83 if (!
strcmp(argv[4],
"CURRENT")) {
86 die(
"Couldn't stat /");
90 }
else if (
strcmp(argv[4],
"FLOPPY")) {
91 if (
stat(argv[4], &sb)) {
93 die(
"Couldn't stat root device.");
105 fprintf(stderr,
"Root device is (%d, %d)\n", major_root, minor_root);
109 fprintf(stderr,
"Boot sector %d bytes.\n", i);
111 die(
"Boot block must be exactly 512 bytes");
112 if (
buf[510] != 0x55 ||
buf[511] != 0xaa)
113 die(
"Boot block hasn't got boot flag (0xAA55)");
114 buf[508] = minor_root;
115 buf[509] = major_root;
117 die(
"Write call failed");
124 die(
"Write call failed");
126 die(
"read-error on `setup'");
130 setup_sectors = (i + 511) / 512;
134 fprintf(stderr,
"Setup is %d bytes.\n", i);
136 while (i < setup_sectors * 512) {
137 c = setup_sectors * 512 -
i;
141 die(
"Write call failed");
147 die(
"Unable to stat `%s': %m", argv[3]);
149 fprintf(stderr,
"System is %d kB\n", sz / 1024);
150 sys_size = (sz + 15) / 16;
153 die(
"System is too big. Try using %smodules.",
155 if (sys_size > 0xffff)
157 "warning: kernel is too big for standalone boot "
162 l = (sz >
sizeof(
buf)) ?
sizeof(
buf) : sz;
166 die(
"Error reading %s: %m", argv[3]);
168 die(
"%s: Unexpected EOF", argv[3]);
178 die(
"Output: seek failed");
179 buf[0] = setup_sectors;
181 die(
"Write of setup sector count failed");
183 die(
"Output: seek failed");
184 buf[0] = (sys_size & 0xff);
185 buf[1] = ((sys_size >> 8) & 0xff);
187 die(
"Write of image length failed");