From e1a400a031b99f54f45d017cf2658d332974c73b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 20 Nov 2012 11:14:57 +0100 Subject: mkubootenv: Implement -n commandline option to disable CRC32 generation --- mkubootenv/mkubootenv.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'mkubootenv') diff --git a/mkubootenv/mkubootenv.c b/mkubootenv/mkubootenv.c index 8e49cbb..26b5334 100644 --- a/mkubootenv/mkubootenv.c +++ b/mkubootenv/mkubootenv.c @@ -11,8 +11,8 @@ * * The environment is preceeded by a 32 bit CRC over the data part. * - * Copyright (c) 2009, Zurich University of Applied Sciences - * Copyright (c) 2009, Tobias Klauser + * Copyright (c) 2009-2012, Zurich University of Applied Sciences + * Copyright (c) 2009-2012, Tobias Klauser * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -154,10 +154,9 @@ static void uboot_env_cleanup_file(struct file *f) close(f->fd); } -static void uboot_env_to_img(struct file *s, struct file *t) +static void uboot_env_to_img(struct file *s, struct file *t, bool do_crc) { uint8_t *p, *q, *end; - uint32_t *crc; dbg("source file (env): %s\n", s->name); dbg("target image file (bin): %s\n", t->name); @@ -179,8 +178,10 @@ static void uboot_env_to_img(struct file *s, struct file *t) *p = 0; /* now for the real CRC32 */ - crc = (uint32_t *) t->ptr; - *crc = crc32(0, t->ptr + CRC32_SIZE, t->size - CRC32_SIZE); + if (do_crc) { + uint32_t *crc = (uint32_t *) t->ptr; + *crc = crc32(0, t->ptr + CRC32_SIZE, t->size - CRC32_SIZE); + } } static void uboot_img_to_env(struct file *s, struct file *t) @@ -206,10 +207,12 @@ static void uboot_img_to_env(struct file *s, struct file *t) static void usage_and_exit(int status) { printf("usage: mkubootenv [-s ] \n" - " -s set size of the target image file to bytes. If is\n" + " -s Set size of the target image file to bytes. If is\n" " bigger than the source file, the target image gets padded with null\n" " bytes. If is smaller than the source file, an error is emitted.\n" - " -r reverse operation: get plaintext env file (target) from binary image\n" + " -n Disable CRC32 calculation. The CRC32 of the generated image will be\n" + " filled with zeros. This option is ignored in reverse mode.\n" + " -r Reverse operation: get plaintext env file (target) from binary image\n" " file (source)\n"); exit(status); } @@ -220,6 +223,7 @@ int main(int argc, char **argv) int status = EXIT_FAILURE; ssize_t img_size = -1; bool reverse = false; + bool do_crc = true; struct file s, t; /* source and target file */ if (argc < 2) @@ -247,6 +251,9 @@ int main(int argc, char **argv) case 'r': reverse = true; break; + case 'n': + do_crc = false; + break; case 'h': status = EXIT_SUCCESS; /* fall through */ @@ -295,7 +302,7 @@ int main(int argc, char **argv) if (uboot_env_prepare_target(&t)) goto cleanup_source; - uboot_env_to_img(&s, &t); + uboot_env_to_img(&s, &t, do_crc); } else { uint8_t *p; uint8_t *end; -- cgit v1.2.3-54-g00ecf