summaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-12-09 09:39:31 -0800
committerPatrick Georgi <pgeorgi@google.com>2016-01-19 18:14:44 +0100
commit755994689630fbec38c1a3e5d61aef69fc7ff8c5 (patch)
treed719c357c2071f51862665398b47f0a1950c6c79 /util/cbfstool/cbfstool.c
parent6313bc7731fccc1a80762093b38352aba75e694d (diff)
downloadcoreboot-755994689630fbec38c1a3e5d61aef69fc7ff8c5.tar.xz
cbfstool: accept read-only files when possible
cbfstool tries opening the input file for write access even if the command does not require modifying the file. Let's not request write access unless it is necessary, this way one can examine write protected files without sudo. BRANCH=none BUG=none TEST=running cbfstool /build/<board>/firmware/image.bin print in chroot does not require root access any more. Change-Id: Ic4e4cc389b160da190e44a676808f5c4e6625567 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: ef6a8e25d9e257d7de4cc6b94e510234fe20a56d Original-Change-Id: I871f32f0662221ffbdb13bf0482cb285ec184d07 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/317300 Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/12931 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 62edd4b7e6..8ad66c457c 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -38,7 +38,10 @@ struct command {
int (*function) (void);
// Whether to populate param.image_region before invoking function
bool accesses_region;
- // Whether to write that region's contents back to image_file at the end
+ // This set to true means two things:
+ // - in case of a command operating on a region, the region's contents
+ // will be written back to image_file at the end
+ // - write access to the file is required
bool modifies_region;
};
@@ -1014,7 +1017,7 @@ static const struct command commands[] = {
{"print", "H:r:vh?", cbfs_print, true, false},
{"read", "r:f:vh?", cbfs_read, true, false},
{"remove", "H:r:n:vh?", cbfs_remove, true, true},
- {"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, false},
+ {"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, true},
{"write", "r:f:udvh?", cbfs_write, true, true},
};
@@ -1372,8 +1375,11 @@ int main(int argc, char **argv)
return 1;
}
} else {
+ bool write_access = commands[i].modifies_region;
+
param.image_file =
- partitioned_file_reopen(image_name);
+ partitioned_file_reopen(image_name,
+ write_access);
}
if (!param.image_file)
return 1;
@@ -1429,7 +1435,6 @@ int main(int argc, char **argv)
if (commands[i].modifies_region) {
assert(param.image_file);
- assert(commands[i].accesses_region);
for (unsigned region = 0; region < num_regions;
++region) {