aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-09-06 14:15:32 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2013-09-26 17:05:41 -0400
commit809373e29a183e4d4f0e4f56ef8b211c6219123c (patch)
tree71bb170759e9a280b6822821d0da26748aea5423 /arch/x86/boot
parent4a10c2ac2f368583138b774ca41fac4207911983 (diff)
x86, build: move build output statistics away from stderr
When building on x86, the final image building step always emits stats to stderr, even though this information is neither a warning nor an error: BUILD arch/x86/boot/bzImage Setup is 16188 bytes (padded to 16384 bytes). System is 6368 kB CRC cbe50c61 Validating automated builds would be cleaner if stderr did not have to filter out these lines. Instead, change how tools/build is called, and make the zoffset header unconditional, and write to a specified file instead of to stdout, which can then be used for statistics, leaving stderr open for legitimate warnings and errors, like the output from die(). Signed-off-by: Kees Cook <keescook@chromium.org> Link: http://lkml.kernel.org/r/20130906181532.GA31260@www.outflux.net Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/Makefile3
-rw-r--r--arch/x86/boot/tools/build.c40
2 files changed, 26 insertions, 17 deletions
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 379814bc41e3..dce69a256896 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -71,7 +71,8 @@ GCOV_PROFILE := n
71$(obj)/bzImage: asflags-y := $(SVGA_MODE) 71$(obj)/bzImage: asflags-y := $(SVGA_MODE)
72 72
73quiet_cmd_image = BUILD $@ 73quiet_cmd_image = BUILD $@
74cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/zoffset.h > $@ 74cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin \
75 $(obj)/zoffset.h $@
75 76
76$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE 77$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE
77 $(call if_changed,image) 78 $(call if_changed,image)
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index c941d6a8887f..8e15b22391fc 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -5,14 +5,15 @@
5 */ 5 */
6 6
7/* 7/*
8 * This file builds a disk-image from two different files: 8 * This file builds a disk-image from three different files:
9 * 9 *
10 * - setup: 8086 machine code, sets up system parm 10 * - setup: 8086 machine code, sets up system parm
11 * - system: 80386 code for actual system 11 * - system: 80386 code for actual system
12 * - zoffset.h: header with ZO_* defines
12 * 13 *
13 * It does some checking that all files are of the correct type, and 14 * It does some checking that all files are of the correct type, and writes
14 * just writes the result to stdout, removing headers and padding to 15 * the result to the specified destination, removing headers and padding to
15 * the right amount. It also writes some system data to stderr. 16 * the right amount. It also writes some system data to stdout.
16 */ 17 */
17 18
18/* 19/*
@@ -136,7 +137,7 @@ static void die(const char * str, ...)
136 137
137static void usage(void) 138static void usage(void)
138{ 139{
139 die("Usage: build setup system [zoffset.h] [> image]"); 140 die("Usage: build setup system zoffset.h image");
140} 141}
141 142
142#ifdef CONFIG_EFI_STUB 143#ifdef CONFIG_EFI_STUB
@@ -265,7 +266,7 @@ int main(int argc, char ** argv)
265 int c; 266 int c;
266 u32 sys_size; 267 u32 sys_size;
267 struct stat sb; 268 struct stat sb;
268 FILE *file; 269 FILE *file, *dest;
269 int fd; 270 int fd;
270 void *kernel; 271 void *kernel;
271 u32 crc = 0xffffffffUL; 272 u32 crc = 0xffffffffUL;
@@ -280,10 +281,13 @@ int main(int argc, char ** argv)
280 startup_64 = 0x200; 281 startup_64 = 0x200;
281#endif 282#endif
282 283
283 if (argc == 4) 284 if (argc != 5)
284 parse_zoffset(argv[3]);
285 else if (argc != 3)
286 usage(); 285 usage();
286 parse_zoffset(argv[3]);
287
288 dest = fopen(argv[4], "w");
289 if (!dest)
290 die("Unable to write `%s': %m", argv[4]);
287 291
288 /* Copy the setup code */ 292 /* Copy the setup code */
289 file = fopen(argv[1], "r"); 293 file = fopen(argv[1], "r");
@@ -318,7 +322,7 @@ int main(int argc, char ** argv)
318 /* Set the default root device */ 322 /* Set the default root device */
319 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); 323 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
320 324
321 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); 325 printf("Setup is %d bytes (padded to %d bytes).\n", c, i);
322 326
323 /* Open and stat the kernel file */ 327 /* Open and stat the kernel file */
324 fd = open(argv[2], O_RDONLY); 328 fd = open(argv[2], O_RDONLY);
@@ -327,7 +331,7 @@ int main(int argc, char ** argv)
327 if (fstat(fd, &sb)) 331 if (fstat(fd, &sb))
328 die("Unable to stat `%s': %m", argv[2]); 332 die("Unable to stat `%s': %m", argv[2]);
329 sz = sb.st_size; 333 sz = sb.st_size;
330 fprintf (stderr, "System is %d kB\n", (sz+1023)/1024); 334 printf("System is %d kB\n", (sz+1023)/1024);
331 kernel = mmap(NULL, sz, PROT_READ, MAP_SHARED, fd, 0); 335 kernel = mmap(NULL, sz, PROT_READ, MAP_SHARED, fd, 0);
332 if (kernel == MAP_FAILED) 336 if (kernel == MAP_FAILED)
333 die("Unable to mmap '%s': %m", argv[2]); 337 die("Unable to mmap '%s': %m", argv[2]);
@@ -348,27 +352,31 @@ int main(int argc, char ** argv)
348#endif 352#endif
349 353
350 crc = partial_crc32(buf, i, crc); 354 crc = partial_crc32(buf, i, crc);
351 if (fwrite(buf, 1, i, stdout) != i) 355 if (fwrite(buf, 1, i, dest) != i)
352 die("Writing setup failed"); 356 die("Writing setup failed");
353 357
354 /* Copy the kernel code */ 358 /* Copy the kernel code */
355 crc = partial_crc32(kernel, sz, crc); 359 crc = partial_crc32(kernel, sz, crc);
356 if (fwrite(kernel, 1, sz, stdout) != sz) 360 if (fwrite(kernel, 1, sz, dest) != sz)
357 die("Writing kernel failed"); 361 die("Writing kernel failed");
358 362
359 /* Add padding leaving 4 bytes for the checksum */ 363 /* Add padding leaving 4 bytes for the checksum */
360 while (sz++ < (sys_size*16) - 4) { 364 while (sz++ < (sys_size*16) - 4) {
361 crc = partial_crc32_one('\0', crc); 365 crc = partial_crc32_one('\0', crc);
362 if (fwrite("\0", 1, 1, stdout) != 1) 366 if (fwrite("\0", 1, 1, dest) != 1)
363 die("Writing padding failed"); 367 die("Writing padding failed");
364 } 368 }
365 369
366 /* Write the CRC */ 370 /* Write the CRC */
367 fprintf(stderr, "CRC %x\n", crc); 371 printf("CRC %x\n", crc);
368 put_unaligned_le32(crc, buf); 372 put_unaligned_le32(crc, buf);
369 if (fwrite(buf, 1, 4, stdout) != 4) 373 if (fwrite(buf, 1, 4, dest) != 4)
370 die("Writing CRC failed"); 374 die("Writing CRC failed");
371 375
376 /* Catch any delayed write failures */
377 if (fclose(dest))
378 die("Writing image failed");
379
372 close(fd); 380 close(fd);
373 381
374 /* Everything is OK */ 382 /* Everything is OK */