diff options
Diffstat (limited to 'common/imd.c')
-rw-r--r-- | common/imd.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/common/imd.c b/common/imd.c index 96496514a5..1100e6878a 100644 --- a/common/imd.c +++ b/common/imd.c @@ -1,16 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright 2014 Sascha Hauer, Pengutronix - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * 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. - * */ #ifdef __BAREBOX__ #include <common.h> @@ -27,6 +17,16 @@ int imd_command_setenv(const char *variable_name, const char *value) return -ENOSYS; } #endif +static inline void read_file_2_free(void *buf) +{ + free(buf); +} + +static int imd_read_file(const char *filename, size_t *size, void **outbuf, + bool allow_mmap) +{ + return read_file_2(filename, size, outbuf, 0x100000); +} #endif /* @@ -168,6 +168,9 @@ static struct imd_type_names imd_types[] = { }, { .type = IMD_TYPE_CRC32, .name = "crc32", + }, { + .type = IMD_TYPE_BUILDSYSTEM, + .name = "buildsystem version", }, }; @@ -312,6 +315,7 @@ static int imd_calculate_crc32(void *input, const struct imd_header *imd_start, const struct imd_header *imd; int length; int end_ofs = (char *)imd_start - (char *)input + sizeof(char) * 8; + *imd_crc = NULL; /* search the checksum imd token */ imd_for_each(imd_start, imd) { @@ -319,7 +323,7 @@ static int imd_calculate_crc32(void *input, const struct imd_header *imd_start, length = ALIGN(length, 4); length += sizeof(struct imd_header); - if (imd_read_type(imd) == IMD_TYPE_CRC32) { + if (imd_is_crc32(imd_read_type(imd))) { *imd_crc = (struct imd_header *)imd; debug("Found crc token at %d\n", end_ofs); break; @@ -412,7 +416,7 @@ int imd_verify_crc32(void *buf, size_t size) *p, crc); return -EILSEQ; } else if (*p != crc && !imd_crc32_is_valid(*flags)) { - printf("CRC: is invalid, but the checksum tag is not enabled\n"); + debug("CRC: is invalid, but the checksum tag is not enabled\n"); return -EINVAL; } else { printf("CRC: valid\n"); @@ -436,6 +440,7 @@ int imd_command(int argc, char *argv[]) char *str; uint32_t checksum = 0; uint32_t verify = 0; + bool allow_mmap = true; imd_command_verbose = 0; @@ -459,6 +464,7 @@ int imd_command(int argc, char *argv[]) break; case 'c': checksum = 1; + allow_mmap = false; break; case 'V': verify = 1; @@ -475,7 +481,7 @@ int imd_command(int argc, char *argv[]) filename = argv[optind]; - ret = read_file_2(filename, &size, &buf, 0x100000); + ret = imd_read_file(filename, &size, &buf, allow_mmap); if (ret && ret != -EFBIG) return -errno; @@ -485,10 +491,15 @@ int imd_command(int argc, char *argv[]) goto out; } - if (checksum) - imd_write_crc32(buf, imd_start, filename, size); - if (verify) - imd_verify_crc32(buf, size); + if (checksum) { + ret = imd_write_crc32(buf, imd_start, filename, size); + goto out; + } + + if (verify) { + ret = imd_verify_crc32(buf, size); + goto out; + } if (type == IMD_TYPE_INVALID) { imd_for_each(imd_start, imd) { @@ -543,6 +554,6 @@ int imd_command(int argc, char *argv[]) ret = 0; out: - free(buf); + read_file_2_free(buf); return ret; } |