summaryrefslogtreecommitdiffstats
path: root/common/bootm.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-01-09 09:59:59 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2014-01-10 11:53:18 +0100
commit9bd67f5e6184ecd03b8e052706218f2a741027c3 (patch)
tree51a5ac95bbc796e0acd756d1fa8df9b4a65f90fb /common/bootm.c
parentf1025bbf3292c8c199e23e618c062ec1e9f2f055 (diff)
downloadbarebox-9bd67f5e6184ecd03b8e052706218f2a741027c3.tar.gz
barebox-9bd67f5e6184ecd03b8e052706218f2a741027c3.tar.xz
bootm: introduce bootm_load_os helper
The common bootm code used to load uImage contents to SDRAM before calling into the handlers if possible. This makes the handlers complicated since they have to handle many cases. Instead, introduce a helper to load the os after the handlers have figured out a good load address. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/bootm.c')
-rw-r--r--common/bootm.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/common/bootm.c b/common/bootm.c
index 2da6e59129..5ad10d9a02 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -45,6 +45,46 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
return NULL;
}
+/*
+ * bootm_load_os() - load OS to RAM
+ *
+ * @data: image data context
+ * @load_address: The address where the OS should be loaded to
+ *
+ * This loads the OS to a RAM location. load_address must be a valid
+ * address. If the image_data doesn't have a OS specified it's considered
+ * an error.
+ *
+ * Return: 0 on success, negative error code otherwise
+ */
+int bootm_load_os(struct image_data *data, unsigned long load_address)
+{
+ if (data->os_res)
+ return 0;
+
+ if (load_address == UIMAGE_INVALID_ADDRESS)
+ return -EINVAL;
+
+ if (data->os) {
+ data->os_res = uimage_load_to_sdram(data->os,
+ data->os_num, load_address);
+ if (!data->os_res)
+ return -ENOMEM;
+
+ return 0;
+ }
+
+ if (data->os_file) {
+ data->os_res = file_to_sdram(data->os_file, load_address);
+ if (!data->os_res)
+ return -ENOMEM;
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static int bootm_open_os_uimage(struct image_data *data)
{
int ret;
@@ -75,15 +115,6 @@ static int bootm_open_os_uimage(struct image_data *data)
if (data->os_address == UIMAGE_SOME_ADDRESS)
data->os_address = data->os->header.ih_load;
- if (data->os_address != UIMAGE_INVALID_ADDRESS) {
- data->os_res = uimage_load_to_sdram(data->os, 0,
- data->os_address);
- if (!data->os_res) {
- uimage_close(data->os);
- return -ENOMEM;
- }
- }
-
return 0;
}