Add support for saveing env variable to SDCard
cover Add support for saveing env variable to SDCard
[PATCH v1 1/3] Make mmc init come before env_relocate
[PATCH v1 2/3] Add support for save environment variable to MMC/SD card [PATCH v1 3/3] mpc8536: Get the address of env on the SDCard
PATCH 1/3 Make mmc init come before env_relocate
If the environment variables are saved on the MMC/SD card, env_relocat can't relocate env from MMC/SD card without mmc init.
--- lib_ppc/board.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
lib_ppc/board.c +6 -6
@@ -824,6 +824,12 @@ void board_init_r (gd_t *id, ulong dest_addr)nand_init ();/* go init the NAND */ #endif +#ifdef CONFIG_GENERIC_MMC +WATCHDOG_RESET (); +puts ("MMC: " ); +mmc_initialize (bd); +#endif +/* relocate environment function pointers etc. */ env_relocate ();
@@ -990,12 +996,6 @@ void board_init_r (gd_t *id, ulong dest_addr)scsi_init ();#endif -#ifdef CONFIG_GENERIC_MMC -WATCHDOG_RESET (); -puts ("MMC: " ); -mmc_initialize (bd); -#endif -#if defined(CONFIG_CMD_DOC )WATCHDOG_RESET ();puts ("DOC: " );
Signature · 1 line
1.6.4
PATCH 2/3 Add support for save environment variable to MMC/SD card
Whether booting from MMC/SD card or not, the environment variables can be saved on it, this patch add the operation support.
--- common/Makefile | 1 + common/cmd_nvedit.c | 3 +- common/env_sdcard.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletions(-) create mode 100644 common/env_sdcard.c
common/Makefile +1 -0
@@ -61,6 +61,7 @@ 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_SPI_FLASH) += env_sf.o +COBJS-$(CONFIG_ENV_IS_IN_SDCARD) += env_sdcard.o COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o # command
common/cmd_nvedit.c +2 -1
@@ -60,9 +60,10 @@ DECLARE_GLOBAL_DATA_PTR; !defined (CONFIG_ENV_IS_IN_NVRAM ) && \ !defined (CONFIG_ENV_IS_IN_ONENAND ) && \ !defined (CONFIG_ENV_IS_IN_SPI_FLASH ) && \ + !defined (CONFIG_ENV_IS_IN_SDCARD ) && \ !defined(CONFIG_ENV_IS_NOWHERE)# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ -SPI_FLASH|MG_DISK|NVRAM|NOWHERE} +SPI_FLASH|MG_DISK|NVRAM|SDCARD|NOWHERE}#endif #define XMK_STR (x) #x
common/env_sdcard.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
1.6.4
PATCH 3/3 mpc8536: Get the address of env on the SDCard
Both the save env and load env operation will call this function to get the address of env on the SDCard, so the user can control where to put the env freely.
Also enable the functionlity of saving env variable to SDCard on mpc8536
--- board/freescale/mpc8536ds/mpc8536ds.c | 46 +++++++++++++++++++++++++++++++++ include/configs/MPC8536DS.h | 5 +++- 2 files changed, 50 insertions(+), 1 deletions(-)
board/freescale/mpc8536ds/mpc8536ds.c +46 -0
@@ -38,6 +38,8 @@#include <tsec.h> #include <netdev.h> #include <sata.h> +#include <mmc.h> +#include <malloc.h> #include "../common/pixis.h" #include "../common/sgmii_riser.h"
@@ -681,3 +683,47 @@ void ft_board_setup(void *blob, bd_t *bd)#endif }#endif + +#if defined(CONFIG_MMC ) +/* +* The environment variables are written to just after the u-boot image +* on SDCard, so we must read the MBR to get the start address and code +* length of the u-boot image, then calculate the address of the env. +*/ +#define ESDHC_BOOT_IMAGE_SIZE 0x48 +#define ESDHC_BOOT_IMAGE_ADDR 0x50 + +int mmc_get_env_addr (int dev,u32 *env_addr) +{ +int ret; +u8 *tmp_buf; +u32 blklen, code_offset, code_len; +struct mmc *mmc =find_mmc_device (dev); + +mmc_init (mmc); + + blklen = mmc->read_bl_len; + tmp_buf =malloc (blklen); +if (!tmp_buf) +return 1 ; + +/* read out the first block, get the config data information */ + ret =mmc_read (mmc,0 , tmp_buf, blklen); +if (ret) { +free (tmp_buf); +return 1 ; + } + +/* Get the Source Address, from offset 0x50 */ + code_offset = *(u32 *)(tmp_buf +ESDHC_BOOT_IMAGE_ADDR ); + +/* Get the code size from offset 0x48 */ + code_len = *(u32 *)(tmp_buf +ESDHC_BOOT_IMAGE_SIZE ); + + *env_addr = code_offset + code_len; + +free (tmp_buf); + +return 0 ; +} +#endif
include/configs/MPC8536DS.h +4 -1
@@ -633,7 +633,10 @@ extern unsigned long get_board_ddr_clk(unsigned long dummy);#define CONFIG_ENV_IS_IN_NAND 1#define CONFIG_ENV_SIZE CONFIG_SYS_NAND_BLOCK_SIZE#define CONFIG_ENV_OFFSET ((512 * 1024) + CONFIG_SYS_NAND_BLOCK_SIZE) -#elif defined(CONFIG_RAMBOOT_SPIFLASH ) || defined(CONFIG_RAMBOOT_SDCARD ) +#elif defined(CONFIG_RAMBOOT_SDCARD ) +#define CONFIG_ENV_IS_IN_SDCARD 1 +#define CONFIG_ENV_SIZE 0x2000 +#elif defined(CONFIG_RAMBOOT_SPIFLASH )#define CONFIG_ENV_IS_NOWHERE 1/* Store ENV in memory only */ #define CONFIG_ENV_ADDR (CONFIG_SYS_MONITOR_BASE - 0x1000)#define CONFIG_ENV_SIZE 0x2000
Signature · 1 line
1.6.4
PATCH 3/3 mpc8536: Get the address of env on the SDCard
Dear Mingkai Hu,
Quoted 8 lines · In message <[email protected]> you…
Both the save env and load env operation will call this function to get the address of env on the SDCard, so the user can control where to put the env freely.
Also enable the functionlity of saving env variable to SDCard on mpc8536
Signed-off-by Mingkai Hu <[email protected]>
...
board/freescale/mpc8536ds/mpc8536ds.c void ft_board_setup(void *blob, bd_t *bd) · line 691
Quoted 5 lines
board/freescale/mpc8536ds/mpc8536ds.c +5
-0+#if defined(CONFIG_MMC ) +/* +* The environment variables are written to just after the u-boot image +* on SDCard, so we must read the MBR to get the start address and code +* length of the u-boot image, then calculate the address of the env.
This seems to be broken by design. If your U-Boot image grows, it would overwrite the environment? Or am I missing something?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de If A equals success, then the formula is A = X + Y + Z. X is work. Y is play. Z is keep your mouth shut. - Albert Einstein
PATCH 3/3 mpc8536: Get the address of env on the SDCard
Quoted 9 lines
-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Wednesday, September 23, 2009 3:00 AM
To: Hu Mingkai-B21284
Cc: u-boot at lists.denx.de; Wood Scott-B07421; Gala Kumar-B11780
Subject: Re: [U-Boot] [PATCH v1 3/3] mpc8536: Get the address of env on the SDCard
Quoted 3 lines
This seems to be broken by design. If your U-Boot image grows, it would overwrite the environment? Or am I missing something?
Yes, if the U-Boot image grows, it would overwrite the env saved last time.
Maybe we should put it the to haed of the U-Boot image.
Thanks,
Mingkai
PATCH 2/3 Add support for save environment variable to MMC/SD card
In reply to Mingkai HuDear Mingkai Hu,
Quoted 4 lines · In message <[email protected]> you…
Whether booting from MMC/SD card or not, the environment variables can be saved on it, this patch add the operation support.
Signed-off-by Mingkai Hu <[email protected]>
...
common/Makefile COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o · line 65
Quoted 8 lines
common/Makefile +1
-0@@ -61,6 +61,7 @@ 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_SPI_FLASH) += env_sf.o +COBJS-$(CONFIG_ENV_IS_IN_SDCARD) += env_sdcard.o COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
Please keep the list sorted.
common/cmd_nvedit.c DECLARE_GLOBAL_DATA_PTR; · line 63
Quoted 10 lines
common/Makefile +0
-0# commandcommon/cmd_nvedit.c +1
-0@@ -60,9 +60,10 @@ DECLARE_GLOBAL_DATA_PTR; !defined (CONFIG_ENV_IS_IN_NVRAM ) && \ !defined (CONFIG_ENV_IS_IN_ONENAND ) && \ !defined (CONFIG_ENV_IS_IN_SPI_FLASH ) && \ + !defined(CONFIG_ENV_IS_IN_SDCARD) && \
Ditto.
common/cmd_nvedit.c DECLARE_GLOBAL_DATA_PTR; · line 66
Quoted 3 lines
common/cmd_nvedit.c +1
-1# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ -SPI_FLASH|MG_DISK|NVRAM|NOWHERE} +SPI_FLASH|MG_DISK|NVRAM|SDCARD|NOWHERE}
Please take the opportunity to sort this list, too. Thanks.
...
common/cmd_nvedit.c DECLARE_GLOBAL_DATA_PTR;
Quoted 5 lines
common/cmd_nvedit.c +5
-0+int env_init (void ) +{ +/* eSDHC isn't usable before relocation */ + gd->env_addr = (ulong)&default_environment[0 ]; + gd->env_valid =1 ;
Argh... Does that mean that your environment suddenly changes while running? That you start running from the default environment (which cannot be changed) and then switch to a the real, changable environment?
This is going to cause a hell of confusion to users who for example want to define a different console baud rate or such...
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de It is surely a great calamity for a human being to have no ob- sessions. - Robert Bly
PATCH 2/3 Add support for save environment variable to MMC/SD card
Quoted 20 lines
-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Wednesday, September 23, 2009 2:54 AM
To: Hu Mingkai-B21284
Cc: u-boot at lists.denx.de; Wood Scott-B07421; Gala Kumar-B11780
Subject: Re: [U-Boot] [PATCH v1 2/3] Add support for save environment variable to MMC/SD cardDear Mingkai Hu,
In message
Quoted 1 line · <[email protected]> you wrote:
Whether booting from MMC/SD card or not, the environment
variables can
Quoted 3 lines
be saved on it, this patch add the operation support.
Signed-off-by Mingkai Hu <[email protected]>...
Quoted 11 lines
common/Makefile COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o · line 65
Quoted 8 lines
common/Makefile +1
-0@@ -61,6 +61,7 @@ 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_SPI_FLASH) += env_sf.o +COBJS-$(CONFIG_ENV_IS_IN_SDCARD) += env_sdcard.o COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.oPlease keep the list sorted.
OK.
Quoted 4 lines
Quoted 4 lines
common/Makefile +0
-0# commandcommon/cmd_nvedit.c index renamed from common/cmd_nvedit.c +0
-02186205..83969ef 100644
---a/common/cmd_nvedit.c
Quoted 9 lines
common/cmd_nvedit.c index DECLARE_GLOBAL_DATA_PTR; · line 63
Quoted 6 lines
+++
b/common/cmd_nvedit.ccommon/cmd_nvedit.c index renamed from common/cmd_nvedit.c +1
-0@@ -60,9 +60,10 @@ DECLARE_GLOBAL_DATA_PTR; !defined(CONFIG_ENV_IS_IN_NVRAM) && \ !defined(CONFIG_ENV_IS_IN_ONENAND) && \ !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \ + !defined(CONFIG_ENV_IS_IN_SDCARD) && \Ditto.
OK.
Quoted 7 lines
common/cmd_nvedit.c index DECLARE_GLOBAL_DATA_PTR; · line 66
Quoted 4 lines
common/cmd_nvedit.c index renamed from common/cmd_nvedit.c +1
-1# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ -SPI_FLASH|MG_DISK|NVRAM|NOWHERE} +SPI_FLASH|MG_DISK|NVRAM|SDCARD|NOWHERE}Please take the opportunity to sort this list, too. Thanks.
OK.
Quoted 12 lines
...
common/cmd_nvedit.c index
Quoted 5 lines
common/cmd_nvedit.c index renamed from common/cmd_nvedit.c +5
-0+int env_init(void) +{ + /* eSDHC isn't usable before relocation */ + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1;Argh... Does that mean that your environment suddenly changes while running? That you start running from the default environment (which cannot be changed) and then switch to a the real, changable environment?
Yes. I refered to env_sf.c file, maybe it has the same issue.
Quoted 3 lines
This is going to cause a hell of confusion to users who for example want to define a different console baud rate or such...
It's a problem.
Thanks,
Mingkai
PATCH 1/3 Make mmc init come before env_relocate
In reply to Mingkai HuDear Mingkai Hu,
Quoted 4 lines · In message <[email protected]> you…
If the environment variables are saved on the MMC/SD card,
env_relocatcan't relocate env from MMC/SD card without mmc init.Signed-off-by Mingkai Hu <[email protected]>
I'm biased. I understand that you do this because you need it for the next patch, which reads the environment from MMC card. But then MMC is just one out of many storage devices, and with the same right we would have to move the SCSI or DoC or S-ATA initialization up, because we could implement storing the environment on such devices, too.
This has not been done so far, because it suffers from the fundamental problem your code is suffering from, too: you cannot access the environment early enough, so for example your board boots with a hard-wird, unchangable console baud rate, despite that you suggest to the user he could change it.
I don't like that, and therefore tend to NAK the whole approach.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Don't hit a man when he's down - kick him; it's easier.
PATCH 1/3 Make mmc init come before env_relocate
Quoted 10 lines
-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Wednesday, September 23, 2009 2:58 AM
To: Hu Mingkai-B21284
Cc: u-boot at lists.denx.de; Wood Scott-B07421; Gala Kumar-B11780
Subject: Re: [U-Boot] [PATCH v1 1/3] Make mmc init come beforeenv_relocate
Quoted 6 lines
This has not been done so far, because it suffers from the fundamental problem your code is suffering from, too: you cannot access the environment early enough, so for example your board boots with a hard-wird, unchangable console baud rate, despite that you suggest to the user he could change it.
Got it.
Quoted 2 lines
I don't like that, and therefore tend to NAK the whole approach.
No problem, after all this patchset is not matured enough.
Thanks,
Mingkai
PATCH 1/3 Make mmc init come before env_relocate
In reply to Wolfgang DenkDear Wolfgang Denk,
Quoted 6 lines
I'm biased. I understand that you do this because you need it for the next patch, which reads the environment from MMC card. But then MMC is just one out of many storage devices, and with the same right we would h ave to move the SCSI or DoC or S-ATA initialization up, because we could implement storing the environment on such devices, too.
Quoted 7 lines
This has not been done so far, because it suffers from the fundamental problem your code is suffering from, too: you cannot access the environment early enough, so for example your board boots with a hard-wird, unchangable console baud rate, despite that you suggest to the user he could change it.
I don't like that, and therefore tend to NAK the whole approach.
I understand why you would like to NAK the approach, but this is not only interesting for this type of ARM. And more and more ARM devices allow direct boot from SD-Card,... and so everybody ask for that I need another storage just for the environment variables. In the production you also have to program this storage. So I think you will get this question more and more. Or more and more patches that are not in the mainline.
For me the question is if where a good way to implement this feature? Do you have a good suggestion for solving the problem of initializations steps?
I would really like to help to get this problem solved, because I'm building at the moment an G20/G45 board that doing the same thing.
bye
Konrad Mattheis
PATCH 1/3 Make mmc init come before env_relocate
Dear Konrad Mattheis,
Quoted 10 lines · In message <F32E8C2599F37641BB4E3F3AC4A3C412016D265C4FE3@ws> you wrote:
Quoted 2 lines
I don't like that, and therefore tend to NAK the whole approach.
I understand why you would like to NAK the approach, but this is not only interesting for this type of ARM. And more and more ARM devices allow direct boot from SD-Card,... and so everybody ask for that I need another storage just for the environment variables. In the production you also have to program this storage. So I think you will get this question more and more. Or more and more patches that are not in the mainline.
I understand the requirements, but I disagree with your conclusions, and with the implementation.
Booting from some storage device (whatever it may be) is one thing, but selecting the storage medium for the U-Boot environment is a different thing.
Quoted 3 lines
For me the question is if where a good way to implement this feature? Do you have a good suggestion for solving the problem of initializations steps?
Well, there are IMO two fundamental questions:
1) Where do we store the environment?
Even if you load the U-Boot binary from - say - MMC/SDCard, there is most probably also another storage medium available on your board which may be easier to use (i. e. available before relocation to RAM) and thus more appropriate to use.
Also, not storing the environment on changable media has the affect that it will allow for persistent settings even when you change the mdium you boot from. This may or may not be an advantage, depending on your requirements. My guess is that it would be an advantage in most applications.
2) How do we implement this?
Assuming you load the U-Boot binary from - say - MMC/SDCard, you must already have some code running that can do this. Then why should that very same code not be able to load the envrionment from the same MMC/SDCard as well? In the worst case you could make it one big blob that gets loaded in one go.
Why do you think we need U-Boot's MMC/SDCard drivers to perform the initial load of the environment from the external storage?
Thus I suggest two approaches to solve the problem, which both have their specific features and advantages, and probably should be not considered as alternatives, but used in combination, at least optionally.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de We, the unwilling, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, for so long, with so little, we are now qualified to do anything with nothing.
PATCH 1/3 Make mmc init come before env_relocate
Dear Wofgang Denk,
Quoted 9 lines
Well, there are IMO two fundamental questions:
1) Where do we store the environment?
Even if you load the U-Boot binary from - say - MMC/SDCard, there is most probably also another storage medium available on your board which may be easier to use (i. e. available before relocation to RAM) and thus more appropriate to use.
Quoted 5 lines
Also, not storing the environment on changable media has the affect that it will allow for persistent settings even when you change the mdium you boot from. This may or may not be an advantage, depending on your requirements. My guess is that it would be an advantage in most applications.
I understand the advantages for storing the settings on the board, but I thing this problem is already perfectly solved. So for that type of applications there is nothing to do.
But for the other type I'm searching for a good way. Some reasons this way is also important:
1. If I have two same hardware boards I just have to change the storage card and the new hardware work in the same way (this is very important for warranty or support problems)
2. At mass production I don't need to program /flash something
Quoted 8 lines
2) How do we implement this?
Assuming you load the U-Boot binary from - say - MMC/SDCard, you must already have some code running that can do this. Then why should that very same code not be able to load the envrionment from the same MMC/SDCard as well? In the worst case you could make it one big blob that gets loaded in one go.
Quoted 8 lines
Why do you think we need U-Boot's MMC/SDCard drivers to perform the initial load of the environment from the external storage?
Thus I suggest two approaches to solve the problem, which both have their specific features and advantages, and probably should be not considered as alternatives, but used in combination, at least optionally.
For the implementation I have now this Idea:
The environment variables can be attached to the uboot-binary. This could be in the begin or end of the file and both have some advantages and disadvantages, but this we could discuss later.
At boot time the u-boot has the possibility to get this environment variables without any driver, because there are in flash or copied into the ram. So the u-boot just have to look at position if it find these variables and then will use them.
If you want to change these variables you have two possibilities.
1. do it in u-boot, u-boot load the driver for the storage and then can write on
2. do in later high level linux/win (there it could be good to deliver an easy c code for the users)
With this solution you also solve the problem with Scott Wood solution, because you already have the right env. variables at the start time. So no problem with serial,...
Best regards,
Konrad Mattheis
PATCH 1/3 Make mmc init come before env_relocate
In reply to Wolfgang DenkQuoted 6 lines · Wolfgang Denk
I'm biased. I understand that you do this because you need it for the next patch, which reads the environment from MMC card. But then MMC is just one out of many storage devices, and with the same right we would have to move the SCSI or DoC or S-ATA initialization up, because we could implement storing the environment on such devices, too.
Quoted 7 lines
This has not been done so far, because it suffers from the fundamental problem your code is suffering from, too: you cannot access the environment early enough, so for example your board boots with a hard-wird, unchangable console baud rate, despite that you suggest to the user he could change it.
I don't like that, and therefore tend to NAK the whole approach.
The same applies to NAND. The CONFIG_NAND_ENV_DST mechanism makes it a bit better (the first stage loader puts the environment in a designated part of RAM); perhaps something similar could be done here?
There's still a problem with doing any console output during the first stage loading itself (such as to indicate failures). For that, the best I can think of would be to have a CONFIG option for a hardcoded baud, and if you leave it undefined you will get no output until the second stage.
-Scott