diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2010-09-23 21:32:19 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-09-24 08:46:22 +0200 |
commit | 0ceafe14be072696eff3e549d8c7b7de8a3e416d (patch) | |
tree | c0ea8344342f23ab546e26a78753452075294619 /scripts | |
parent | aba80a2d2d0f1b25185246925577ce2108247dde (diff) | |
download | barebox-0ceafe14be072696eff3e549d8c7b7de8a3e416d.tar.gz barebox-0ceafe14be072696eff3e549d8c7b7de8a3e416d.tar.xz |
Replace direct header access with the API routines
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/mkimage.c | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/scripts/mkimage.c b/scripts/mkimage.c index 561dc84372..6cbf80e8c9 100644 --- a/scripts/mkimage.c +++ b/scripts/mkimage.c @@ -260,7 +260,7 @@ NXTARG: ; */ memcpy (hdr, ptr, sizeof(image_header_t)); - if (ntohl(hdr->ih_magic) != IH_MAGIC) { + if (image_check_magic(hdr)) { fprintf (stderr, "%s: Bad Magic Number: \"%s\" is no valid image\n", cmdname, imagefile); @@ -268,10 +268,10 @@ NXTARG: ; } data = (char *)hdr; - len = sizeof(image_header_t); + len = image_get_header_size(); - checksum = ntohl(hdr->ih_hcrc); - hdr->ih_hcrc = htonl(0); /* clear for re-calculation */ + checksum = image_get_hcrc(hdr); + image_set_hcrc(hdr, 0); /* clear for re-calculation */ if (crc32 (0, (unsigned char *)data, len) != checksum) { fprintf (stderr, @@ -280,10 +280,10 @@ NXTARG: ; exit (EXIT_FAILURE); } - data = (char *)(ptr + sizeof(image_header_t)); - len = sbuf.st_size - sizeof(image_header_t) ; + data = (char *)(ptr + image_get_header_size()); + len = sbuf.st_size - image_get_header_size() ; - if (crc32 (0, (unsigned char *)data, len) != ntohl(hdr->ih_dcrc)) { + if (crc32 (0, (unsigned char *)data, len) != image_get_dcrc(hdr)) { fprintf (stderr, "%s: ERROR: \"%s\" has corrupted data!\n", cmdname, imagefile); @@ -304,15 +304,16 @@ NXTARG: ; * * write dummy header, to be fixed later */ - memset (hdr, 0, sizeof(image_header_t)); + memset (hdr, 0, image_get_header_size()); - if (write(ifd, hdr, sizeof(image_header_t)) != sizeof(image_header_t)) { + if (write(ifd, hdr, image_get_header_size()) != image_get_header_size()) { 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; @@ -394,27 +395,27 @@ NXTARG: ; hdr = (image_header_t *)ptr; checksum = crc32 (0, - (unsigned char *)(ptr + sizeof(image_header_t)), - sbuf.st_size - sizeof(image_header_t) + (unsigned char *)(ptr + image_get_header_size()), + sbuf.st_size - image_get_header_size() ); /* Build new header */ - 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_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); - strncpy((char *)hdr->ih_name, name, IH_NMLEN); + image_set_name(hdr, name); - checksum = crc32(0,(unsigned char *)hdr,sizeof(image_header_t)); + checksum = crc32(0,(unsigned char *)hdr, image_get_header_size()); - hdr->ih_hcrc = htonl(checksum); + image_set_hcrc(hdr, checksum); print_header (hdr); @@ -479,14 +480,14 @@ copy_file (int ifd, const char *datafile, int pad) * reserved for it. */ - if ((unsigned)sbuf.st_size < sizeof(image_header_t)) { + if ((unsigned)sbuf.st_size < image_get_header_size()) { fprintf (stderr, "%s: Bad size: \"%s\" is too small for XIP\n", cmdname, datafile); exit (EXIT_FAILURE); } - for (p=ptr; p < ptr+sizeof(image_header_t); p++) { + for (p = ptr; p < ptr + image_get_header_size(); p++) { if ( *p != 0xff ) { fprintf (stderr, "%s: Bad file: \"%s\" has invalid buffer for XIP\n", @@ -495,7 +496,7 @@ copy_file (int ifd, const char *datafile, int pad) } } - offset = sizeof(image_header_t); + offset = image_get_header_size(); } size = sbuf.st_size - offset; @@ -545,22 +546,23 @@ print_header (image_header_t *hdr) time_t timestamp; uint32_t size; - timestamp = (time_t)ntohl(hdr->ih_time); - size = ntohl(hdr->ih_size); + timestamp = (time_t)image_get_time(hdr); + size = image_get_size(hdr); - printf ("Image Name: %.*s\n", IH_NMLEN, hdr->ih_name); + printf ("Image Name: %.*s\n", IH_NMLEN, image_get_name(hdr)); printf ("Created: %s", ctime(×tamp)); 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", ntohl(hdr->ih_load)); - printf ("Entry Point: 0x%08X\n", ntohl(hdr->ih_ep)); + printf ("Load Address: 0x%08X\n", image_get_load(hdr)); + printf ("Entry Point: 0x%08X\n", image_get_ep(hdr)); - if (hdr->ih_type == IH_TYPE_MULTI || hdr->ih_type == IH_TYPE_SCRIPT) { + if (image_check_type(hdr, IH_TYPE_MULTI) || + image_check_type(hdr, IH_TYPE_SCRIPT)) { int i, ptrs; uint32_t pos; uint32_t *len_ptr = (uint32_t *) ( - (unsigned long)hdr + sizeof(image_header_t) + (unsigned long)hdr + image_get_header_size() ); /* determine number of images first (to calculate image offsets) */ @@ -568,14 +570,14 @@ print_header (image_header_t *hdr) ; ptrs = i; /* null pointer terminates list */ - pos = sizeof(image_header_t) + ptrs * sizeof(long); + pos = image_get_header_size() + 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 (hdr->ih_type == IH_TYPE_SCRIPT && i > 0) { + if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) { /* * the user may need to know offsets * if planning to do something with @@ -596,10 +598,10 @@ static void print_type (image_header_t *hdr) { printf ("%s %s %s (%s)\n", - image_arch(hdr->ih_arch), - image_os(hdr->ih_os), - image_type(hdr->ih_type), - image_compression(hdr->ih_comp) + 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)) ); } |