summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-10-07 14:11:38 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-10-07 14:11:38 +0200
commitf7403928a9ee57ac717e38610dcbb04bb7798734 (patch)
tree3b7d58ff844b1ea9edbf0147035c62fe4887be5f
parent884f4d47c697b825a7e69fe51d3b409be58da5d0 (diff)
downloadbarebox-f7403928a9ee57ac717e38610dcbb04bb7798734.tar.gz
barebox-f7403928a9ee57ac717e38610dcbb04bb7798734.tar.xz
Revert "Replace direct header access with the API routines"
This reverts commit 0ceafe14be072696eff3e549d8c7b7de8a3e416d. Conflicts: include/image.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/lib/armlinux.c6
-rw-r--r--arch/blackfin/lib/blackfin_linux.c4
-rw-r--r--arch/m68k/lib/m68k-linuxboot.c8
-rw-r--r--arch/ppc/lib/ppclinux.c6
-rw-r--r--commands/bootm.c79
-rw-r--r--common/image.c8
-rw-r--r--include/image.h179
-rw-r--r--scripts/mkimage.c84
8 files changed, 103 insertions, 271 deletions
diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index 7c2cbf95ea..b50d535811 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -212,7 +212,7 @@ int do_bootm_linux(struct image_data *data)
void (*theKernel)(int zero, int arch, void *params);
image_header_t *os_header = &data->os->header;
- if (image_check_type(os_header, IH_TYPE_MULTI)) {
+ if (os_header->ih_type == IH_TYPE_MULTI) {
printf("Multifile images not handled at the moment\n");
return -1;
}
@@ -227,14 +227,14 @@ int do_bootm_linux(struct image_data *data)
return -1;
}
- theKernel = (void *)image_get_ep(os_header);
+ theKernel = (void *)ntohl(os_header->ih_ep);
debug("## Transferring control to Linux (at address 0x%p) ...\n",
theKernel);
setup_tags();
- if (relocate_image(data->os, (void *)image_get_load(os_header)))
+ if (relocate_image(data->os, (void *)ntohl(os_header->ih_load)))
return -1;
/* we assume that the kernel is in place */
diff --git a/arch/blackfin/lib/blackfin_linux.c b/arch/blackfin/lib/blackfin_linux.c
index eda3f4c011..ce5f3a54c2 100644
--- a/arch/blackfin/lib/blackfin_linux.c
+++ b/arch/blackfin/lib/blackfin_linux.c
@@ -47,10 +47,10 @@ static int do_bootm_linux(struct image_data *idata)
struct image_handle *os_handle = idata->os;
image_header_t *os_header = &os_handle->header;
- appl = (int (*)(char *))image_get_ep(os_header);
+ appl = (int (*)(char *))ntohl(os_header->ih_ep);
printf("Starting Kernel at 0x%08x\n", appl);
- if (relocate_image(os_handle, (void *)image_get_load(os_header)))
+ if (relocate_image(os_handle, (void *)ntohl(os_header->ih_load)))
return -1;
icache_disable();
diff --git a/arch/m68k/lib/m68k-linuxboot.c b/arch/m68k/lib/m68k-linuxboot.c
index e5e90a8722..417a8e0cd7 100644
--- a/arch/m68k/lib/m68k-linuxboot.c
+++ b/arch/m68k/lib/m68k-linuxboot.c
@@ -109,20 +109,20 @@ static int do_bootm_linux(struct image_data *data)
const char *commandline = getenv ("bootargs");
uint32_t loadaddr,loadsize;
- if (image_check_type(os_header, IH_TYPE_MULTI)) {
+ if (os_header->ih_type == IH_TYPE_MULTI) {
printf("Multifile images not handled at the moment\n");
return -1;
}
printf("commandline: %s\n", commandline);
- theKernel = (void (*)(int,int,uint))image_get_ep(os_header);
+ theKernel = (void (*)(int,int,uint))ntohl((os_header->ih_ep));
debug ("## Transferring control to Linux (at address %08lx) ...\n",
(ulong) theKernel);
- loadaddr = (uint32_t)image_get_load(os_header);
- loadsize = (uint32_t)image_get_size(os_header);
+ loadaddr = (uint32_t)ntohl(os_header->ih_load);
+ loadsize = (uint32_t)ntohl(os_header->ih_size);
setup_boot_record( (char*)(loadaddr+loadsize),(char*)commandline);
if (relocate_image(data->os, (void *)loadaddr))
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 5ee908d132..35a9d31a8e 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -45,7 +45,7 @@ static int do_bootm_linux(struct image_data *idata)
printf("entering %s: os_header: %p initrd_header: %p oftree: %s\n",
__FUNCTION__, os_header, initrd_header, idata->oftree);
- if (image_check_type(os_header, IH_TYPE_MULTI)) {
+ if (os_header->ih_type == IH_TYPE_MULTI) {
unsigned long *data = (unsigned long *)(idata->os->data);
unsigned long len1 = 0, len2 = 0;
@@ -199,9 +199,9 @@ static int do_bootm_linux(struct image_data *idata)
#endif /* CONFIG_MPC5xxx */
}
- kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep(os_header); /* FIXME */
+ kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ntohl(os_header->ih_ep); /* FIXME */
- if (relocate_image(idata->os, (void *)image_get_load(os_header)))
+ if (relocate_image(idata->os, (void *)ntohl(os_header->ih_load)))
return -1;
#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
diff --git a/commands/bootm.c b/commands/bootm.c
index 98047cda69..a64f67879d 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -98,19 +98,19 @@ fixup_silent_linux ()
int relocate_image(struct image_handle *handle, void *load_address)
{
image_header_t *hdr = &handle->header;
- unsigned long len = image_get_size(hdr);
+ unsigned long len = ntohl(hdr->ih_size);
unsigned long data = (unsigned long)(handle->data);
#if defined CONFIG_CMD_BOOTM_ZLIB || defined CONFIG_CMD_BOOTM_BZLIB
uint unc_len = CFG_BOOTM_LEN;
#endif
- switch (image_get_comp(hdr)) {
+ switch (hdr->ih_comp) {
case IH_COMP_NONE:
- if(image_get_load(hdr) == data) {
+ if(ntohl(hdr->ih_load) == data) {
printf (" XIP ... ");
} else {
- memmove ((void *) image_get_load(hdr), (uchar *)data, len);
+ memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
}
break;
#ifdef CONFIG_CMD_BOOTM_ZLIB
@@ -137,8 +137,7 @@ int relocate_image(struct image_handle *handle, void *load_address)
break;
#endif
default:
- printf("Unimplemented compression type %d\n",
- image_get_comp(hdr));
+ printf ("Unimplemented compression type %d\n", hdr->ih_comp);
return -1;
}
@@ -162,24 +161,24 @@ struct image_handle *map_image(const char *filename, int verify)
handle = xzalloc(sizeof(struct image_handle));
header = &handle->header;
- if (read(fd, header, image_get_header_size()) < 0) {
+ if (read(fd, header, sizeof(image_header_t)) < 0) {
printf("could not read: %s\n", errno_str());
goto err_out;
}
- if (image_check_magic(header)) {
+ if (ntohl(header->ih_magic) != IH_MAGIC) {
puts ("Bad Magic Number\n");
goto err_out;
}
- checksum = image_get_hcrc(header);
+ checksum = ntohl(header->ih_hcrc);
header->ih_hcrc = 0;
- if (crc32 (0, (uchar *)header, image_get_header_size()) != checksum) {
+ if (crc32 (0, (uchar *)header, sizeof(image_header_t)) != checksum) {
puts ("Bad Header Checksum\n");
goto err_out;
}
- len = image_get_size(header);
+ len = ntohl(header->ih_size);
handle->data = memmap(fd, PROT_READ);
if (handle->data == (void *)-1) {
@@ -190,13 +189,12 @@ struct image_handle *map_image(const char *filename, int verify)
goto err_out;
}
} else {
- handle->data = (void *)((unsigned long)handle->data +
- image_get_header_size());
+ handle->data = (void *)((unsigned long)handle->data + sizeof(image_header_t));
}
if (verify) {
puts (" Verifying Checksum ... ");
- if (crc32 (0, handle->data, len) != image_get_dcrc(header)) {
+ if (crc32 (0, handle->data, len) != ntohl(header->ih_dcrc)) {
printf ("Bad Data CRC\n");
goto err_out;
}
@@ -332,9 +330,8 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
os_header = &os_handle->header;
- if (image_check_arch(os_header, IH_ARCH)) {
- printf("Unsupported Architecture 0x%x\n",
- image_get_arch(os_header));
+ if (os_header->ih_arch != IH_ARCH) {
+ printf ("Unsupported Architecture 0x%x\n", os_header->ih_arch);
goto err_out;
}
@@ -350,15 +347,14 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
/* loop through the registered handlers */
list_for_each_entry(handler, &handler_list, list) {
- if (image_check_os(os_header, handler->image_type)) {
+ if (handler->image_type == os_header->ih_os) {
handler->bootm(&data);
printf("handler returned!\n");
goto err_out;
}
}
- printf("no image handler found for image type %d\n",
- image_get_os(os_header));
+ printf("no image handler found for image type %d\n", os_header->ih_os);
err_out:
if (os_handle)
@@ -407,17 +403,17 @@ static int image_info (ulong addr)
printf ("\n## Checking Image at %08lx ...\n", addr);
/* Copy header so we can blank CRC field for re-calculation */
- memmove (&header, (char *)addr, image_get_header_size());
+ memmove (&header, (char *)addr, sizeof(image_header_t));
- if (image_check_magic(hdr)) {
+ if (ntohl(hdr->ih_magic) != IH_MAGIC) {
puts (" Bad Magic Number\n");
return 1;
}
data = (ulong)&header;
- len = image_get_header_size();
+ len = sizeof(image_header_t);
- checksum = image_get_hcrc(hdr);
+ checksum = ntohl(hdr->ih_hcrc);
hdr->ih_hcrc = 0;
if (crc32 (0, (uchar *)data, len) != checksum) {
@@ -428,11 +424,11 @@ static int image_info (ulong addr)
/* for multi-file images we need the data part, too */
print_image_hdr ((image_header_t *)addr);
- data = addr + image_get_header_size();
- len = image_get_size(hdr);
+ data = addr + sizeof(image_header_t);
+ len = ntohl(hdr->ih_size);
puts (" Verifying Checksum ... ");
- if (crc32 (0, (uchar *)data, len) != image_get_dcrc(hdr)) {
+ if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
puts (" Bad Data CRC\n");
return 1;
}
@@ -455,11 +451,11 @@ void
print_image_hdr (image_header_t *hdr)
{
#if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
- time_t timestamp = (time_t)image_get_time(hdr);
+ time_t timestamp = (time_t)ntohl(hdr->ih_time);
struct rtc_time tm;
#endif
- printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name(hdr));
+ printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
#if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
to_tm (timestamp, &tm);
printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
@@ -468,27 +464,26 @@ print_image_hdr (image_header_t *hdr)
#endif /* CONFIG_CMD_DATE, CONFIG_TIMESTAMP */
#ifdef CONFIG_CMD_BOOTM_SHOW_TYPE
printf (" Image Type: %s %s %s (%s)\n",
- image_get_arch_name(image_get_arch(hdr)),
- image_get_os_name(image_get_os(hdr)),
- image_get_type_name(image_get_type(hdr)),
- image_get_comp_name(image_get_comp(hdr)));
+ image_arch(hdr->ih_arch),
+ image_os(hdr->ih_os),
+ image_type(hdr->ih_type),
+ image_compression(hdr->ih_comp));
#endif
printf (" Data Size: %d Bytes = %s\n"
" Load Address: %08x\n"
" Entry Point: %08x\n",
- image_get_size(hdr),
- size_human_readable(image_get_size(hdr)),
- image_get_load(hdr),
- image_get_ep(hdr));
+ ntohl(hdr->ih_size),
+ size_human_readable(ntohl(hdr->ih_size)),
+ ntohl(hdr->ih_load),
+ ntohl(hdr->ih_ep));
- if (image_check_type(hdr, IH_TYPE_MULTI)) {
+ if (hdr->ih_type == IH_TYPE_MULTI) {
int i;
- uint32_t len;
- uint32_t *len_ptr = (uint32_t *)((ulong)hdr + image_get_header_size());
+ ulong len;
+ ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
puts (" Contents:\n");
- for (i=0; len_ptr[i]; ++i) {
- len = ntohl(len_ptr[i]);
+ for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
printf (" Image %d: %8ld Bytes = %s", i, len,
size_human_readable (len));
}
diff --git a/common/image.c b/common/image.c
index 75346f5079..b0af2efd3e 100644
--- a/common/image.c
+++ b/common/image.c
@@ -113,22 +113,22 @@ static char *get_table_entry_name(table_entry_t *table, char *msg, int id)
return msg;
}
-const char *image_get_os_name(uint8_t os)
+const char *image_os(uint8_t os)
{
return get_table_entry_name(os_name, "Unknown OS", os);
}
-const char *image_get_arch_name(uint8_t arch)
+const char *image_arch(uint8_t arch)
{
return get_table_entry_name(arch_name, "Unknown Architecture", arch);
}
-const char *image_get_type_name(uint8_t type)
+const char *image_type(uint8_t type)
{
return get_table_entry_name(type_name, "Unknown Image", type);
}
-const char *image_get_comp_name(uint8_t comp)
+const char *image_compression(uint8_t comp)
{
return get_table_entry_name(comp_name, "Unknown Compression", comp);
}
diff --git a/include/image.h b/include/image.h
index de11bf8db2..c69178c65e 100644
--- a/include/image.h
+++ b/include/image.h
@@ -32,11 +32,6 @@
#define __IMAGE_H__
#include <linux/types.h>
-#ifdef __BAREBOX__
-#include <asm/byteorder.h>
-#include <stdio.h>
-#include <string.h>
-#endif
/*
* Operating System Codes
@@ -82,9 +77,8 @@
#define IH_ARCH_NIOS 13 /* Nios-32 */
#define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
#define IH_ARCH_NIOS2 15 /* Nios-II */
-#define IH_ARCH_BLACKFIN 16 /* Blackfin */
+#define IH_ARCH_BLACKFIN 16 /* Blackfin */
#define IH_ARCH_AVR32 17 /* AVR32 */
-#define IH_ARCH_LINUX 18 /* Linux */
#if defined(__PPC__)
#define IH_ARCH IH_ARCH_PPC
@@ -106,8 +100,6 @@
#define IH_ARCH IH_ARCH_BLACKFIN
#elif defined(__avr32__)
#define IH_ARCH IH_ARCH_AVR32
-#elif defined(CONFIG_LINUX)
-#define IH_ARCH IH_ARCH_LINUX
#endif
/*
@@ -196,185 +188,32 @@ struct image_handle {
};
#if defined(CONFIG_CMD_BOOTM_SHOW_TYPE) || !defined(__BAREBOX__)
-const char *image_get_os_name(uint8_t os);
-const char *image_get_arch_name(uint8_t arch);
-const char *image_get_type_name(uint8_t type);
-const char *image_get_comp_name(uint8_t comp);
+const char *image_os(uint8_t os);
+const char *image_arch(uint8_t arch);
+const char *image_type(uint8_t type);
+const char *image_compression(uint8_t comp);
#else
-static inline const char *image_get_os_name(uint8_t os)
+static inline const char *image_os(uint8_t os)
{
return NULL;
}
-static inline const char *image_get_arch_name(uint8_t arch)
+static inline const char *image_arch(uint8_t arch)
{
return NULL;
}
-static inline const char *image_get_type_name(uint8_t type)
+static inline const char *image_type(uint8_t type)
{
return NULL;
}
-static inline const char *image_get_comp_name(uint8_t comp)
+static inline const char *image_compression(uint8_t comp)
{
return NULL;
}
#endif
-#define uimage_to_cpu(x) be32_to_cpu(x)
-#define cpu_to_uimage(x) cpu_to_be32(x)
-
-static inline uint32_t image_get_header_size(void)
-{
- return sizeof(image_header_t);
-}
-
-#define image_get_hdr_u32(x) \
-static inline uint32_t image_get_##x(const image_header_t *hdr) \
-{ \
- return uimage_to_cpu(hdr->ih_##x); \
-}
-
-image_get_hdr_u32(magic); /* image_get_magic */
-image_get_hdr_u32(hcrc); /* image_get_hcrc */
-image_get_hdr_u32(time); /* image_get_time */
-image_get_hdr_u32(size); /* image_get_size */
-image_get_hdr_u32(load); /* image_get_load */
-image_get_hdr_u32(ep); /* image_get_ep */
-image_get_hdr_u32(dcrc); /* image_get_dcrc */
-
-#define image_get_hdr_u8(x) \
-static inline uint8_t image_get_##x(const image_header_t *hdr) \
-{ \
- return hdr->ih_##x; \
-}
-image_get_hdr_u8(os); /* image_get_os */
-image_get_hdr_u8(arch); /* image_get_arch */
-image_get_hdr_u8(type); /* image_get_type */
-image_get_hdr_u8(comp); /* image_get_comp */
-
-static inline char *image_get_name(const image_header_t *hdr)
-{
- return (char*)hdr->ih_name;
-}
-
-static inline uint32_t image_get_data_size(const image_header_t *hdr)
-{
- return image_get_size(hdr);
-}
-
-/**
- * image_get_data - get image payload start address
- * @hdr: image header
- *
- * image_get_data() returns address of the image payload. For single
- * component images it is image data start. For multi component
- * images it points to the null terminated table of sub-images sizes.
- *
- * returns:
- * image payload data start address
- */
-static inline ulong image_get_data(const image_header_t *hdr)
-{
- return ((ulong)hdr + image_get_header_size());
-}
-
-static inline uint32_t image_get_image_size(const image_header_t *hdr)
-{
- return (image_get_size(hdr) + image_get_header_size());
-}
-
-static inline ulong image_get_image_end(const image_header_t *hdr)
-{
- return ((ulong)hdr + image_get_image_size(hdr));
-}
-
-#define image_set_hdr_u32(x) \
-static inline void image_set_##x(image_header_t *hdr, uint32_t val) \
-{ \
- hdr->ih_##x = cpu_to_uimage(val); \
-}
-
-image_set_hdr_u32(magic); /* image_set_magic */
-image_set_hdr_u32(hcrc); /* image_set_hcrc */
-image_set_hdr_u32(time); /* image_set_time */
-image_set_hdr_u32(size); /* image_set_size */
-image_set_hdr_u32(load); /* image_set_load */
-image_set_hdr_u32(ep); /* image_set_ep */
-image_set_hdr_u32(dcrc); /* image_set_dcrc */
-
-#define image_set_hdr_u8(x) \
-static inline void image_set_##x(image_header_t *hdr, uint8_t val) \
-{ \
- hdr->ih_##x = val; \
-}
-
-image_set_hdr_u8(os); /* image_set_os */
-image_set_hdr_u8(arch); /* image_set_arch */
-image_set_hdr_u8(type); /* image_set_type */
-image_set_hdr_u8(comp); /* image_set_comp */
-
-static inline void image_set_name(image_header_t *hdr, const char *name)
-{
- strncpy(image_get_name(hdr), name, IH_NMLEN);
-}
-
-static inline int image_check_magic(const image_header_t *hdr)
-{
- return (image_get_magic(hdr) == IH_MAGIC);
-}
-static inline int image_check_type(const image_header_t *hdr, uint8_t type)
-{
- return (image_get_type(hdr) == type);
-}
-static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
-{
- return (image_get_arch(hdr) == arch);
-}
-static inline int image_check_os(const image_header_t *hdr, uint8_t os)
-{
- return (image_get_os(hdr) == os);
-}
-
-#ifdef __BAREBOX__
-static inline int image_check_target_arch(const image_header_t *hdr)
-{
-#if defined(__ARM__)
- if (!image_check_arch(hdr, IH_ARCH_ARM))
-#elif defined(__avr32__)
- if (!image_check_arch(hdr, IH_ARCH_AVR32))
-#elif defined(__bfin__)
- if (!image_check_arch(hdr, IH_ARCH_BLACKFIN))
-#elif defined(__I386__)
- if (!image_check_arch(hdr, IH_ARCH_I386))
-#elif defined(__m68k__)
- if (!image_check_arch(hdr, IH_ARCH_M68K))
-#elif defined(__microblaze__)
- if (!image_check_arch(hdr, IH_ARCH_MICROBLAZE))
-#elif defined(__mips__)
- if (!image_check_arch(hdr, IH_ARCH_MIPS))
-#elif defined(__nios__)
- if (!image_check_arch(hdr, IH_ARCH_NIOS))
-#elif defined(__nios2__)
- if (!image_check_arch(hdr, IH_ARCH_NIOS2))
-#elif defined(__PPC__)
- if (!image_check_arch(hdr, IH_ARCH_PPC))
-#elif defined(__sh__)
- if (!image_check_arch(hdr, IH_ARCH_SH))
-#elif defined(__sparc__)
- if (!image_check_arch(hdr, IH_ARCH_SPARC))
-#elif defined(CONFIG_LINUX)
- if (!image_check_arch(hdr, IH_ARCH_LINUX))
-#else
-# error Unknown CPU type
-#endif
- return 0;
-
- return 1;
-}
-#endif /* USE_HOSTCC */
-
/* commamds/bootm.c */
void print_image_hdr (image_header_t *hdr);
diff --git a/scripts/mkimage.c b/scripts/mkimage.c
index fef82c6c9e..aac722008f 100644
--- a/scripts/mkimage.c
+++ b/scripts/mkimage.c
@@ -224,7 +224,7 @@ NXTARG: ;
*/
memcpy (hdr, ptr, sizeof(image_header_t));
- if (image_check_magic(hdr)) {
+ if (ntohl(hdr->ih_magic) != IH_MAGIC) {
fprintf (stderr,
"%s: Bad Magic Number: \"%s\" is no valid image\n",
cmdname, imagefile);
@@ -232,10 +232,10 @@ NXTARG: ;
}
data = (char *)hdr;
- len = image_get_header_size();
+ len = sizeof(image_header_t);
- checksum = image_get_hcrc(hdr);
- image_set_hcrc(hdr, 0); /* clear for re-calculation */
+ checksum = ntohl(hdr->ih_hcrc);
+ hdr->ih_hcrc = htonl(0); /* clear for re-calculation */
if (crc32 (0, (unsigned char *)data, len) != checksum) {
fprintf (stderr,
@@ -244,10 +244,10 @@ NXTARG: ;
exit (EXIT_FAILURE);
}
- data = (char *)(ptr + image_get_header_size());
- len = sbuf.st_size - image_get_header_size() ;
+ data = (char *)(ptr + sizeof(image_header_t));
+ len = sbuf.st_size - sizeof(image_header_t) ;
- if (crc32 (0, (unsigned char *)data, len) != image_get_dcrc(hdr)) {
+ if (crc32 (0, (unsigned char *)data, len) != ntohl(hdr->ih_dcrc)) {
fprintf (stderr,
"%s: ERROR: \"%s\" has corrupted data!\n",
cmdname, imagefile);
@@ -268,16 +268,15 @@ NXTARG: ;
*
* write dummy header, to be fixed later
*/
- memset (hdr, 0, image_get_header_size());
+ memset (hdr, 0, sizeof(image_header_t));
- if (write(ifd, hdr, image_get_header_size()) != image_get_header_size()) {
+ if (write(ifd, hdr, sizeof(image_header_t)) != sizeof(image_header_t)) {
fprintf (stderr, "%s: Write error on %s: %s\n",
cmdname, imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
- if ((opt_type == IH_TYPE_MULTI) ||
- (opt_type == IH_TYPE_SCRIPT)) {
+ if (opt_type == IH_TYPE_MULTI || opt_type == IH_TYPE_SCRIPT) {
char *file = datafile;
uint32_t size;
@@ -359,27 +358,27 @@ NXTARG: ;
hdr = (image_header_t *)ptr;
checksum = crc32 (0,
- (unsigned char *)(ptr + image_get_header_size()),
- sbuf.st_size - image_get_header_size()
+ (unsigned char *)(ptr + sizeof(image_header_t)),
+ sbuf.st_size - sizeof(image_header_t)
);
/* Build new header */
- image_set_magic(hdr, IH_MAGIC);
- image_set_time(hdr, sbuf.st_mtime);
- image_set_size(hdr, sbuf.st_size - image_get_header_size());
- image_set_load(hdr, addr);
- image_set_ep(hdr, ep);
- image_set_dcrc(hdr, checksum);
- image_set_os(hdr, opt_os);
- image_set_arch(hdr, opt_arch);
- image_set_type(hdr, opt_type);
- image_set_comp(hdr, opt_comp);
+ hdr->ih_magic = htonl(IH_MAGIC);
+ hdr->ih_time = htonl(sbuf.st_mtime);
+ hdr->ih_size = htonl(sbuf.st_size - sizeof(image_header_t));
+ hdr->ih_load = htonl(addr);
+ hdr->ih_ep = htonl(ep);
+ hdr->ih_dcrc = htonl(checksum);
+ hdr->ih_os = opt_os;
+ hdr->ih_arch = opt_arch;
+ hdr->ih_type = opt_type;
+ hdr->ih_comp = opt_comp;
- image_set_name(hdr, name);
+ strncpy((char *)hdr->ih_name, name, IH_NMLEN);
- checksum = crc32(0,(unsigned char *)hdr, image_get_header_size());
+ checksum = crc32(0,(unsigned char *)hdr,sizeof(image_header_t));
- image_set_hcrc(hdr, checksum);
+ hdr->ih_hcrc = htonl(checksum);
print_header (hdr);
@@ -444,14 +443,14 @@ copy_file (int ifd, const char *datafile, int pad)
* reserved for it.
*/
- if ((unsigned)sbuf.st_size < image_get_header_size()) {
+ if ((unsigned)sbuf.st_size < sizeof(image_header_t)) {
fprintf (stderr,
"%s: Bad size: \"%s\" is too small for XIP\n",
cmdname, datafile);
exit (EXIT_FAILURE);
}
- for (p = ptr; p < ptr + image_get_header_size(); p++) {
+ for (p=ptr; p < ptr+sizeof(image_header_t); p++) {
if ( *p != 0xff ) {
fprintf (stderr,
"%s: Bad file: \"%s\" has invalid buffer for XIP\n",
@@ -460,7 +459,7 @@ copy_file (int ifd, const char *datafile, int pad)
}
}
- offset = image_get_header_size();
+ offset = sizeof(image_header_t);
}
size = sbuf.st_size - offset;
@@ -510,23 +509,22 @@ print_header (image_header_t *hdr)
time_t timestamp;
uint32_t size;
- timestamp = (time_t)image_get_time(hdr);
- size = image_get_size(hdr);
+ timestamp = (time_t)ntohl(hdr->ih_time);
+ size = ntohl(hdr->ih_size);
- printf ("Image Name: %.*s\n", IH_NMLEN, image_get_name(hdr));
+ printf ("Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
printf ("Created: %s", ctime(&timestamp));
printf ("Image Type: "); print_type(hdr);
printf ("Data Size: %d Bytes = %.2f kB = %.2f MB\n",
size, (double)size / 1.024e3, (double)size / 1.048576e6 );
- printf ("Load Address: 0x%08X\n", image_get_load(hdr));
- printf ("Entry Point: 0x%08X\n", image_get_ep(hdr));
+ printf ("Load Address: 0x%08X\n", ntohl(hdr->ih_load));
+ printf ("Entry Point: 0x%08X\n", ntohl(hdr->ih_ep));
- if (image_check_type(hdr, IH_TYPE_MULTI) ||
- image_check_type(hdr, IH_TYPE_SCRIPT)) {
+ if (hdr->ih_type == IH_TYPE_MULTI || hdr->ih_type == IH_TYPE_SCRIPT) {
int i, ptrs;
uint32_t pos;
uint32_t *len_ptr = (uint32_t *) (
- (unsigned long)hdr + image_get_header_size()
+ (unsigned long)hdr + sizeof(image_header_t)
);
/* determine number of images first (to calculate image offsets) */
@@ -534,14 +532,14 @@ print_header (image_header_t *hdr)
;
ptrs = i; /* null pointer terminates list */
- pos = image_get_header_size() + ptrs * sizeof(long);
+ pos = sizeof(image_header_t) + ptrs * sizeof(long);
printf ("Contents:\n");
for (i=0; len_ptr[i]; ++i) {
size = ntohl(len_ptr[i]);
printf (" Image %d: %8d Bytes = %4d kB = %d MB\n",
i, size, size>>10, size>>20);
- if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) {
+ if (hdr->ih_type == IH_TYPE_SCRIPT && i > 0) {
/*
* the user may need to know offsets
* if planning to do something with
@@ -562,10 +560,10 @@ static void
print_type (image_header_t *hdr)
{
printf ("%s %s %s (%s)\n",
- image_get_arch_name(image_get_arch(hdr)),
- image_get_os_name(image_get_os(hdr)),
- image_get_type_name(image_get_type(hdr)),
- image_get_comp_name(image_get_comp(hdr))
+ image_arch(hdr->ih_arch),
+ image_os(hdr->ih_os),
+ image_type(hdr->ih_type),
+ image_compression(hdr->ih_comp)
);
}