summaryrefslogtreecommitdiffstats
path: root/crypto
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 /crypto
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 'crypto')
-rw-r--r--crypto/crc32.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/crypto/crc32.c b/crypto/crc32.c
index 275edb4c52..e7b1bd76b6 100644
--- a/crypto/crc32.c
+++ b/crypto/crc32.c
@@ -10,6 +10,12 @@
#ifdef __BAREBOX__ /* Shut down "ANSI does not permit..." warnings */
#include <common.h>
+#include <xfuncs.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <linux/ctype.h>
+#include <errno.h>
#endif
#ifdef CONFIG_DYNAMIC_CRC_TABLE
@@ -178,3 +184,57 @@ uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len)
return crc;
}
+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, strerror(errno));
+ 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;
+ }
+
+out_free:
+ free(buf);
+out:
+ close(fd);
+
+ return ret;
+}
+#ifdef __BAREBOX__
+EXPORT_SYMBOL(file_crc);
+#endif