[U-Boot] [RFC PATCH 12/22] dm: Support driver model prior to relocation

Simon Glass
2014-05-24T21:21:11Z

Initialise devices marked 'pre-reloc' and make them available prior to
relocation. Note that this requires pre-reloc malloc() to be available.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

common/board_f.c | 30 ++++++++++++++++++++++++++++++
common/board_r.c | 3 +++
include/asm-generic/global_data.h | 1 +
3 files changed, 34 insertions(+)

diff --git a/common/board_f.c b/common/board_f.c
index cc040c7..0dc745a 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -14,6 +14,7 @@
#include <linux/compiler.h>
#include <version.h>
#include <environment.h>
+#include <dm.h>
#include <fdtdec.h>
#include <fs.h>
#if defined(CONFIG_CMD_IDE)
@@ -52,6 +53,7 @@
#ifdef CONFIG_SANDBOX
#include <asm/state.h>
#endif
+#include <dm/root.h>
#include <linux/compiler.h>

/*
@@ -787,6 +789,33 @@ static int initf_malloc(void)
return 0;
}

+static int initf_dm(void)
+{
+#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_BASE)
+ int ret;
+
+ ret = dm_init();
+ if (ret) {
+ debug("dm_init() failed: %d\n", ret);
+ return ret;
+ }
+ ret = dm_scan_platdata(true);
+ if (ret) {
+ debug("dm_scan_platdata() failed: %d\n", ret);
+ return ret;
+ }
+#ifdef CONFIG_OF_CONTROL
+ ret = dm_scan_fdt(gd->fdt_blob, true);
+ if (ret) {
+ debug("dm_scan_fdt() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+#endif
+
+ return 0;
+}
+
static init_fnc_t init_sequence_f[] = {
#ifdef CONFIG_SANDBOX
setup_ram_buf,
@@ -845,6 +874,7 @@ static init_fnc_t init_sequence_f[] = {
init_timebase,
#endif
initf_malloc,
+ initf_dm,
init_baud_rate, /* initialze baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
diff --git a/common/board_r.c b/common/board_r.c
index e16f3ad..13c1bc1 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -275,6 +275,9 @@ static int initr_dm(void)
{
int ret;

+ /* Save the pre-reloc driver model and start a new one */
+ gd->dm_root_f = gd->dm_root;
+ gd->dm_root = NULL;
ret = dm_init();
if (ret) {
debug("dm_init() failed: %d\n", ret);
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 1070a75..b3b91d3 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -66,6 +66,7 @@ typedef struct global_data {

#ifdef CONFIG_DM
struct device *dm_root; /* Root instance for Driver Model */
+ struct device *dm_root_f; /* Pre-relocation root instance */
struct list_head uclass_root; /* Head of core tree */
#endif

--
1.9.1.423.g4596e3a