diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-12-06 08:23:24 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-12-06 08:23:24 +0100 |
commit | e9ea6eeaabb15258dbeefe06a421fca8c2fe9baa (patch) | |
tree | 075fbf70c17a50190c3fb290eb6b362177f0d1e5 /scripts | |
parent | 18aa86831ed72380b7c2edba3c27bbf7a999da76 (diff) | |
parent | 1e7f2bd25c28b36c7c40ed4797b2a21cc4e1502e (diff) | |
download | barebox-e9ea6eeaabb15258dbeefe06a421fca8c2fe9baa.tar.gz barebox-e9ea6eeaabb15258dbeefe06a421fca8c2fe9baa.tar.xz |
Merge branch 'for-next/misc'
Conflicts:
scripts/Makefile
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/.gitignore | 2 | ||||
-rw-r--r-- | scripts/Makefile | 2 | ||||
-rw-r--r-- | scripts/bareboxcrc32.c | 60 | ||||
-rw-r--r-- | scripts/bareboxenv.c | 19 | ||||
-rw-r--r-- | scripts/compiler.h | 25 | ||||
-rw-r--r-- | scripts/imx/imx-usb-loader.c | 8 | ||||
-rw-r--r-- | scripts/kwbimage.c | 16 | ||||
-rw-r--r-- | scripts/kwboot.c | 1 |
8 files changed, 107 insertions, 26 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore index b88f8d8661..fac394d128 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -10,3 +10,5 @@ mkublheader omap_signGP zynq_mkimage socfpga_mkimage +bareboxcrc32 +bareboxcrc32-target diff --git a/scripts/Makefile b/scripts/Makefile index 2f78c4bb64..3908c1dcb9 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -8,6 +8,7 @@ hostprogs-y += bin2c hostprogs-y += mkimage hostprogs-y += fix_size hostprogs-y += bareboxenv +hostprogs-y += bareboxcrc32 hostprogs-y += kernel-install hostprogs-$(CONFIG_KALLSYMS) += kallsyms hostprogs-$(CONFIG_ARCH_MVEBU) += kwbimage kwboot @@ -26,6 +27,7 @@ subdir-$(CONFIG_DTC) += dtc targetprogs-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target targetprogs-$(CONFIG_KERNEL_INSTALL_TARGET) += kernel-install-target +targetprogs-$(CONFIG_BAREBOXCRC32_TARGET) += bareboxcrc32-target # Let clean descend into subdirs subdir- += basic kconfig setupmbr diff --git a/scripts/bareboxcrc32.c b/scripts/bareboxcrc32.c new file mode 100644 index 0000000000..e00ffafeb7 --- /dev/null +++ b/scripts/bareboxcrc32.c @@ -0,0 +1,60 @@ +/* + * bareboxcrc32.c - generate crc32 checksum in little endian + * + * Copyright (c) 2013 Michael Grzeschik <mgr@pengutronix.de> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdint.h> +#include <limits.h> +#include <errno.h> +#include <dirent.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> +#include <libgen.h> + +#include "compiler.h" + +#define debug(...) + +#include "../crypto/crc32.c" + +int main(int argc, char *argv[]) +{ + loff_t start = 0, size = ~0; + ulong crc = 0, total = 0; + char *filename = NULL; + int i; + + if (!filename && argc < 2) { + printf("usage: %s filename\n", argv[0]); + exit(1); + } + + for (i = 1; i < argc; i++) { + filename = argv[i]; + if (file_crc(filename, start, size, &crc, &total) < 0) + exit(1); + printf("%08lx\t%s\n", crc, filename); + } + + exit(0); + +} diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c index f372685ae7..da420db578 100644 --- a/scripts/bareboxenv.c +++ b/scripts/bareboxenv.c @@ -35,25 +35,6 @@ #define debug(...) -static void *xmalloc(size_t size) -{ - void *p = NULL; - - if (!(p = malloc(size))) { - printf("ERROR: out of memory\n"); - exit(1); - } - - return p; -} - -static void *xzalloc(size_t size) -{ - void *p = xmalloc(size); - memset(p, 0, size); - return p; -} - /* Find out if the last character of a string matches the one given. * Don't underrun the buffer if the string length is 0. */ diff --git a/scripts/compiler.h b/scripts/compiler.h index 53f84b6d1b..0891c3bfa6 100644 --- a/scripts/compiler.h +++ b/scripts/compiler.h @@ -107,4 +107,29 @@ typedef uint32_t __u32; # define be64_to_cpu(x) (x) #endif +#define min(x, y) ({ \ + typeof(x) _min1 = (x); \ + typeof(y) _min2 = (y); \ + (void) (&_min1 == &_min2); \ + _min1 < _min2 ? _min1 : _min2; }) + +inline void *xmalloc(size_t size) +{ + void *p = NULL; + + if (!(p = malloc(size))) { + printf("ERROR: out of memory\n"); + exit(1); + } + + return p; +} + +inline void *xzalloc(size_t size) +{ + void *p = xmalloc(size); + memset(p, 0, size); + return p; +} + #endif diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c index 81c0640bee..12a89f5825 100644 --- a/scripts/imx/imx-usb-loader.c +++ b/scripts/imx/imx-usb-loader.c @@ -326,7 +326,7 @@ static int transfer(struct libusb_device_handle *h, int report, unsigned char *p memcpy(p, &tmp[1], *last_trans); } } else { - printf("Unexpected report %i err=%i, cnt=%i, last_trans=%i, %02x %02x %02x %02x\n", + printf("Unexpected report %i err=%i, cnt=%u, last_trans=%i, %02x %02x %02x %02x\n", tmp[0], err, cnt, *last_trans, tmp[0], tmp[1], tmp[2], tmp[3]); err = 0; } @@ -475,7 +475,7 @@ static int read_memory(struct libusb_device_handle *h, struct usb_id *p_id, tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0; err = transfer(h, 4, tmp, 64, &last_trans, p_id); if (err) { - printf("r4 in err=%i, last_trans=%i %02x %02x %02x %02x cnt=%d rem=%d\n", + printf("r4 in err=%i, last_trans=%i %02x %02x %02x %02x cnt=%u rem=%d\n", err, last_trans, tmp[0], tmp[1], tmp[2], tmp[3], cnt, rem); break; } @@ -483,7 +483,7 @@ static int read_memory(struct libusb_device_handle *h, struct usb_id *p_id, if ((last_trans == 64) && (cnt == rem)) { /* Last transfer is expected to be too large for HID */ } else { - printf("err: %02x %02x %02x %02x cnt=%d rem=%d last_trans=%i\n", + printf("err: %02x %02x %02x %02x cnt=%u rem=%d last_trans=%i\n", tmp[0], tmp[1], tmp[2], tmp[3], cnt, rem, last_trans); } last_trans = rem; @@ -1247,7 +1247,7 @@ static int do_irom_download(struct libusb_device_handle *h, struct usb_id *p_id, } } - printf("loading binary file(%s) to %08x, skip=0x%x, fsize=%d type=%d...\n", + printf("loading binary file(%s) to %08x, skip=0x%x, fsize=%u type=%d...\n", curr->filename, dladdr, skip, fsize, type); ret = load_file(h, p_id, p, cnt, buf, BUF_SIZE, diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c index 4ebb07fe22..82cf21c4c8 100644 --- a/scripts/kwbimage.c +++ b/scripts/kwbimage.c @@ -685,6 +685,7 @@ static int image_create_payload(void *payload_start, size_t payloadsz, const char *payload_filename) { FILE *payload; + struct stat s; uint32_t *payload_checksum = (uint32_t *) (payload_start + payloadsz); int ret; @@ -696,7 +697,14 @@ static int image_create_payload(void *payload_start, size_t payloadsz, return -1; } - ret = fread(payload_start, payloadsz, 1, payload); + ret = stat(payload_filename, &s); + if (ret < 0) { + fprintf(stderr, "Cannot stat payload file %s\n", + payload_filename); + return ret; + } + + ret = fread(payload_start, s.st_size, 1, payload); if (ret != 1) { fprintf(stderr, "Cannot read payload file %s\n", payload_filename); @@ -747,7 +755,8 @@ static void *image_create_v0(struct image_cfg_element *image_cfg, return NULL; } - payloadsz = s.st_size; + /* payload size must be multiple of 32b */ + payloadsz = 4 * ((s.st_size + 3)/4); } /* Headers, payload and 32-bits checksum */ @@ -875,7 +884,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg, return NULL; } - payloadsz = s.st_size; + /* payload size must be multiple of 32b */ + payloadsz = 4 * ((s.st_size + 3)/4); } /* The payload should be aligned on some reasonable diff --git a/scripts/kwboot.c b/scripts/kwboot.c index 33c94b3a8b..81da3e81bc 100644 --- a/scripts/kwboot.c +++ b/scripts/kwboot.c @@ -334,6 +334,7 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data, size_t n; int i; + block->soh = SOH; block->pnum = pnum; block->_pnum = ~block->pnum; |