/* * SPDX-License-Identifier: BSD-3-Clause * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors * */ #ifndef __FLASH_LAYOUT_H__ #define __FLASH_LAYOUT_H__ #include "hardware/regs/addressmap.h" /* Coming from SDK */ #define FLASH_S_PARTITION_SIZE (0x60000) /* 384 kB */ #define FLASH_NS_PARTITION_SIZE (0x60000) /* 384 kB */ #define FLASH_MAX_PARTITION_SIZE FLASH_S_PARTITION_SIZE /* Sector size of the flash hardware; same as FLASH0_SECTOR_SIZE */ #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4 kB */ /* Same as FLASH0_SIZE */ #define FLASH_TOTAL_SIZE (0x200000) /* 2MB */ #if ((FLASH_S_PARTITION_SIZE % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0) #error "Secure image size should be a multiple of flash sector size!" #endif #if ((FLASH_NS_PARTITION_SIZE % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0) #error "Non-secure image size should be a multiple of flash sector size!" #endif /* Flash layout info for BL2 bootloader */ #define FLASH_BASE_ADDRESS (XIP_BASE) /* Offset and size definitions of the flash partitions that are handled by the * bootloader. The image swapping is done between IMAGE_PRIMARY and * IMAGE_SECONDARY, SCRATCH is used as a temporary storage during image * swapping. */ #define FLASH_AREA_BL2_OFFSET (0x0) #define FLASH_AREA_BL2_SIZE (0x11000) /* 68 kB */ #if !defined(MCUBOOT_IMAGE_NUMBER) || (MCUBOOT_IMAGE_NUMBER == 1) /* Secure + Non-secure image primary slot */ #define FLASH_AREA_0_ID (1) #define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE + \ FLASH_NS_PARTITION_SIZE) /* Secure + Non-secure secondary slot */ #define FLASH_AREA_2_ID (FLASH_AREA_0_ID + 1) #define FLASH_AREA_2_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE + \ FLASH_NS_PARTITION_SIZE) /* Scratch area */ #define FLASH_AREA_SCRATCH_ID (FLASH_AREA_2_ID + 1) #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) #define FLASH_AREA_SCRATCH_SIZE (0x8000) /* 32 kB */ /* The maximum number of status entries supported by the bootloader. */ #define MCUBOOT_STATUS_MAX_ENTRIES ((FLASH_S_PARTITION_SIZE + \ FLASH_NS_PARTITION_SIZE) / \ FLASH_AREA_SCRATCH_SIZE) /* Maximum number of image sectors supported by the bootloader. */ #define MCUBOOT_MAX_IMG_SECTORS ((FLASH_S_PARTITION_SIZE + \ FLASH_NS_PARTITION_SIZE) / \ FLASH_AREA_IMAGE_SECTOR_SIZE) #elif (MCUBOOT_IMAGE_NUMBER == 2) /* Secure image primary slot */ #define FLASH_AREA_0_ID (1) #define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) /* Non-secure image primary slot */ #define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) #define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) #define FLASH_AREA_1_SIZE (FLASH_NS_PARTITION_SIZE) /* Secure image secondary slot */ #define FLASH_AREA_2_ID (FLASH_AREA_1_ID + 1) #define FLASH_AREA_2_OFFSET (FLASH_AREA_1_OFFSET + FLASH_AREA_1_SIZE) #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) /* Non-secure image secondary slot */ #define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) #define FLASH_AREA_3_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) #define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) /* Scratch area */ #define FLASH_AREA_SCRATCH_ID (FLASH_AREA_3_ID + 1) #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_3_OFFSET + FLASH_AREA_3_SIZE) #define FLASH_AREA_SCRATCH_SIZE (0x8000) /* 32 kB */ /* The maximum number of status entries supported by the bootloader. */ #define MCUBOOT_STATUS_MAX_ENTRIES (FLASH_MAX_PARTITION_SIZE / \ FLASH_AREA_SCRATCH_SIZE) /* Maximum number of image sectors supported by the bootloader. */ #define MCUBOOT_MAX_IMG_SECTORS (FLASH_MAX_PARTITION_SIZE / \ FLASH_AREA_IMAGE_SECTOR_SIZE) #else /* MCUBOOT_IMAGE_NUMBER > 2 */ #error "Only MCUBOOT_IMAGE_NUMBER 1 and 2 are supported!" #endif /* MCUBOOT_IMAGE_NUMBER */ /* Protected Storage (PS) Service definitions */ #define FLASH_PS_AREA_OFFSET (FLASH_AREA_SCRATCH_OFFSET + \ FLASH_AREA_SCRATCH_SIZE) #define FLASH_PS_AREA_SIZE (2 * FLASH_AREA_IMAGE_SECTOR_SIZE) /* 8 kB */ /* Internal Trusted Storage (ITS) Service definitions */ #define FLASH_ITS_AREA_OFFSET (FLASH_PS_AREA_OFFSET + \ FLASH_PS_AREA_SIZE) #define FLASH_ITS_AREA_SIZE (2 * FLASH_AREA_IMAGE_SECTOR_SIZE) /* 8 kB */ /* OTP_definitions */ #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_ITS_AREA_OFFSET + \ FLASH_ITS_AREA_SIZE) #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (2 * FLASH_AREA_IMAGE_SECTOR_SIZE) /* 8 kB */ #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE #if (((FLASH_OTP_NV_COUNTERS_AREA_SIZE % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0) || \ (FLASH_OTP_NV_COUNTERS_AREA_SIZE < (2 * FLASH_OTP_NV_COUNTERS_SECTOR_SIZE)) || \ (((FLASH_OTP_NV_COUNTERS_AREA_SIZE / FLASH_OTP_NV_COUNTERS_SECTOR_SIZE) % 2) != 0) \ ) #error "NV_COUNTERS should be a multiple of block size and total number of blocks should be more greater than or equal to 2 and even." #endif #if ( FLASH_OTP_NV_COUNTERS_AREA_OFFSET + FLASH_OTP_NV_COUNTERS_AREA_SIZE > FLASH_TOTAL_SIZE) #error "Out of flash memory!" #endif /* Offset and size definition in flash area used by assemble.py */ #define SECURE_IMAGE_OFFSET (0x0) #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + \ SECURE_IMAGE_MAX_SIZE) #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE /* Flash device name used by BL2 * Name is defined in flash driver file: Driver_Flash_RPI.c */ #define FLASH_DEV_NAME RP2350_FLASH /* Smallest flash programmable unit in bytes */ #define TFM_HAL_FLASH_PROGRAM_UNIT (0x100) /* Protected Storage (PS) Service definitions * Note: Further documentation of these definitions can be found in the * TF-M PS Integration Guide. */ #define TFM_HAL_PS_FLASH_DRIVER RP2350_FLASH /* In this target the CMSIS driver requires only the offset from the base * address instead of the full memory address. */ /* Base address of dedicated flash area for PS */ #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET /* Size of dedicated flash area for PS */ #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE #define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE /* Number of physical erase sectors per logical FS block */ #define TFM_HAL_PS_SECTORS_PER_BLOCK (1) /* Smallest flash programmable unit in bytes */ #define TFM_HAL_PS_PROGRAM_UNIT TFM_HAL_FLASH_PROGRAM_UNIT #define PS_FLASH_NAND_BUF_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE) #if (((TFM_HAL_PS_FLASH_AREA_SIZE % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0) || \ ((TFM_HAL_PS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 0) || \ ((TFM_HAL_PS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 1) || \ ((TFM_HAL_PS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 3) \ ) #error "PS area size should be a multiple of block size and total number of blocks can not be 0, 1 or 3." #endif /* Internal Trusted Storage (ITS) Service definitions * Note: Further documentation of these definitions can be found in the * TF-M ITS Integration Guide. The ITS should be in the internal flash, but is * allocated in the external flash just for development platforms that don't * have internal flash available. */ #define TFM_HAL_ITS_FLASH_DRIVER RP2350_FLASH /* In this target the CMSIS driver requires only the offset from the base * address instead of the full memory address. */ /* Base address of dedicated flash area for ITS */ #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET /* Size of dedicated flash area for ITS */ #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE #define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE /* Number of physical erase sectors per logical FS block */ #define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) /* Smallest flash programmable unit in bytes */ #define TFM_HAL_ITS_PROGRAM_UNIT TFM_HAL_FLASH_PROGRAM_UNIT #define ITS_FLASH_NAND_BUF_SIZE (2 * FLASH_AREA_IMAGE_SECTOR_SIZE) #if (((TFM_HAL_ITS_FLASH_AREA_SIZE % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0) || \ ((TFM_HAL_ITS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 0) || \ ((TFM_HAL_ITS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 1) || \ ((TFM_HAL_ITS_FLASH_AREA_SIZE / FLASH_AREA_IMAGE_SECTOR_SIZE) == 3) \ ) #error "ITS area size should be a multiple of block size and total number of blocks can not be 0, 1 or 3." #endif /* OTP / NV counter definitions */ #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ TFM_OTP_NV_COUNTERS_AREA_SIZE) #endif /* __FLASH_LAYOUT_H__ */