* [PATCH v3 1/2] Fix the error reporting of get_bct_size_from_image() and read_bct_file()
@ 2015-12-08 14:32 Alban Bedel
[not found] ` <1449585133-9384-1-git-send-email-alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Alban Bedel @ 2015-12-08 14:32 UTC (permalink / raw)
To: linux-tegra-u79uwXL29TY76Z2rM5mHXA; +Cc: Alban Bedel
get_bct_size_from_image() and read_bct_file() should return negative
error codes, so add the missing minus signs. Also fix the return value
check on get_bct_size_from_image(), a negative value indicate an error
not zero.
Signed-off-by: Alban Bedel <alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
---
Changelog:
v2: * Fixed the same bug in read_bct_file()
---
src/cbootimage.c | 2 +-
src/data_layout.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cbootimage.c b/src/cbootimage.c
index da1d1a5..fc99af2 100644
--- a/src/cbootimage.c
+++ b/src/cbootimage.c
@@ -239,7 +239,7 @@ main(int argc, char *argv[])
/* Get BCT_SIZE from input image file */
bct_size = get_bct_size_from_image(&context);
- if (!bct_size) {
+ if (bct_size < 0) {
printf("Error: Invalid input image file %s\n",
context.input_image_filename);
goto fail;
diff --git a/src/data_layout.c b/src/data_layout.c
index 5d3fe10..460310d 100644
--- a/src/data_layout.c
+++ b/src/data_layout.c
@@ -792,7 +792,7 @@ read_bct_file(struct build_image_context_rec *context)
free(bct_storage);
if (!data_is_valid_bct(context))
- return ENODATA;
+ return -ENODATA;
return err;
}
@@ -1050,11 +1050,11 @@ int get_bct_size_from_image(build_image_context *context)
fp = fopen(context->input_image_filename, "r");
if (!fp)
- return ENODATA;
+ return -ENODATA;
if (fread(buffer, 1, NVBOOT_CONFIG_TABLE_SIZE_MAX, fp) != NVBOOT_CONFIG_TABLE_SIZE_MAX) {
fclose(fp);
- return ENODATA;
+ return -ENODATA;
}
context->bct = buffer;
--
2.6.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] Fix image update with image smaller than 10KiB
[not found] ` <1449585133-9384-1-git-send-email-alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
@ 2015-12-08 14:32 ` Alban Bedel
2015-12-09 0:16 ` [PATCH v3 1/2] Fix the error reporting of get_bct_size_from_image() and read_bct_file() Stephen Warren
1 sibling, 0 replies; 3+ messages in thread
From: Alban Bedel @ 2015-12-08 14:32 UTC (permalink / raw)
To: linux-tegra-u79uwXL29TY76Z2rM5mHXA; +Cc: Alban Bedel
The BCT size check assume a quiet large image, however if the image
doesn't contains a bootloader it won't be that large. Change the size
check to only read the minimum data needed to verify the BCT version
and get the size.
Signed-off-by: Alban Bedel <alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
--
Changelog:
v2: * Add a comment to explain the value of NVBOOT_CONFIG_TABLE_SIZE_MIN
v3: * Only read the minimum data needed
---
src/cbootimage.h | 14 ++++++++++++++
src/data_layout.c | 4 ++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/cbootimage.h b/src/cbootimage.h
index 63f0ee9..ba2d997 100644
--- a/src/cbootimage.h
+++ b/src/cbootimage.h
@@ -49,6 +49,20 @@
#define MAX_MTS_SIZE (4 * 1024 * 1024)
+/* Minimum size to read to at least be able to validate a BCT, it must
+ * include the boot_data_version field with any BCT version while not
+ * beeing larger than the smallest possible BCT. The currently supported
+ * BCT are as follow:
+ *
+ * Chip Version offset Total size
+ * T20 32 4080
+ * T30 32 6128
+ * T114 1792 8192
+ * T124 1744 8192
+ * T132 1744 8704
+ * T210 1328 10240
+ */
+#define NVBOOT_CONFIG_TABLE_SIZE_MIN 4080
#define NVBOOT_CONFIG_TABLE_SIZE_MAX (10 * 1024)
/*
diff --git a/src/data_layout.c b/src/data_layout.c
index 460310d..0eace5f 100644
--- a/src/data_layout.c
+++ b/src/data_layout.c
@@ -1044,7 +1044,7 @@ int data_is_valid_bct(build_image_context *context)
int get_bct_size_from_image(build_image_context *context)
{
- u_int8_t buffer[NVBOOT_CONFIG_TABLE_SIZE_MAX];
+ u_int8_t buffer[NVBOOT_CONFIG_TABLE_SIZE_MIN];
u_int32_t bct_size = 0;
FILE *fp;
@@ -1052,7 +1052,7 @@ int get_bct_size_from_image(build_image_context *context)
if (!fp)
return -ENODATA;
- if (fread(buffer, 1, NVBOOT_CONFIG_TABLE_SIZE_MAX, fp) != NVBOOT_CONFIG_TABLE_SIZE_MAX) {
+ if (fread(buffer, 1, NVBOOT_CONFIG_TABLE_SIZE_MIN, fp) != NVBOOT_CONFIG_TABLE_SIZE_MIN) {
fclose(fp);
return -ENODATA;
}
--
2.6.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/2] Fix the error reporting of get_bct_size_from_image() and read_bct_file()
[not found] ` <1449585133-9384-1-git-send-email-alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2015-12-08 14:32 ` [PATCH v3 2/2] Fix image update with image smaller than 10KiB Alban Bedel
@ 2015-12-09 0:16 ` Stephen Warren
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Warren @ 2015-12-09 0:16 UTC (permalink / raw)
To: Alban Bedel; +Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA
On 12/08/2015 07:32 AM, Alban Bedel wrote:
> get_bct_size_from_image() and read_bct_file() should return negative
> error codes, so add the missing minus signs. Also fix the return value
> check on get_bct_size_from_image(), a negative value indicate an error
> not zero.
I've applied the series.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-12-09 0:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-08 14:32 [PATCH v3 1/2] Fix the error reporting of get_bct_size_from_image() and read_bct_file() Alban Bedel
[not found] ` <1449585133-9384-1-git-send-email-alban.bedel-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2015-12-08 14:32 ` [PATCH v3 2/2] Fix image update with image smaller than 10KiB Alban Bedel
2015-12-09 0:16 ` [PATCH v3 1/2] Fix the error reporting of get_bct_size_from_image() and read_bct_file() Stephen Warren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).