Support dynamic/patched NAND ENV offset
PATCH 1/1 Support dynamic/patched NAND ENV offset
This patch adds support for CFG_ENV_OFFSET_PATCHED and CFG_ENV_OFFSET_OOB.
Both try to solve the problem of fixing the environment location in NAND flash at compile time, which doesn't work well if the NAND flash has a bad block at exactly that location.
CFG_ENV_OFFSET_PATCHED puts the environment in a global variable. You can then use the linker script to put that variable to a fixed location in the u-boot image. Then you can use bianry patching during the production flash process.
The idea of CFG_ENV_OFFSET_OOB is to store the environment offset in the NAND OOB data of block 0. We can do this in case the vendor makes a guarantee that block 0 never is a factory-default bad block.
common/env_nand.c +27 -0
@@ -271,6 +271,33 @@ulong total;int ret; +#if defined(CFG_ENV_OFFSET_OOB ) +struct mtd_info *mtd = &nand_info[0 ]; +struct nand_chip *this = mtd->priv; +int buf_len; +uint8_t *buf; + + buf_len = (1 << this->bbt_erase_shift); + buf_len += (buf_len >> this->page_shift) * mtd->oobsize; + buf =malloc (buf_len); +if (!buf) +return ; + +nand_read_raw (mtd, buf,0 , mtd->oobblock, mtd->oobsize); +if (buf[mtd->oobblock +8 +0 ] =='E' && + buf[mtd->oobblock +8 +1 ] =='N' && + buf[mtd->oobblock +8 +2 ] =='V' && + buf[mtd->oobblock +8 +3 ] =='0' ) { +CFG_ENV_OFFSET = *((unsigned long *) &buf[mtd->oobblock +8 +4 ]); +/* fall through to the normal environment reading code below */ +free (buf); +puts ("Found Environment offset in OOB..\n" ); + }else { +free (buf); +return use_default (); + } +#endif + total =CFG_ENV_SIZE ; ret =nand_read (&nand_info[0 ],CFG_ENV_OFFSET , &total, (u_char *)env_ptr);if (ret || total !=CFG_ENV_SIZE )
common/environment.c +6 -0
@@ -29,6 +29,12 @@#undef __ASSEMBLY__#include <environment.h> +#if defined(CFG_ENV_OFFSET_PATCHED ) +unsigned long env_offset =CFG_ENV_OFFSET_PATCHED ; +#elif defined(CFG_ENV_OFFSET_OOB ) +unsigned long env_offset =CFG_ENV_OFFSET_OOB ; +#endif +/* * Handle HOSTS that have prepended * crap on symbol names, not TARGETS.
include/environment.h +5 -0
@@ -70,6 +70,10 @@#endif /* CFG_ENV_IS_IN_FLASH */ #if defined(CFG_ENV_IS_IN_NAND ) +#if defined(CFG_ENV_OFFSET_PATCHED ) || defined(CFG_ENV_OFFSET_OOB ) +extern unsigned long env_offset; +#define CFG_ENV_OFFSET env_offset +#else # ifndef CFG_ENV_OFFSET # error "Need to define CFG_ENV_OFFSET when using CFG_ENV_IS_IN_NAND"# endif
@@ -82,6 +86,7 @@# ifdef CFG_ENV_IS_EMBEDDED # define ENV_IS_EMBEDDED 1# endif +#endif /* CFG_ENV_NAND_PATCHED */ #endif /* CFG_ENV_IS_IN_NAND */
include/configs/neo1973.h +1 -1
@@ -197,7 +197,7 @@#define CFG_ENV_IS_IN_NAND 1#define CFG_ENV_SIZE 0x4000/* 16k Total Size of Environment Sector */ -#define CFG_ENV_OFFSET 0x30000/* environment after bootloader */ +#define CFG_ENV_OFFSET_OOB 1/* Location of ENV stored in block 0 OOB */ #define NAND_MAX_CHIPS 1#define CFG_NAND_BASE 0x4e000000
common/Makefile +1 -1
@@ -32,7 +32,7 @@ cmd_bdinfo.o cmd_bedbug.o cmd_bmp.o cmd_boot.o cmd_bootm.o \ cmd_cache.o cmd_console.o \ cmd_date.o cmd_dcr.o cmd_diag.o cmd_display.o cmd_doc.o cmd_dtt.o \ - cmd_eeprom.o cmd_elf.o cmd_ext2.o \ + cmd_dynenv.o cmd_eeprom.o cmd_elf.o cmd_ext2.o \ cmd_fat.o cmd_fdc.o cmd_fdos.o cmd_flash.o cmd_fpga.o \ cmd_i2c.o cmd_ide.o cmd_immap.o cmd_itest.o cmd_jffs2.o \ cmd_load.o cmd_log.o \
common/cmd_dynenv.c new file +85 -0
85 lines not on this page · raw message
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone
PATCH 1/1 Support dynamic/patched NAND ENV offset
Sorry, the previous one was 'polluted' by a change to neo1973.h, which is not [yet?] in the current u-boot git tree.
Here is a cleaned up version:
This patch adds support for CFG_ENV_OFFSET_PATCHED and CFG_ENV_OFFSET_OOB.
Both try to solve the problem of fixing the environment location in NAND flash at compile time, which doesn't work well if the NAND flash has a bad block at exactly that location.
CFG_ENV_OFFSET_PATCHED puts the environment in a global variable. You can then use the linker script to put that variable to a fixed location in the u-boot image. Then you can use bianry patching during the production flash process.
The idea of CFG_ENV_OFFSET_OOB is to store the environment offset in the NAND OOB data of block 0. We can do this in case the vendor makes a guarantee that block 0 never is a factory-default bad block.
common/env_nand.c +27 -0
@@ -271,6 +271,33 @@ulong total;int ret; +#if defined(CFG_ENV_OFFSET_OOB ) +struct mtd_info *mtd = &nand_info[0 ]; +struct nand_chip *this = mtd->priv; +int buf_len; +uint8_t *buf; + + buf_len = (1 << this->bbt_erase_shift); + buf_len += (buf_len >> this->page_shift) * mtd->oobsize; + buf =malloc (buf_len); +if (!buf) +return ; + +nand_read_raw (mtd, buf,0 , mtd->oobblock, mtd->oobsize); +if (buf[mtd->oobblock +8 +0 ] =='E' && + buf[mtd->oobblock +8 +1 ] =='N' && + buf[mtd->oobblock +8 +2 ] =='V' && + buf[mtd->oobblock +8 +3 ] =='0' ) { +CFG_ENV_OFFSET = *((unsigned long *) &buf[mtd->oobblock +8 +4 ]); +/* fall through to the normal environment reading code below */ +free (buf); +puts ("Found Environment offset in OOB..\n" ); + }else { +free (buf); +return use_default (); + } +#endif + total =CFG_ENV_SIZE ; ret =nand_read (&nand_info[0 ],CFG_ENV_OFFSET , &total, (u_char *)env_ptr);if (ret || total !=CFG_ENV_SIZE )
common/environment.c +6 -0
@@ -29,6 +29,12 @@#undef __ASSEMBLY__#include <environment.h> +#if defined(CFG_ENV_OFFSET_PATCHED ) +unsigned long env_offset =CFG_ENV_OFFSET_PATCHED ; +#elif defined(CFG_ENV_OFFSET_OOB ) +unsigned long env_offset =CFG_ENV_OFFSET_OOB ; +#endif +/* * Handle HOSTS that have prepended * crap on symbol names, not TARGETS.
include/environment.h +5 -0
@@ -70,6 +70,10 @@#endif /* CFG_ENV_IS_IN_FLASH */ #if defined(CFG_ENV_IS_IN_NAND ) +#if defined(CFG_ENV_OFFSET_PATCHED ) || defined(CFG_ENV_OFFSET_OOB ) +extern unsigned long env_offset; +#define CFG_ENV_OFFSET env_offset +#else # ifndef CFG_ENV_OFFSET # error "Need to define CFG_ENV_OFFSET when using CFG_ENV_IS_IN_NAND"# endif
@@ -82,6 +86,7 @@# ifdef CFG_ENV_IS_EMBEDDED # define ENV_IS_EMBEDDED 1# endif +#endif /* CFG_ENV_NAND_PATCHED */ #endif /* CFG_ENV_IS_IN_NAND */
common/Makefile +1 -1
@@ -32,7 +32,7 @@ cmd_bdinfo.o cmd_bedbug.o cmd_bmp.o cmd_boot.o cmd_bootm.o \ cmd_cache.o cmd_console.o \ cmd_date.o cmd_dcr.o cmd_diag.o cmd_display.o cmd_doc.o cmd_dtt.o \ - cmd_eeprom.o cmd_elf.o cmd_ext2.o \ + cmd_dynenv.o cmd_eeprom.o cmd_elf.o cmd_ext2.o \ cmd_fat.o cmd_fdc.o cmd_fdos.o cmd_flash.o cmd_fpga.o \ cmd_i2c.o cmd_ide.o cmd_immap.o cmd_itest.o cmd_jffs2.o \ cmd_load.o cmd_log.o \
common/cmd_dynenv.c new file +85 -0
85 lines not on this page · raw message
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone