Memory Interface

Abstract memory interface. More...

## Data Structures

struct | memory_interface_t
| Interface to memory operations. More...
struct | memory_region_interface_t
| Interface to memory operations for one region of memory. More...
struct | memory_map_entry_t
| Structure of a memory map entry. More...

## Enumerations

enum

_memory_interface_status {
kStatusMemoryRangeInvalid = MAKE_STATUS(kStatusGroup_MemoryInterface, 0),
kStatusMemoryReadFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 1),
kStatusMemoryWriteFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 2),
kStatusMemoryCumulativeWrite = MAKE_STATUS(kStatusGroup_MemoryInterface, 3),
kStatusMemoryAppOverlapWithExecuteOnlyRegion = MAKE_STATUS(kStatusGroup_MemoryInterface, 4)
}

| Memory interface status codes.
enum | { kMemoryNotExecutable = false, kMemoryIsExecutable = true }
enum | _memorymap_constants { kIndexFlashArray = 0, kIndexSRAM = 1, kIndexDTCM = 2, kIndexOCRAM = 3, kIndexQspiMemory = 2, kIndexQspiAliasArea = 3, kSRAMSeparatrix = (uint32_t)0x20000000 }
| Memory Map index constants. More...
enum | flash_erase_all_option_t { kFlashEraseAllOption_Blocks = 0, kFlashEraseAllOption_ExecuteOnlySegments = 1 }
| flash memory erase all options.

## Functions

void | host_flash_erase_all (void)
| Erase all flash.
void | host_flash_erase_all_unsecure (void)
| Erase all flash (unsecure).
void | host_flash_erase_region (uint32_t address, uint32_t count)
| Erase a region of flash.

## Variables

memory_map_entry_t | g_memoryMap []
| Memory map for the system.
static const memory_region_interface_t * | s_flushMemoryInterface = NULL
| This variable is used to do flush operation, it is bind to write operation.
const memory_interface_t | g_memoryInterface
| Interface to generic memory operations. More...

## Memory interfaces

const memory_interface_t | g_memoryInterface
| Abstract memory interface. More...
const memory_region_interface_t | g_flashMemoryInterface
| Flash memory interface. More...
const memory_region_interface_t | g_normalMemoryInterface
| Memory interface for memory with Normal type. More...
const memory_region_interface_t | g_normalDTCMInterface
| Memory interface for memory with Normal type. More...
const memory_region_interface_t | g_normalOCRAMInterface
| Memory interface for memory with Normal type. More...
const memory_region_interface_t | g_deviceMemoryInterface
| Memory interface for memory with Device or Strongly-ordered type. More...
const memory_region_interface_t | g_qspiMemoryInterface
| Interface to qspi memory operations.
const memory_region_interface_t | g_qspiAliasAreaInterface
| Interface to qspi alias area operations.

## Generic memory interface implementation

status_t | mem_init (void)
| Initialize memory interface.
status_t | mem_read (uint32_t address, uint32_t length, uint8_t *buffer)
| Read memory.
status_t | mem_write (uint32_t address, uint32_t length, const uint8_t *buffer)
| Write memory.
status_t | mem_fill (uint32_t address, uint32_t length, uint32_t pattern)
| Fill memory with a word pattern.
status_t | mem_erase (uint32_t address, uint32_t length)
| Erase memory:
status_t | mem_flush (void)
| Flush meory: More...
status_t | find_map_entry (uint32_t address, uint32_t length, const memory_map_entry_t **map)
| Find a map entry that matches address and length. More...
bool | mem_is_erased (uint32_t address, uint32_t length)
| Check is the specified memory region is erased.

## Memory utilities

bool | mem_is_block_reserved (uint32_t address, uint32_t length)
| Determine if all or part of block is in a reserved region.

## Flash erase operations

status_t | flash_mem_erase (uint32_t address, uint32_t length)
| Erase Flash memory.
status_t | flash_mem_erase_all (flash_erase_all_option_t eraseOption)
| Erase all Flash memory or all Flash execute-only segments. More...
status_t | flash_mem_erase_all (void)
| Erase all Flash memory. More...
status_t | flash_mem_erase_all_unsecure (void)
| Erase all Flash memory (unsecure).

## QSPI erase operation

status_t | qspi_mem_erase_all (void)
| Erase all QSPI memory.

## Usage Information

Abstract memory interface.

## Data Structure Documentation

struct memory_interface_t

Interface to memory operations.

This is the main abstract interface to all memory operations.

### Data Fields

status_t(* | init )(void)
status_t(* | read )(uint32_t address, uint32_t length, uint8_t *buffer)
status_t(* | write )(uint32_t address, uint32_t length, const uint8_t *buffer)
status_t(* | fill )(uint32_t address, uint32_t length, uint32_t pattern)
status_t(* | flush )(void)
status_t(* | erase )(uint32_t address, uint32_t length)

struct memory_region_interface_t

Interface to memory operations for one region of memory.

### Data Fields

status_t(* | init )(void)
status_t(* | read )(uint32_t address, uint32_t length, uint8_t *buffer)
status_t(* | write )(uint32_t address, uint32_t length, const uint8_t *buffer)
status_t(* | fill )(uint32_t address, uint32_t length, uint32_t pattern)
status_t(* | flush )(void)
status_t(* | erase )(uint32_t address, uint32_t length)

struct memory_map_entry_t

Structure of a memory map entry.

Collaboration diagram for memory_map_entry_t:
[legend]

Data Fields
uint32_t | endAddress |
bool | isExecutable |
const memory_region_interface_t * | memoryInterface |
uint32_t | startAddress |

## Enumeration Type Documentation

anonymous enum

Enumerator
kMemoryNotExecutable | The memory doesn't support executing in place.
kMemoryIsExecutable | The memory supports executing in place.

enum _memorymap_constants

Memory Map index constants.

Enumerator
kSRAMSeparatrix | This value is the start address of SRAM_U.

## Function Documentation

status_t find_map_entry | ( | uint32_t | address,
|  | uint32_t | length,
|  | const memory_map_entry_t ** | map
| ) |  |

Find a map entry that matches address and length.

Parameters

  address | Start address for the memory operation.
  length | Number of bytes on which the operation will act.
  map | The matching map entry is returned through this pointer if the return status is #kStatus_Success.

Return values

  #kStatus_Success | A valid map entry was found and returned through map.
  #kStatusMemoryRangeInvalid | The requested address range does not match an entry, or the length extends past the matching entry's end address.

status_t flash_mem_erase_all | ( | flash_erase_all_option_t | eraseOption | ) |

Erase all Flash memory or all Flash execute-only segments.

It is only valid for non-flash resident bootloader when option is erasing execute-only segments.

status_t flash_mem_erase_all | ( | void |  | ) |

Erase all Flash memory.

If building for flash resident bootloader, we have to decompose the the flash erase all operation into two region erases. This allows the user to still do an erase all, but not wipe out the bootloader itself.

status_t mem_flush | ( | void |  | ) |

Flush meory:

Flush buffered data into target memory.

Note
  1. This function should be called immediately after one write-memory command(either received in command packet or in sb file), only in this way, given data can be programmed at given address as expected.

1. So far, flush() is only implemented in qspi memory interface, for other memory interfaces, it is not available and mem_flush() just returns kStatus_Success if it is called.
2. This function is designed to flush buffered data into target memory, please call it only if it is required to do so. For example, write 128 bytes to qspi flash, while the page size is 256 bytes, that means data might not be written to qspi memory immediately, since the internal buffer of qspi memory interface is not full, if no data are expected to write to left area of the same page, this function can be used to force to write immediately, otherwise, keep in mind that any calls should be avoided. If users voilate this rules, it would make the left area of the same page cannot be programmed.

Returns
  An error code or kStatus_Success

## Variable Documentation

const memory_region_interface_t g_deviceMemoryInterface

Memory interface for memory with Device or Strongly-ordered type.

This memory type does not support multiword loads and stores.

Memory interface for memory with Device or Strongly-ordered type.

const memory_region_interface_t g_flashMemoryInterface

Flash memory interface.

Flash memory interface.

const memory_interface_t g_memoryInterface

Initial value:
= {
mem_init, mem_read, mem_write,
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
mem_fill,
#else
NULL,
#endif
mem_flush, mem_erase,
}
mem_flush
status_t mem_flush(void)
Flush meory:
Definition: memory.c:194
mem_erase
status_t mem_erase(uint32_t address, uint32_t length)
Erase memory:
Definition: memory.c:121
mem_init
status_t mem_init(void)
Initialize memory interface.
Definition: memory.c:278
mem_read
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
Read memory.
Definition: memory.c:74
mem_fill
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
Fill memory with a word pattern.
Definition: memory.c:155
mem_write
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer)
Write memory.
Definition: memory.c:91

Interface to generic memory operations.

Abstract memory interface.

const memory_interface_t g_memoryInterface

Abstract memory interface.

This interface utilizes the memory map to perform different memory operations depending on the region of memory being accessed.

Abstract memory interface.

const memory_region_interface_t g_normalDTCMInterface

Memory interface for memory with Normal type.

Use of multiword loads and stores is allowed with this memory type.

Memory interface for memory with Normal type.

const memory_region_interface_t g_normalMemoryInterface

Memory interface for memory with Normal type.

Use of multiword loads and stores is allowed with this memory type.

Memory interface for memory with Normal type.

const memory_region_interface_t g_normalOCRAMInterface

Memory interface for memory with Normal type.

Use of multiword loads and stores is allowed with this memory type.

Memory interface for memory with Normal type.