Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/mkubootimage When printing the header, convert value...
details: https://anonhg.NetBSD.org/src/rev/30a0c1701d76
branches: trunk
changeset: 765861:30a0c1701d76
user: matt <matt%NetBSD.org@localhost>
date: Wed Jun 08 05:54:38 2011 +0000
description:
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
diffstat:
usr.bin/mkubootimage/mkubootimage.c | 70 +++++++++++++++++++++++++++++++++---
1 files changed, 63 insertions(+), 7 deletions(-)
diffs (126 lines):
diff -r ebc3b56247bd -r 30a0c1701d76 usr.bin/mkubootimage/mkubootimage.c
--- a/usr.bin/mkubootimage/mkubootimage.c Wed Jun 08 05:31:43 2011 +0000
+++ b/usr.bin/mkubootimage/mkubootimage.c Wed Jun 08 05:54:38 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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);
Home |
Main Index |
Thread Index |
Old Index