Patchwork [U-Boot,v3,20/23] keymile, common: add setting of some environment variables

login
register
mail settings
Submitter Heiko Schocher
Date March 21, 2011, 7:02 a.m.
Message ID <1300690939-31511-21-git-send-email-hs@denx.de>
Download mbox | patch
Permalink /patch/87700/
State Superseded
Headers show

Comments

Heiko Schocher - March 21, 2011, 7:02 a.m.
This patch adds last_stage_init to all keymile boards. And
in the last stage init some environment variables for u-boot
were set. Currently these are pnvramaddr, pram and var address.

Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
Signed-off-by: Heiko Schocher <hs@denx.de>
cc: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Wolfgang Denk <wd@denx.de>
cc: Kim Phillips <kim.phillips@freescale.com>
---
Changes for v2:
  - fix checkpatch.pl errors and warnings
Changes for v3:
  - rebased only

 board/keymile/common/common.c    |   38 +++++++++++++++++++++++++++++++++++++-
 board/keymile/common/common.h    |    1 +
 board/keymile/km83xx/km83xx.c    |    6 ++++++
 board/keymile/km_arm/km_arm.c    |    6 ++++++
 board/keymile/mgcoge/mgcoge.c    |    6 ++++++
 include/configs/keymile-common.h |    3 +++
 include/configs/km_arm.h         |    7 +++++++
 7 files changed, 66 insertions(+), 1 deletions(-)

Patch

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 8392a64..3908e63 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -42,6 +42,7 @@ 
 
 static void i2c_write_start_seq(void);
 static int i2c_make_abort(void);
+DECLARE_GLOBAL_DATA_PTR;
 
 int ivm_calc_crc(unsigned char *buf, int len)
 {
@@ -73,7 +74,42 @@  int ivm_calc_crc(unsigned char *buf, int len)
 	return crc;
 }
 
-static int ivm_set_value(char *name, char *value)
+/*
+ * Set Keymile specific environment variables
+ * Currently only some memory layout variables are calculated here
+ * ... ------------------------------------------------
+ * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM
+ * ... |<------------------- pram ------------------->|
+ * ... ------------------------------------------------
+ * @END_OF_RAM: denotes the RAM size
+ * @pnvramaddr: Startadress of pseudo non volatile RAM in hex
+ * @pram      : preserved ram size in k
+ * @varaddr   : startadress for /var mounted into RAM
+ */
+int set_km_env(void)
+{
+	uchar buf[32];
+	unsigned int pnvramaddr;
+	unsigned int pram;
+	unsigned int varaddr;
+
+	pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
+			- CONFIG_KM_PNVRAM;
+	sprintf((char *)buf, "0x%x", pnvramaddr);
+	setenv("pnvramaddr", (char *)buf);
+
+	pram = (CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM + CONFIG_KM_PNVRAM) /
+		0x400;
+	sprintf((char *)buf, "0x%x", pram);
+	setenv("pram", (char *)buf);
+
+	varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
+	sprintf((char *)buf, "0x%x", varaddr);
+	setenv("varaddr", (char *)buf);
+	return 0;
+}
+
+static int  ivm_set_value(char *name, char *value)
 {
 	char tempbuf[256];
 
diff --git a/board/keymile/common/common.h b/board/keymile/common/common.h
index 03838fe..7a8238c 100644
--- a/board/keymile/common/common.h
+++ b/board/keymile/common/common.h
@@ -49,6 +49,7 @@  int ivm_read_eeprom(void);
 int keymile_hdlc_enet_initialize(bd_t *bis);
 #endif
 
+int set_km_env(void);
 int fdt_set_node_and_value(void *blob,
 			char *nodename,
 			char *regname,
diff --git a/board/keymile/km83xx/km83xx.c b/board/keymile/km83xx/km83xx.c
index d940a1e..818e3e3 100644
--- a/board/keymile/km83xx/km83xx.c
+++ b/board/keymile/km83xx/km83xx.c
@@ -190,6 +190,12 @@  int misc_init_r(void)
 	return 0;
 }
 
+int last_stage_init(void)
+{
+	set_km_env();
+	return 0;
+}
+
 int fixed_sdram(void)
 {
 	immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c
index cb999b2..c772ee2 100644
--- a/board/keymile/km_arm/km_arm.c
+++ b/board/keymile/km_arm/km_arm.c
@@ -212,6 +212,12 @@  int board_init(void)
 	return 0;
 }
 
+int last_stage_init(void)
+{
+	set_km_env();
+	return 0;
+}
+
 #if defined(CONFIG_CMD_SF)
 int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
diff --git a/board/keymile/mgcoge/mgcoge.c b/board/keymile/mgcoge/mgcoge.c
index a58256e..340016b 100644
--- a/board/keymile/mgcoge/mgcoge.c
+++ b/board/keymile/mgcoge/mgcoge.c
@@ -313,6 +313,12 @@  int board_early_init_r(void)
 	return 0;
 }
 
+int last_stage_init(void)
+{
+	set_km_env();
+	return 0;
+}
+
 int hush_init_var(void)
 {
 	ivm_read_eeprom();
diff --git a/include/configs/keymile-common.h b/include/configs/keymile-common.h
index 77e2090..da5a447 100644
--- a/include/configs/keymile-common.h
+++ b/include/configs/keymile-common.h
@@ -26,6 +26,9 @@ 
 
 /* Do boardspecific init for all boards */
 #define CONFIG_BOARD_EARLY_INIT_R
+#define CONFIG_LAST_STAGE_INIT
+
+#define CONFIG_BOOTCOUNT_LIMIT
 
 /*
  * By default kwbimage.cfg from board specific folder is used
diff --git a/include/configs/km_arm.h b/include/configs/km_arm.h
index 8cb0fe8..9c8d0e7 100644
--- a/include/configs/km_arm.h
+++ b/include/configs/km_arm.h
@@ -254,4 +254,11 @@  int get_scl (void);
 #define CONFIG_SYS_INIT_SP_ADDR		0xC8012000
 /* Do early setups now in board_init_f() */
 #define CONFIG_BOARD_EARLY_INIT_F
+
+/*
+ * resereved pram area at the end of memroy [hex]
+ * 8Mbytes for switch + 4Kbytes for bootcount
+ */
+#define CONFIG_KM_RESERVED_PRAM 0x801000
+
 #endif /* _CONFIG_KM_ARM_H */