aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Shan <gwshan@linux.vnet.ibm.com>2016-06-10 15:03:34 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-06-14 16:00:16 +1000
commit108988a1497f23bbce6cc419e48e616648bbdfba (patch)
tree497991a46d707bb6038025a1a199bb5c63d31868
parent271c6112389b57860fe6e2e8aae3be27e6adbc37 (diff)
downloadskiboot-108988a1497f23bbce6cc419e48e616648bbdfba.zip
skiboot-108988a1497f23bbce6cc419e48e616648bbdfba.tar.gz
skiboot-108988a1497f23bbce6cc419e48e616648bbdfba.tar.bz2
core/fdt: Introduce __create_dtb()
There is shared logic to flatten the whole device tree (used when loading kernel) or device sub-tree (used by PCI hot add). This introduces helper function __create_dtb() for the shared logic. No functional changes introduced. Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--core/fdt.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/core/fdt.c b/core/fdt.c
index 6d8130d..fbfbac6 100644
--- a/core/fdt.c
+++ b/core/fdt.c
@@ -165,15 +165,31 @@ static void create_dtb_reservemap(void *fdt, const struct dt_node *root)
save_err(fdt_finish_reservemap(fdt));
}
+static int __create_dtb(void *fdt, size_t len,
+ const struct dt_node *root)
+{
+ fdt_create(fdt, len);
+ create_dtb_reservemap(fdt, root);
+ flatten_dt_node(fdt, root);
+
+ save_err(fdt_finish(fdt));
+ if (fdt_error) {
+ prerror("dtb: error %s\n", fdt_strerror(fdt_error));
+ return fdt_error;
+ }
+
+ dump_fdt(fdt);
+ return 0;
+}
+
void *create_dtb(const struct dt_node *root)
{
void *fdt = NULL;
size_t len = DEVICE_TREE_MAX_SIZE;
uint32_t old_last_phandle = last_phandle;
+ int ret;
do {
- if (fdt)
- free(fdt);
last_phandle = old_last_phandle;
fdt_error = 0;
fdt = malloc(len);
@@ -182,26 +198,14 @@ void *create_dtb(const struct dt_node *root)
return NULL;
}
- fdt_create(fdt, len);
-
- create_dtb_reservemap(fdt, root);
-
- /* Unflatten our live tree */
- flatten_dt_node(fdt, root);
-
- save_err(fdt_finish(fdt));
-
- if (!fdt_error)
- break;
+ ret = __create_dtb(fdt, len, root);
+ if (ret) {
+ free(fdt);
+ fdt = NULL;
+ }
len *= 2;
- } while (fdt_error == -FDT_ERR_NOSPACE);
+ } while (ret == -FDT_ERR_NOSPACE);
- dump_fdt(fdt);
-
- if (fdt_error) {
- prerror("dtb: error %s\n", fdt_strerror(fdt_error));
- return NULL;
- }
return fdt;
}