Skip to content

Commit 03fb08d

Browse files
Ansueltrini
authored andcommitted
env: Introduce support for MTD
Introduce support for env in generic MTD. Currently we only support SPI flash based on the lagacy sf cmd that assume SPI flash are always NOR. This is not the case as to SPI controller also NAND can be attached. To support also these flash scenario, add support for storing and reading ENV from generic MTD device by adding an env driver that base entirely on the MTD api. Introduce a new kconfig CONFIG_ENV_IS_IN_MTD and CONFIG_ENV_MTD_DEV to define the name of the MTD device as exposed by mtd list. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
1 parent f717d79 commit 03fb08d

File tree

5 files changed

+372
-4
lines changed

5 files changed

+372
-4
lines changed

env/Kconfig

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ config ENV_IS_DEFAULT
7474
!ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
7575
!ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
7676
!ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
77-
!ENV_IS_IN_UBI
77+
!ENV_IS_IN_UBI && !ENV_IS_IN_MTD
7878
select ENV_IS_NOWHERE
7979

8080
config ENV_IS_NOWHERE
@@ -387,6 +387,25 @@ config ENV_IS_IN_SPI_FLASH
387387
during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
388388
aligned to an erase sector boundary.
389389

390+
config ENV_IS_IN_MTD
391+
bool "Environment is in MTD flash"
392+
depends on !CHAIN_OF_TRUST && (SPI_FLASH || DM_SPI_FLASH)
393+
default y if ARCH_AIROHA
394+
help
395+
Define this if you have a MTD Flash memory device which you
396+
want to use for the environment.
397+
398+
- CONFIG_ENV_MTD_DEV:
399+
400+
Specifies which SPI NAND device the environment is stored in.
401+
402+
- CONFIG_ENV_OFFSET:
403+
- CONFIG_ENV_SIZE:
404+
405+
These two #defines specify the offset and size of the
406+
environment area within the MTD Flash.
407+
CONFIG_ENV_OFFSET must be aligned to an erase sector boundary.
408+
390409
config ENV_SECT_SIZE_AUTO
391410
bool "Use automatically detected sector size"
392411
depends on ENV_IS_IN_SPI_FLASH
@@ -562,8 +581,8 @@ config ENV_EXT4_FILE
562581
config ENV_ADDR
563582
hex "Environment address"
564583
depends on ENV_IS_IN_FLASH || ENV_IS_IN_NVRAM || ENV_IS_IN_ONENAND || \
565-
ENV_IS_IN_REMOTE || ENV_IS_IN_SPI_FLASH
566-
default 0x0 if ENV_IS_IN_SPI_FLASH
584+
ENV_IS_IN_REMOTE || ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
585+
default 0x0 if ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
567586
help
568587
Offset from the start of the device (or partition)
569588

@@ -577,7 +596,7 @@ config ENV_ADDR_REDUND
577596
config ENV_OFFSET
578597
hex "Environment offset"
579598
depends on ENV_IS_IN_EEPROM || ENV_IS_IN_MMC || ENV_IS_IN_NAND || \
580-
ENV_IS_IN_SPI_FLASH
599+
ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
581600
default 0x3f8000 if ARCH_ROCKCHIP && ENV_IS_IN_MMC
582601
default 0x140000 if ARCH_ROCKCHIP && ENV_IS_IN_SPI_FLASH
583602
default 0xF0000 if ARCH_SUNXI
@@ -666,6 +685,12 @@ config SYS_RELOC_GD_ENV_ADDR
666685
Relocate the early env_addr pointer so we know it is not inside
667686
the binary. Some systems need this and for the rest, it doesn't hurt.
668687

688+
config ENV_MTD_DEV
689+
string "mtd device name"
690+
depends on ENV_IS_IN_MTD
691+
help
692+
MTD device name on the platform where the environment is stored.
693+
669694
config SYS_MMC_ENV_DEV
670695
int "mmc device number"
671696
depends on ENV_IS_IN_MMC || ENV_IS_IN_FAT || ENV_IS_IN_EXT4 || \

env/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ obj-$(CONFIG_$(PHASE_)ENV_IS_IN_FAT) += fat.o
2626
obj-$(CONFIG_$(PHASE_)ENV_IS_IN_EXT4) += ext4.o
2727
obj-$(CONFIG_$(PHASE_)ENV_IS_IN_NAND) += nand.o
2828
obj-$(CONFIG_$(PHASE_)ENV_IS_IN_SPI_FLASH) += sf.o
29+
obj-$(CONFIG_$(PHASE_)ENV_IS_IN_MTD) += mtd.o
2930
obj-$(CONFIG_$(PHASE_)ENV_IS_IN_FLASH) += flash.o
3031

3132
CFLAGS_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)

env/env.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static enum env_location env_locations[] = {
5858
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
5959
ENVL_SPI_FLASH,
6060
#endif
61+
#ifdef CONFIG_ENV_IS_IN_MTD
62+
ENVL_MTD,
63+
#endif
6164
#ifdef CONFIG_ENV_IS_IN_UBI
6265
ENVL_UBI,
6366
#endif

0 commit comments

Comments
 (0)