diff options
author | Penny Chiu <pchiu@nvidia.com> | 2014-04-11 17:50:43 +0800 |
---|---|---|
committer | Stephen Warren <swarren@nvidia.com> | 2014-04-15 12:02:07 -0600 |
commit | ef386340a60eb3d21f2215316e90dd4ba35fd27e (patch) | |
tree | f1c524838b5c9d2e4cfdf6f45ac5c1e33333fc5d /src/set.c | |
parent | 5f0b21a2b62a2cafab0dc3848d5516d93b2288ae (diff) | |
download | nvidia-cbootimage-ef386340a60eb3d21f2215316e90dd4ba35fd27e.tar.gz |
Add update BCT configs feature
This feature reads the BCT data from BCT or BCT with bootloader
appended binary, updates the BCT data based on config file, then
writes to new image file.
Signed-off-by: Penny Chiu <pchiu@nvidia.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'src/set.c')
-rw-r--r-- | src/set.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -43,6 +43,8 @@ int read_from_image(char *filename, + u_int32_t offset, + u_int32_t max_size, u_int8_t **image, u_int32_t *actual_size, file_type f_type) @@ -57,6 +59,8 @@ read_from_image(char *filename, return result; } + fseek(fp, offset, SEEK_SET); + if (stat(filename, &stats) != 0) { printf("Error: Unable to query info on bootloader path %s\n", filename); @@ -64,14 +68,21 @@ read_from_image(char *filename, goto cleanup; } - *actual_size = (u_int32_t)stats.st_size; - - if (f_type == file_type_bl && *actual_size > MAX_BOOTLOADER_SIZE) { - printf("Error: Bootloader file %s is too large.\n", - filename); - result = 1; - goto cleanup; + if (f_type == file_type_bl) { + if ((stats.st_size - offset) > max_size) { + printf("Error: Bootloader file %s is too large.\n", + filename); + result = 1; + goto cleanup; + } + *actual_size = (u_int32_t)stats.st_size; + } else { + if ((stats.st_size - offset) < max_size) + *actual_size = stats.st_size - offset; + else + *actual_size = max_size; } + *image = malloc(*actual_size); if (*image == NULL) { result = 1; @@ -80,7 +91,8 @@ read_from_image(char *filename, memset(*image, 0, *actual_size); - if (fread(*image, 1, (size_t)stats.st_size, fp) != stats.st_size) { + if (fread(*image, 1, (size_t)(*actual_size), fp) != + (size_t)(*actual_size)) { result = 1; goto cleanup; } |