summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Grzeschik <m.grzeschik@pengutronix.de>2013-12-04 00:06:38 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-12-04 17:17:06 +0100
commit1e7f2bd25c28b36c7c40ed4797b2a21cc4e1502e (patch)
treec9e17a96d29046e033c37e0341570cc9501012da /commands
parenta83f635fb2a069c91693ebd15f336fa04e1b7204 (diff)
downloadbarebox-1e7f2bd25c28b36c7c40ed4797b2a21cc4e1502e.tar.gz
barebox-1e7f2bd25c28b36c7c40ed4797b2a21cc4e1502e.tar.xz
scripts: bareboxcrc32 as host and target userspacetool
This patch adds the crc32 command to be build as host and optionally as target tool. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/crc.c63
1 files changed, 4 insertions, 59 deletions
diff --git a/commands/crc.c b/commands/crc.c
index ee8dacff0b..824dda4c7d 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -21,66 +21,8 @@
#include <command.h>
#include <fs.h>
#include <getopt.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <xfuncs.h>
#include <malloc.h>
-#include <linux/ctype.h>
-
-static int file_crc(char* filename, ulong start, ulong size, ulong *crc,
- ulong *total)
-{
- int fd, now;
- int ret = 0;
- char *buf;
-
- *total = 0;
- *crc = 0;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- printf("open %s: %s\n", filename, errno_str());
- return fd;
- }
-
- if (start > 0) {
- off_t lseek_ret;
- errno = 0;
- lseek_ret = lseek(fd, start, SEEK_SET);
- if (lseek_ret == (off_t)-1 && errno) {
- perror("lseek");
- ret = -1;
- goto out;
- }
- }
-
- buf = xmalloc(4096);
-
- while (size) {
- now = min((ulong)4096, size);
- now = read(fd, buf, now);
- if (now < 0) {
- ret = now;
- perror("read");
- goto out_free;
- }
- if (!now)
- break;
- *crc = crc32(*crc, buf, now);
- size -= now;
- *total += now;
- }
-
- printf ("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
- filename, start, start + *total - 1, *crc);
-
-out_free:
- free(buf);
-out:
- close(fd);
-
- return ret;
-}
+#include <environment.h>
static int crc_from_file(const char* file, ulong *crc)
{
@@ -143,6 +85,9 @@ static int do_crc(int argc, char *argv[])
if (file_crc(filename, start, size, &crc, &total) < 0)
return 1;
+ printf("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
+ filename, (ulong)start, (ulong)start + total - 1, crc);
+
#ifdef CONFIG_CMD_CRC_CMP
if (vfilename) {
size = total;