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>
diff --git a/env/Kconfig b/env/Kconfig
index 9507aee..9f5ec44 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -74,7 +74,7 @@
!ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
!ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
!ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
- !ENV_IS_IN_UBI
+ !ENV_IS_IN_UBI && !ENV_IS_IN_MTD
select ENV_IS_NOWHERE
config ENV_IS_NOWHERE
@@ -387,6 +387,25 @@
during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be
aligned to an erase sector boundary.
+config ENV_IS_IN_MTD
+ bool "Environment is in MTD flash"
+ depends on !CHAIN_OF_TRUST && (SPI_FLASH || DM_SPI_FLASH)
+ default y if ARCH_AIROHA
+ help
+ Define this if you have a MTD Flash memory device which you
+ want to use for the environment.
+
+ - CONFIG_ENV_MTD_DEV:
+
+ Specifies which SPI NAND device the environment is stored in.
+
+ - CONFIG_ENV_OFFSET:
+ - CONFIG_ENV_SIZE:
+
+ These two #defines specify the offset and size of the
+ environment area within the MTD Flash.
+ CONFIG_ENV_OFFSET must be aligned to an erase sector boundary.
+
config ENV_SECT_SIZE_AUTO
bool "Use automatically detected sector size"
depends on ENV_IS_IN_SPI_FLASH
@@ -562,8 +581,8 @@
config ENV_ADDR
hex "Environment address"
depends on ENV_IS_IN_FLASH || ENV_IS_IN_NVRAM || ENV_IS_IN_ONENAND || \
- ENV_IS_IN_REMOTE || ENV_IS_IN_SPI_FLASH
- default 0x0 if ENV_IS_IN_SPI_FLASH
+ ENV_IS_IN_REMOTE || ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
+ default 0x0 if ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
help
Offset from the start of the device (or partition)
@@ -577,7 +596,7 @@
config ENV_OFFSET
hex "Environment offset"
depends on ENV_IS_IN_EEPROM || ENV_IS_IN_MMC || ENV_IS_IN_NAND || \
- ENV_IS_IN_SPI_FLASH
+ ENV_IS_IN_SPI_FLASH || ENV_IS_IN_MTD
default 0x3f8000 if ARCH_ROCKCHIP && ENV_IS_IN_MMC
default 0x140000 if ARCH_ROCKCHIP && ENV_IS_IN_SPI_FLASH
default 0xF0000 if ARCH_SUNXI
@@ -666,6 +685,12 @@
Relocate the early env_addr pointer so we know it is not inside
the binary. Some systems need this and for the rest, it doesn't hurt.
+config ENV_MTD_DEV
+ string "mtd device name"
+ depends on ENV_IS_IN_MTD
+ help
+ MTD device name on the platform where the environment is stored.
+
config SYS_MMC_ENV_DEV
int "mmc device number"
depends on ENV_IS_IN_MMC || ENV_IS_IN_FAT || ENV_IS_IN_EXT4 || \