Module Name: src Committed By: matt Date: Wed Jun 8 05:54:38 UTC 2011
Modified Files: src/usr.bin/mkubootimage: mkubootimage.c Log Message: When printing the header, convert values to names: Use strlcpy to copy the name, not strncpy. magic: 0x27051956 time: Tue Jun 7 15:58:41 2011 size: 2482203 load addr: 0x00020000 entry point: 0x00020000 data crc: 0x700fdf53 os: 2 (netbsd) arch: 7 (powerpc) type: 2 (kernel) comp: 1 (gz) name: NetBSD/evbppc 5.99.52 (INSTALL_ header crc: 0x94ea96cf To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/mkubootimage/mkubootimage.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/mkubootimage/mkubootimage.c diff -u src/usr.bin/mkubootimage/mkubootimage.c:1.6 src/usr.bin/mkubootimage/mkubootimage.c:1.7 --- src/usr.bin/mkubootimage/mkubootimage.c:1.6 Sat Feb 26 20:03:09 2011 +++ src/usr.bin/mkubootimage/mkubootimage.c Wed Jun 8 05:54:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mkubootimage.c,v 1.6 2011/02/26 20:03:09 phx Exp $ */ +/* $NetBSD: mkubootimage.c,v 1.7 2011/06/08 05:54:38 matt Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcne...@invisible.ca> @@ -30,7 +30,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: mkubootimage.c,v 1.6 2011/02/26 20:03:09 phx Exp $"); +__RCSID("$NetBSD: mkubootimage.c,v 1.7 2011/06/08 05:54:38 matt Exp $"); #include <sys/mman.h> #include <sys/stat.h> @@ -84,6 +84,19 @@ return IH_OS_UNKNOWN; } +static const char * +get_os_name(enum uboot_image_os os) +{ + unsigned int i; + + for (i = 0; i < __arraycount(uboot_os); i++) { + if (uboot_os[i].os == os) + return uboot_os[i].name; + } + + return "Unknown"; +} + struct uboot_arch { enum uboot_image_arch arch; const char *name; @@ -107,6 +120,19 @@ return IH_ARCH_UNKNOWN; } +static const char * +get_arch_name(enum uboot_image_arch arch) +{ + unsigned int i; + + for (i = 0; i < __arraycount(uboot_arch); i++) { + if (uboot_arch[i].arch == arch) + return uboot_arch[i].name; + } + + return "Unknown"; +} + struct uboot_type { enum uboot_image_type type; const char *name; @@ -130,6 +156,19 @@ return IH_TYPE_UNKNOWN; } +static const char * +get_type_name(enum uboot_image_type type) +{ + unsigned int i; + + for (i = 0; i < __arraycount(uboot_type); i++) { + if (uboot_type[i].type == type) + return uboot_type[i].name; + } + + return "Unknown"; +} + struct uboot_comp { enum uboot_image_comp comp; const char *name; @@ -152,6 +191,19 @@ return IH_TYPE_UNKNOWN; } +static const char * +get_comp_name(enum uboot_image_comp comp) +{ + unsigned int i; + + for (i = 0; i < __arraycount(uboot_comp); i++) { + if (uboot_comp[i].comp == comp) + return uboot_comp[i].name; + } + + return "Unknown"; +} + static void usage(void) { @@ -176,10 +228,14 @@ printf(" load addr: 0x%08x\n", ntohl(hdr->ih_load)); printf(" entry point: 0x%08x\n", ntohl(hdr->ih_ep)); printf(" data crc: 0x%08x\n", ntohl(hdr->ih_dcrc)); - printf(" os: %d\n", hdr->ih_os); - printf(" arch: %d\n", hdr->ih_arch); - printf(" type: %d\n", hdr->ih_type); - printf(" comp: %d\n", hdr->ih_comp); + printf(" os: %d (%s)\n", hdr->ih_os, + get_os_name(hdr->ih_os)); + printf(" arch: %d (%s)\n", hdr->ih_arch, + get_arch_name(hdr->ih_arch)); + printf(" type: %d (%s)\n", hdr->ih_type, + get_type_name(hdr->ih_type)); + printf(" comp: %d (%s)\n", hdr->ih_comp, + get_comp_name(hdr->ih_comp)); printf(" name: %s\n", hdr->ih_name); printf(" header crc: 0x%08x\n", hdr->ih_hcrc); } @@ -222,7 +278,7 @@ hdr->ih_arch = image_arch; hdr->ih_type = image_type; hdr->ih_comp = image_comp; - strncpy((char *)hdr->ih_name, image_name, sizeof(hdr->ih_name)); + strlcpy((char *)hdr->ih_name, image_name, sizeof(hdr->ih_name)); crc = crc32((void *)hdr, sizeof(*hdr)); hdr->ih_hcrc = htonl(crc);