[Skiboot] [PATCH 2/2] mambo: fake NVRAM support

Chris Smart distroguy at gmail.com
Tue Nov 29 14:18:48 AEDT 2016


This re-configures the Mambo platform to use the new fake NVRAM
introduced by Jack Miller <jack at codezen.org> in commit:

  mambo: Add Fake NVRAM driver

An existing NVRAM file can be loaded by pointing SKIBOOT_NVRAM
environment variable to the file when running Mambo.

If no NVRAM file is provided, the default is set to 256Kb and will be
formatted automatically by Skiboot on boot, e.g.:

[ 0.000975501,5 ] NVRAM: Size is 256 KB
[ 0.002292860,3 ] NVRAM: Partition at offset 0x0 has incorrect 0 length
[ 0.002298792,3 ] NVRAM: Re-initializing (size: 0x00040000)

This has been tested in Mambo, on bare metal Linux, as well as OpenPower
BMC machines.

Signed-off-by: Chris Smart <chris at distroguy.com>
---
 external/mambo/skiboot.tcl | 22 +++++++++++++++++++++-
 platforms/mambo/mambo.c    | 20 +++-----------------
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/external/mambo/skiboot.tcl b/external/mambo/skiboot.tcl
index 02a5ba94bc1922bf..fdcf14d17fdfd353 100644
--- a/external/mambo/skiboot.tcl
+++ b/external/mambo/skiboot.tcl
@@ -171,17 +171,37 @@ lappend compat "ibm,power8-xscom"
 set compat [of::encode_compat $compat]
 mysim of addprop $xscom_node byte_array "compatible" $compat
 
+# Load any initramfs
+set cpio_start 0x80000000
+set cpio_end $cpio_start
 if { [info exists env(SKIBOOT_INITRD)] } {
     set cpio_file $env(SKIBOOT_INITRD)
     set chosen_node [mysim of find_device /chosen]
     set cpio_size [file size $cpio_file]
-    set cpio_start 0x80000000
     set cpio_end [expr $cpio_start + $cpio_size]
     mysim of addprop $chosen_node int "linux,initrd-start" $cpio_start
     mysim of addprop $chosen_node int "linux,initrd-end"   $cpio_end
     mysim mcm 0 memory fread $cpio_start $cpio_size $cpio_file
 }
 
+# Default NVRAM is blank and will be formatted by Skiboot if no file is provided
+set fake_nvram_start $cpio_end
+set fake_nvram_size 0x40000
+# Load any fake NVRAM file if provided
+if { [info exists env(SKIBOOT_NVRAM)] } {
+    # Set up and write NVRAM file
+    set fake_nvram_file $env(SKIBOOT_NVRAM)
+    set fake_nvram_size [file size $fake_nvram_file]
+    mysim mcm 0 memory fread $fake_nvram_start $fake_nvram_size $fake_nvram_file
+}
+
+# Add device tree entry for NVRAM
+set reserved_memory [mysim of addchild $root_node "reserved-memory" ""]
+set fake_nvram_node [mysim of addchild $reserved_memory "ibm,fake-nvram" ""]
+set reg [list $fake_nvram_start $fake_nvram_size ]
+mysim of addprop $fake_nvram_node array64 "reg" reg
+mysim of addprop $fake_nvram_node empty "name" "ibm,fake-nvram"
+
 # Init CPUs
 set pir 0
 for { set c 0 } { $c < $mconf(cpus) } { incr c } {
diff --git a/platforms/mambo/mambo.c b/platforms/mambo/mambo.c
index 8d4820f1bbfe5548..663164d0b87f7377 100644
--- a/platforms/mambo/mambo.c
+++ b/platforms/mambo/mambo.c
@@ -281,21 +281,6 @@ static void __attribute__((noreturn)) mambo_terminate(const char *msg __unused)
 	for (;;) ;
 }
 
-static int mambo_nvram_info(uint32_t *total_size)
-{
-	*total_size = 0x100000;
-	return OPAL_SUCCESS;
-}
-
-static int mambo_nvram_start_read(void *dst, uint32_t src, uint32_t len)
-{
-	memset(dst+src, 0, len);
-
-	nvram_read_complete(true);
-
-	return OPAL_SUCCESS;
-}
-
 static int mambo_heartbeat_time(void)
 {
 	/*
@@ -311,9 +296,10 @@ DECLARE_PLATFORM(mambo) = {
 	.init		= mambo_platform_init,
 	.cec_power_down = mambo_cec_power_down,
 	.terminate	= mambo_terminate,
-	.nvram_info		= mambo_nvram_info,
-	.nvram_start_read	= mambo_nvram_start_read,
 	.start_preload_resource	= flash_start_preload_resource,
 	.resource_loaded	= flash_resource_loaded,
 	.heartbeat_time		= mambo_heartbeat_time,
+	.nvram_info		= fake_nvram_info,
+	.nvram_start_read	= fake_nvram_start_read,
+	.nvram_write		= fake_nvram_write,
 };
-- 
2.9.3



More information about the Skiboot mailing list