diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-03-14 16:16:02 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-04-04 07:44:26 +0200 |
commit | d5e19a7ea2a9cdb156677ce957183a8c8b5a2fe5 (patch) | |
tree | 53637927bf18236629e4df1f4a65e588489cf426 /common | |
parent | d4ff9c40baf3cf64565c423d6f7622f27ec48a84 (diff) | |
download | barebox-d5e19a7ea2a9cdb156677ce957183a8c8b5a2fe5.tar.gz barebox-d5e19a7ea2a9cdb156677ce957183a8c8b5a2fe5.tar.xz |
bootm: provide handlers the start of the OS image
The bootm code needs to read the beginning of the OS image in order to
determine the filetype. If it does so already, then we can provide the
handlers the buffer. This can help the handlers to find some image
metadata before loading the full image.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/bootm.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/common/bootm.c b/common/bootm.c index 3e48ca1d88..5ff6683fe7 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -529,6 +529,7 @@ int bootm_boot(struct bootm_data *bootm_data) struct image_handler *handler; int ret; enum filetype os_type; + size_t size; if (!bootm_data->os_file) { printf("no image given\n"); @@ -548,7 +549,13 @@ int bootm_boot(struct bootm_data *bootm_data) data->os_address = bootm_data->os_address; data->os_entry = bootm_data->os_entry; - os_type = file_name_detect_type(data->os_file); + ret = read_file_2(data->os_file, &size, &data->os_header, PAGE_SIZE); + if (ret < 0 && ret != -EFBIG) + goto err_out; + if (size < PAGE_SIZE) + goto err_out; + + os_type = file_detect_type(data->os_header, PAGE_SIZE); if ((int)os_type < 0) { printf("could not open %s: %s\n", data->os_file, strerror(-os_type)); @@ -674,6 +681,7 @@ err_out: of_delete_node(data->of_root_node); globalvar_remove("linux.bootargs.bootm.appendroot"); + free(data->os_header); free(data->os_file); free(data->oftree_file); free(data->initrd_file); |