diff mbox

[U-Boot] env_ram.c: import env from other boot loader

Message ID 1320994497-27894-1-git-send-email-macpaul@andestech.com
State Changes Requested
Delegated to: Wolfgang Denk
Headers show

Commit Message

Macpaul Lin Nov. 11, 2011, 6:54 a.m. UTC
If the system has dual boot loader, say loader1 and u-boot is loader2.
If loader1 will be booted before u-boot and then pass env to u-boot in
the format of u-boot's env, this module provides importing env from ram.

This feature needs to add related support in cmd_nvedit.c.

Signed-off-by: Macpaul Lin <macpaul@andestech.com>
---
 common/Makefile     |    1 +
 common/cmd_nvedit.c |    3 +-
 common/env_ram.c    |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletions(-)
 create mode 100644 common/env_ram.c

Comments

Wolfgang Denk Nov. 11, 2011, 11:49 a.m. UTC | #1
Dear Macpaul Lin,

In message <1320994497-27894-1-git-send-email-macpaul@andestech.com> you wrote:
> If the system has dual boot loader, say loader1 and u-boot is loader2.
> If loader1 will be booted before u-boot and then pass env to u-boot in
> the format of u-boot's env, this module provides importing env from ram.
> 
> This feature needs to add related support in cmd_nvedit.c.

I don't think you need extra code for this.  The situation is not
different from any other where for example the environment is attached
to the U-Boot image, or embedded into it.  You just need to configure
the address / offset correctly in your board config header.

Best regards,

Wolfgang Denk
Macpaul Lin Nov. 12, 2011, 6:30 a.m. UTC | #2
Hi Wolfgang,

2011/11/11 Wolfgang Denk <wd@denx.de>:
> Dear Macpaul Lin,
>
> I don't think you need extra code for this.  The situation is not
> different from any other where for example the environment is attached
> to the U-Boot image, or embedded into it.  You just need to configure
> the address / offset correctly in your board config header.

Thanks!

I'll check this out next week.
diff mbox

Patch

diff --git a/common/Makefile b/common/Makefile
index 1b672ad..8e39502 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -60,6 +60,7 @@  COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
 COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
 COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
+COBJS-$(CONFIG_ENV_IS_IN_RAM) += env_ram.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
 COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
 
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 396a171..5b6c6bc 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -64,10 +64,11 @@  DECLARE_GLOBAL_DATA_PTR;
 	!defined(CONFIG_ENV_IS_IN_NAND)		&& \
 	!defined(CONFIG_ENV_IS_IN_NVRAM)	&& \
 	!defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
+	!defined(CONFIG_ENV_IS_IN_RAM)		&& \
 	!defined(CONFIG_ENV_IS_IN_SPI_FLASH)	&& \
 	!defined(CONFIG_ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|MG_DISK|NVRAM|MMC} or CONFIG_ENV_IS_NOWHERE
+SPI_FLASH|MG_DISK|NVRAM|MMC|RAM} or CONFIG_ENV_IS_NOWHERE
 #endif
 
 #define XMK_STR(x)	#x
diff --git a/common/env_ram.c b/common/env_ram.c
new file mode 100644
index 0000000..4a3cad2
--- /dev/null
+++ b/common/env_ram.c
@@ -0,0 +1,58 @@ 
+/*
+ * (C) Copyright 2000-2010
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2011 Andes Technology
+ * Macpaul Lin <macpaul@andestech.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <linux/stddef.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+char *env_name_spec = "Ram";
+
+extern uchar default_environment[];
+env_t *env_ptr = NULL;
+
+void env_relocate_spec(void)
+{
+	env_import((char *)CONFIG_ENV_IMPORT_ADDR, 0);
+}
+
+uchar env_get_char_spec(int index)
+{
+	return *((uchar *)(gd->env_addr + index));
+}
+
+/*
+ * Initialize Environment use
+ */
+int env_init(void)
+{
+	gd->env_addr  = (ulong)&default_environment[0];
+	gd->env_valid = 1;
+
+	return 0;
+}