Skip to content

Commit

Permalink
bootm: provide handlers the start of the OS image
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
saschahauer committed Apr 4, 2018
1 parent d4ff9c4 commit d5e19a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/bootm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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));
Expand Down Expand Up @@ -674,6 +681,7 @@ int bootm_boot(struct bootm_data *bootm_data)
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);
Expand Down
7 changes: 7 additions & 0 deletions include/bootm.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ struct image_data {
struct fdt_header *oftree;
struct resource *oftree_res;

/*
* The first PAGE_SIZE bytes of the OS image. Can be used by the image
* handlers to analyze the OS image before actually loading the bulk of
* it.
*/
void *os_header;

enum bootm_verify verify;
int verbose;
int force;
Expand Down

0 comments on commit d5e19a7

Please sign in to comment.