From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 08/13] bootm: move oftree code together
Date: Fri, 15 Jan 2016 16:07:13 +0100 [thread overview]
Message-ID: <1452870438-29656-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1452870438-29656-1-git-send-email-s.hauer@pengutronix.de>
The device tree code is distributed in several places in the bootm code.
Move it all together in bootm_load_devicetree().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/bootm.c | 193 +++++++++++++++++++++++++--------------------------------
1 file changed, 86 insertions(+), 107 deletions(-)
diff --git a/common/bootm.c b/common/bootm.c
index 06f1f8a..e399a6a 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -199,6 +199,47 @@ done:
return 0;
}
+static int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
+ struct fdt_header **fdt)
+{
+ enum filetype ft;
+ const char *oftree = data->oftree_file;
+ int num = simple_strtoul(data->oftree_part, NULL, 0);
+ struct uimage_handle *of_handle;
+ int release = 0;
+
+ printf("Loading devicetree from '%s'@%d\n", oftree, num);
+
+ if (!IS_ENABLED(CONFIG_CMD_BOOTM_OFTREE_UIMAGE))
+ return -EINVAL;
+
+ if (!strcmp(data->os_file, oftree)) {
+ of_handle = data->os;
+ } else if (!strcmp(data->initrd_file, oftree)) {
+ of_handle = data->initrd;
+ } else {
+ of_handle = uimage_open(oftree);
+ if (!of_handle)
+ return -ENODEV;
+ uimage_print_contents(of_handle);
+ release = 1;
+ }
+
+ *fdt = uimage_load_to_buf(of_handle, num, size);
+
+ if (release)
+ uimage_close(of_handle);
+
+ ft = file_detect_type(*fdt, *size);
+ if (ft != filetype_oftree) {
+ printf("%s is not an oftree but %s\n",
+ data->oftree_file, file_type_to_string(ft));
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/*
* bootm_load_devicetree() - load devicetree
*
@@ -212,8 +253,10 @@ done:
*/
int bootm_load_devicetree(struct image_data *data, unsigned long load_address)
{
+ enum filetype type;
int fdt_size;
struct fdt_header *oftree;
+ int ret;
if (data->oftree)
return 0;
@@ -221,8 +264,49 @@ int bootm_load_devicetree(struct image_data *data, unsigned long load_address)
if (!IS_ENABLED(CONFIG_OFTREE))
return 0;
- if (!data->of_root_node)
- return 0;
+ if (data->oftree_file) {
+ size_t size;
+
+ type = file_name_detect_type(data->oftree_file);
+
+ if ((int)type < 0) {
+ printf("could not open %s: %s\n", data->oftree_file,
+ strerror(-type));
+ return (int)type;
+ }
+
+ switch (type) {
+ case filetype_uimage:
+ ret = bootm_open_oftree_uimage(data, &size, &oftree);
+ break;
+ case filetype_oftree:
+ ret = read_file_2(data->oftree_file, &size, (void *)&oftree,
+ FILESIZE_MAX);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (ret)
+ return ret;
+
+ data->of_root_node = of_unflatten_dtb(oftree);
+
+ free(oftree);
+
+ if (!data->of_root_node) {
+ pr_err("unable to unflatten devicetree\n");
+ return -EINVAL;
+ }
+
+ } else {
+ data->of_root_node = of_get_root_node();
+ if (!data->of_root_node)
+ return 0;
+
+ if (bootm_verbose(data) > 1 && data->of_root_node)
+ printf("using internal devicetree\n");
+ }
if (data->initrd_res) {
of_add_initrd(data->of_root_node, data->initrd_res->start,
@@ -311,84 +395,6 @@ static int bootm_open_os_uimage(struct image_data *data)
return 0;
}
-static int bootm_open_oftree_uimage(struct image_data *data)
-{
- struct fdt_header *fdt;
- enum filetype ft;
- const char *oftree = data->oftree_file;
- int num = simple_strtoul(data->oftree_part, NULL, 0);
- struct uimage_handle *of_handle;
- int release = 0;
- size_t size;
-
- printf("Loading devicetree from '%s'@%d\n", oftree, num);
-
- if (IS_ENABLED(CONFIG_CMD_BOOTM_OFTREE_UIMAGE)) {
- if (!strcmp(data->os_file, oftree)) {
- of_handle = data->os;
- } else if (!strcmp(data->initrd_file, oftree)) {
- of_handle = data->initrd;
- } else {
- of_handle = uimage_open(oftree);
- if (!of_handle)
- return -ENODEV;
- uimage_print_contents(of_handle);
- release = 1;
- }
-
- fdt = uimage_load_to_buf(of_handle, num, &size);
-
- if (release)
- uimage_close(of_handle);
-
- ft = file_detect_type(fdt, size);
- if (ft != filetype_oftree) {
- printf("%s is not an oftree but %s\n",
- data->oftree_file, file_type_to_string(ft));
- return -EINVAL;
- }
-
- data->of_root_node = of_unflatten_dtb(fdt);
- if (!data->of_root_node) {
- pr_err("unable to unflatten devicetree\n");
- free(fdt);
- return -EINVAL;
- }
-
- free(fdt);
-
- return 0;
- } else {
- return -EINVAL;
- }
-}
-
-static int bootm_open_oftree(struct image_data *data)
-{
- struct fdt_header *fdt;
- const char *oftree = data->oftree_file;
- size_t size;
-
- printf("Loading devicetree from '%s'\n", oftree);
-
- fdt = read_file(oftree, &size);
- if (!fdt) {
- perror("open");
- return -ENODEV;
- }
-
- data->of_root_node = of_unflatten_dtb(fdt);
- if (!data->of_root_node) {
- pr_err("unable to unflatten devicetree\n");
- free(fdt);
- return -EINVAL;
- }
-
- free(fdt);
-
- return 0;
-}
-
static void bootm_print_info(struct image_data *data)
{
if (data->os_res)
@@ -431,7 +437,6 @@ int bootm_boot(struct bootm_data *bootm_data)
struct image_handler *handler;
int ret;
enum filetype os_type;
- enum filetype oftree_type = filetype_unknown;
if (!bootm_data->os_file) {
printf("no image given\n");
@@ -465,17 +470,6 @@ int bootm_boot(struct bootm_data *bootm_data)
goto err_out;
}
- if (IS_ENABLED(CONFIG_OFTREE) && data->oftree_file) {
- oftree_type = file_name_detect_type(data->oftree_file);
-
- if ((int)oftree_type < 0) {
- printf("could not open %s: %s\n", data->oftree_file,
- strerror(-oftree_type));
- ret = (int) oftree_type;
- goto err_out;
- }
- }
-
if (os_type == filetype_uimage) {
ret = bootm_open_os_uimage(data);
if (ret) {
@@ -492,21 +486,6 @@ int bootm_boot(struct bootm_data *bootm_data)
printf(", multifile image %s", data->os_part);
printf("\n");
- if (IS_ENABLED(CONFIG_OFTREE)) {
- if (data->oftree_file) {
- if (oftree_type == filetype_uimage)
- ret = bootm_open_oftree_uimage(data);
- if (oftree_type == filetype_oftree)
- ret = bootm_open_oftree(data);
- if (ret)
- goto err_out;
- } else {
- data->of_root_node = of_get_root_node();
- if (bootm_verbose(data) > 1 && data->of_root_node)
- printf("using internal devicetree\n");
- }
- }
-
if (data->os_address == UIMAGE_SOME_ADDRESS)
data->os_address = UIMAGE_INVALID_ADDRESS;
--
2.6.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-01-15 15:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-15 15:07 [PATCH v3] FIT support Sascha Hauer
2016-01-15 15:07 ` [PATCH 01/13] ARM: zImage: add missing free() in appended device tree code Sascha Hauer
2016-01-15 15:07 ` [PATCH 02/13] bootm: Do not call uimage_close twice Sascha Hauer
2016-01-15 15:07 ` [PATCH 03/13] bootm: introduce bootm_get_os_size Sascha Hauer
2016-01-15 15:07 ` [PATCH 04/13] bootm: use names instead of numbers for image parts Sascha Hauer
2016-01-15 15:07 ` [PATCH 05/13] ARM: bootm: Use kernel handler to start barebox image Sascha Hauer
2016-01-15 15:07 ` [PATCH 06/13] bootm: Push dryrun to handlers Sascha Hauer
2016-01-15 15:07 ` [PATCH 07/13] bootm: move initrd code together Sascha Hauer
2016-01-15 15:07 ` Sascha Hauer [this message]
2016-01-15 15:07 ` [PATCH 09/13] bootm: Initialize bootm_data defaults in single place Sascha Hauer
2016-01-15 15:07 ` [PATCH 10/13] crypto: add digest_alloc_by_algo() Sascha Hauer
2016-01-15 15:07 ` [PATCH 11/13] crypto: add RSA support Sascha Hauer
2016-01-15 15:07 ` [PATCH 12/13] bootm: make verifying/hashing configurable Sascha Hauer
2016-01-15 15:07 ` [PATCH 13/13] bootm: add initial FIT support Sascha Hauer
2016-01-15 15:37 ` Holger Schurig
2016-01-18 7:31 ` Sascha Hauer
2016-01-15 15:50 ` [PATCH v3] " Yegor Yefremov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452870438-29656-9-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox