NOR flash class.
More...
|
| #define | PBL_FLASH_OTP_CELL(_name, _offset, _len) {.name = (_name), .offset = (_offset), .len = (_len)} |
| | Initializer for a struct pbl_flash_otp_cell.
|
| |
| #define | PBL_FLASH_STATE_DEFINE(sym) |
| | Define the class state of flash sym, for the PBL_FLASH_*_DEFINE() macro of a driver.
|
| |
| #define | PBL_FLASH_INIT(sym, _name, _parent, _ops, _geometry, _otp, _otp_layout) |
| | Initializer for the struct pbl_flash of flash sym.
|
| |
|
| static const struct pbl_flash_geometry * | pbl_flash_get_geometry (const struct pbl_flash *flash) |
| | Get the geometry of a flash.
|
| |
| static bool | pbl_flash_in_coredump (const struct pbl_flash *flash) |
| | Check whether the flash runs in coredump mode, for drivers.
|
| |
| void | pbl_flash_set_map (const struct pbl_flash *flash, const void *ptr, uint32_t len) |
| | Declare where the CPU reads the flash directly, for drivers.
|
| |
| int | pbl_flash_read (const struct pbl_flash *flash, uint32_t addr, void *buf, size_t len) |
| | Read data.
|
| |
| int | pbl_flash_write (const struct pbl_flash *flash, uint32_t addr, const void *buf, size_t len) |
| | Program data into an erased range.
|
| |
| int | pbl_flash_erase (const struct pbl_flash *flash, uint32_t addr, size_t len) |
| | Erase a range.
|
| |
| int | pbl_flash_erase_async (const struct pbl_flash *flash, uint32_t addr, size_t len, pbl_flash_erase_cb_t cb, void *arg) |
| | Erase a range, returning once the erase has started.
|
| |
| bool | pbl_flash_is_erased (const struct pbl_flash *flash, uint32_t addr, size_t len) |
| | Check whether a range is erased.
|
| |
| int | pbl_flash_protect (const struct pbl_flash *flash, uint32_t addr, size_t len) |
| | Refuse writes and erases in a range, replacing the previous one.
|
| |
| int | pbl_flash_unprotect (const struct pbl_flash *flash) |
| | Allow writes and erases everywhere.
|
| |
| void | pbl_flash_stop (const struct pbl_flash *flash) |
| | Wait for the erase in progress, if any, and return the hardware to the state the boot code expects, before a reset.
|
| |
| int | pbl_flash_coredump_init (const struct pbl_flash *flash) |
| | Re-initialize the flash for use from a fault handler.
|
| |
| void | pbl_flash_power_down (const struct pbl_flash *flash, pbl_flash_pm_fn_t fn, void *arg) |
| | Power the flash down while a function runs, with interrupts disabled.
|
| |
| int | pbl_flash_pm_suspend (const struct pbl_flash *flash) |
| | Power the flash down until pbl_flash_pm_resume(), with interrupts disabled.
|
| |
| void | pbl_flash_pm_resume (const struct pbl_flash *flash) |
| | Power the flash back up after pbl_flash_pm_suspend().
|
| |
| uint32_t | pbl_flash_crc32 (const struct pbl_flash *flash, uint32_t addr, size_t len) |
| | CRC-32 of a range.
|
| |
| uint32_t | pbl_flash_crc32_legacy (const struct pbl_flash *flash, uint32_t addr, size_t len) |
| | Legacy checksum of a range, as used by firmware images and resources.
|
| |
|
The user OTP area of drivers that select FLASH_OTP: n_regions regions of region_len bytes, region i starting at offset i * region_len.
OTP bits are programmed like the main array, from erased (1) to 0, and a locked region can no longer be programmed or erased. Locking is irreversible: only the recovery firmware builds it, and it is never done implicitly. The board names the ranges it stores data in as cells.
|
| int | pbl_flash_otp_get_info (const struct pbl_flash *flash, struct pbl_flash_otp_info *info) |
| | Get the OTP organization.
|
| |
| int | pbl_flash_otp_read (const struct pbl_flash *flash, uint32_t offs, void *buf, size_t len) |
| | Read from the OTP area.
|
| |
| int | pbl_flash_otp_write (const struct pbl_flash *flash, uint32_t offs, const void *buf, size_t len) |
| | Program the OTP area.
|
| |
| int | pbl_flash_otp_is_locked (const struct pbl_flash *flash, uint8_t region, bool *locked) |
| | Check whether an OTP region is locked.
|
| |
| int | pbl_flash_otp_lock (const struct pbl_flash *flash, uint8_t region) |
| | Lock an OTP region forever.
|
| |
| int | pbl_flash_otp_erase (const struct pbl_flash *flash, uint8_t region) |
| | Erase an OTP region.
|
| |
| const struct pbl_flash_otp_cell * | pbl_flash_otp_cell_get (const struct pbl_flash *flash, const char *name) |
| | Find an OTP cell by name.
|
| |
NOR flash class.
A flash is a struct pbl_flash device. Addresses are offsets from its first byte, wherever the SoC maps it. Writes only clear bits, so the target range must be erased first. Erases work on whole subsectors: the class erases a range with as few sector and subsector erases as it can, skipping the blank ones.
static void prv_erased(int status, void *arg) {
}
if (ret != 0) {
return ret;
}
if (ret != 0) {
return ret;
}
const struct pbl_flash *const FLASH
The board's storage flash.
int pbl_flash_erase(const struct pbl_flash *flash, uint32_t addr, size_t len)
Erase a range.
int pbl_flash_write(const struct pbl_flash *flash, uint32_t addr, const void *buf, size_t len)
Program data into an erased range.
int pbl_flash_erase_async(const struct pbl_flash *flash, uint32_t addr, size_t len, pbl_flash_erase_cb_t cb, void *arg)
Erase a range, returning once the erase has started.
Calls are serialized per device and must not be issued from ISRs. A read or write issued while an erase is in progress suspends the erase, if the driver can, and the class resumes it shortly after. Only one erase runs at a time: starting another one blocks until the first is done.
Calls return 0 or a negative errno: -EINVAL for a range outside the flash or an unaligned erase, -EACCES for a write or erase in the protected range and -ENODEV if the flash is not ready. A hardware failure while reading, writing or erasing is fatal.
After pbl_flash_coredump_init() the class runs without OS services: no locking, no timers, no sleeping, and erases are synchronous. That is not reversible.
◆ pbl_flash_geometry
| struct pbl_flash_geometry |
| Data Fields |
|
uint32_t |
page_size |
Program page size, in bytes. |
|
uint16_t |
sector_erase_ms |
Typical sector erase time, to pace erase polling. |
|
uint32_t |
sector_size |
Large erase unit, in bytes. |
|
uint32_t |
size |
Size, in bytes. |
|
uint16_t |
subsector_erase_ms |
Typical subsector erase time, to pace erase polling. |
|
uint32_t |
subsector_size |
Small erase unit, in bytes. |
◆ pbl_flash_otp_info
| struct pbl_flash_otp_info |
Organization of the user one-time programmable (OTP) area.
| Data Fields |
|
uint8_t |
n_regions |
Number of regions, 0 without OTP. |
|
uint32_t |
region_len |
Size of each region, in bytes. |
◆ pbl_flash_otp_cell
| struct pbl_flash_otp_cell |
A named range of the OTP area.
| Data Fields |
|
uint32_t |
len |
Size, in bytes. |
|
const char * |
name |
Name. |
|
uint32_t |
offset |
Offset in the OTP area. |
◆ pbl_flash_otp_layout
| struct pbl_flash_otp_layout |
Named ranges of the OTP area, as laid out by the board.
| Data Fields |
|
const struct pbl_flash_otp_cell * |
cells |
Cells. |
|
uint8_t |
num_cells |
Number of cells. |
◆ pbl_flash
◆ PBL_FLASH_INIT
| #define PBL_FLASH_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_parent, |
|
|
|
_ops, |
|
|
|
_geometry, |
|
|
|
_otp, |
|
|
|
_otp_layout |
|
) |
| |
Value: { \
.ops = (_ops), \
.state = &sym##_flash_state, \
.geometry = (_geometry), \
.otp = (_otp), \
.otp_layout = (_otp_layout), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
Initializer for the struct pbl_flash of flash sym.
- Parameters
-
| sym | Symbol of the flash instance, with its state defined by PBL_FLASH_STATE_DEFINE(). |
| _name | Name. |
| _parent | Parent device, e.g. the memory controller, or NULL. |
| _ops | Driver operations. |
| _geometry | Geometry. |
| _otp | OTP organization, or NULL. |
| _otp_layout | OTP cells, or NULL. |
◆ PBL_FLASH_OTP_CELL
| #define PBL_FLASH_OTP_CELL |
( |
|
_name, |
|
|
|
_offset, |
|
|
|
_len |
|
) |
| {.name = (_name), .offset = (_offset), .len = (_len)} |
◆ PBL_FLASH_STATE_DEFINE
| #define PBL_FLASH_STATE_DEFINE |
( |
|
sym | ) |
|
Value:
static struct pbl_flash_state sym##_flash_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132
Define the class state of flash sym, for the PBL_FLASH_*_DEFINE() macro of a driver.
- Parameters
-
| sym | Symbol of the flash instance. |
◆ pbl_flash_erase_cb_t
| typedef void(* pbl_flash_erase_cb_t) (int status, void *arg) |
Completion callback of pbl_flash_erase_async().
Runs on pbl_sys_workq_high, or from the caller if there is nothing to erase, with no lock held: it may start another erase.
- Parameters
-
| status | 0 or a negative errno. |
| arg | Callback argument. |
◆ pbl_flash_pm_fn_t
| typedef void(* pbl_flash_pm_fn_t) (void *arg) |
◆ pbl_flash_coredump_init()
| int pbl_flash_coredump_init |
( |
const struct pbl_flash * |
flash | ) |
|
Re-initialize the flash for use from a fault handler.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_flash_crc32()
| uint32_t pbl_flash_crc32 |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
size_t |
len |
|
) |
| |
CRC-32 of a range.
- Parameters
-
| flash | Flash. |
| addr | Address. |
| len | Number of bytes. |
- Returns
- CRC-32.
◆ pbl_flash_crc32_legacy()
| uint32_t pbl_flash_crc32_legacy |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
size_t |
len |
|
) |
| |
Legacy checksum of a range, as used by firmware images and resources.
- Parameters
-
| flash | Flash. |
| addr | Address. |
| len | Number of bytes. |
- Returns
- Checksum.
◆ pbl_flash_erase()
| int pbl_flash_erase |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
size_t |
len |
|
) |
| |
Erase a range.
Feeds the caller's task watchdog while it waits, unless a single erase unit takes unreasonably long.
- Parameters
-
| flash | Flash. |
| addr | Address, aligned to a subsector. |
| len | Number of bytes, rounded up to a subsector. |
- Returns
- 0 or a negative errno.
Referenced by pbl_flash_partition_erase().
◆ pbl_flash_erase_async()
Erase a range, returning once the erase has started.
- Parameters
-
| flash | Flash. |
| addr | Address, aligned to a subsector. |
| len | Number of bytes, rounded up to a subsector. |
| cb | Completion callback. |
| arg | Callback argument. |
- Returns
- 0 if
cb will be called, or a negative errno.
◆ pbl_flash_get_geometry()
◆ pbl_flash_in_coredump()
| static bool pbl_flash_in_coredump |
( |
const struct pbl_flash * |
flash | ) |
|
|
inlinestatic |
◆ pbl_flash_is_erased()
| bool pbl_flash_is_erased |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
size_t |
len |
|
) |
| |
Check whether a range is erased.
- Parameters
-
| flash | Flash. |
| addr | Address. |
| len | Number of bytes. |
- Returns
- True if the flash is ready and every byte reads as erased.
Referenced by pbl_flash_partition_is_erased().
◆ pbl_flash_otp_cell_get()
Find an OTP cell by name.
- Parameters
-
- Returns
- Cell, or NULL if the board has no such cell.
◆ pbl_flash_otp_erase()
| int pbl_flash_otp_erase |
( |
const struct pbl_flash * |
flash, |
|
|
uint8_t |
region |
|
) |
| |
Erase an OTP region.
- Parameters
-
| flash | Flash. |
| region | Region. |
- Returns
- 0,
-ENOTSUP if the flash cannot erase it, -EROFS if the region is locked, or another negative errno.
◆ pbl_flash_otp_get_info()
Get the OTP organization.
- Parameters
-
| flash | Flash. |
| [out] | info | Organization. |
- Returns
- 0, or
-ENOTSUP without OTP.
◆ pbl_flash_otp_is_locked()
| int pbl_flash_otp_is_locked |
( |
const struct pbl_flash * |
flash, |
|
|
uint8_t |
region, |
|
|
bool * |
locked |
|
) |
| |
Check whether an OTP region is locked.
- Parameters
-
| flash | Flash. |
| region | Region. |
| [out] | locked | Lock state. |
- Returns
- 0 or a negative errno.
◆ pbl_flash_otp_lock()
| int pbl_flash_otp_lock |
( |
const struct pbl_flash * |
flash, |
|
|
uint8_t |
region |
|
) |
| |
Lock an OTP region forever.
- Parameters
-
| flash | Flash. |
| region | Region. |
- Returns
- 0,
-ENOTSUP if the flash cannot lock it, or another negative errno.
◆ pbl_flash_otp_read()
| int pbl_flash_otp_read |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
offs, |
|
|
void * |
buf, |
|
|
size_t |
len |
|
) |
| |
Read from the OTP area.
- Parameters
-
| flash | Flash. |
| offs | Offset in the OTP area. |
| [out] | buf | Buffer. |
| len | Number of bytes. |
- Returns
- 0 or a negative errno.
◆ pbl_flash_otp_write()
| int pbl_flash_otp_write |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
offs, |
|
|
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
Program the OTP area.
- Parameters
-
| flash | Flash. |
| offs | Offset in the OTP area. |
| buf | Data. |
| len | Number of bytes. |
- Returns
- 0,
-EROFS if a region in the range is locked, or another negative errno.
◆ pbl_flash_pm_resume()
| void pbl_flash_pm_resume |
( |
const struct pbl_flash * |
flash | ) |
|
◆ pbl_flash_pm_suspend()
| int pbl_flash_pm_suspend |
( |
const struct pbl_flash * |
flash | ) |
|
Power the flash down until pbl_flash_pm_resume(), with interrupts disabled.
For a flash the CPU does not execute from, see pbl_flash_power_down() otherwise.
- Parameters
-
- Return values
-
| 0 | Powered down. |
| -EBUSY | An erase or a transfer is in progress. |
| -ENOTSUP | The driver cannot. |
◆ pbl_flash_power_down()
Power the flash down while a function runs, with interrupts disabled.
The flash stays powered while an erase is in progress, but fn always runs. When the CPU executes from the flash, fn must run from RAM.
- Parameters
-
| flash | Flash. |
| fn | Function to run. |
| arg | Argument of fn. |
◆ pbl_flash_protect()
| int pbl_flash_protect |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
size_t |
len |
|
) |
| |
Refuse writes and erases in a range, replacing the previous one.
- Parameters
-
| flash | Flash. |
| addr | Address. |
| len | Number of bytes. |
- Returns
- 0 or a negative errno.
Referenced by pbl_flash_partition_protect().
◆ pbl_flash_read()
| int pbl_flash_read |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
void * |
buf, |
|
|
size_t |
len |
|
) |
| |
◆ pbl_flash_set_map()
| void pbl_flash_set_map |
( |
const struct pbl_flash * |
flash, |
|
|
const void * |
ptr, |
|
|
uint32_t |
len |
|
) |
| |
Declare where the CPU reads the flash directly, for drivers.
Reads inside the window then copy from memory instead of going through the driver. The driver keeps the window coherent after it writes or erases.
- Parameters
-
| flash | Flash. |
| ptr | CPU address of the first byte, or NULL to remove the window. |
| len | Size of the window in bytes. |
◆ pbl_flash_stop()
| void pbl_flash_stop |
( |
const struct pbl_flash * |
flash | ) |
|
Wait for the erase in progress, if any, and return the hardware to the state the boot code expects, before a reset.
The flash then refuses every call with -ENODEV, until pbl_flash_coredump_init().
- Parameters
-
◆ pbl_flash_unprotect()
| int pbl_flash_unprotect |
( |
const struct pbl_flash * |
flash | ) |
|
Allow writes and erases everywhere.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_flash_write()
| int pbl_flash_write |
( |
const struct pbl_flash * |
flash, |
|
|
uint32_t |
addr, |
|
|
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
Program data into an erased range.
- Parameters
-
| flash | Flash. |
| addr | Address. |
| buf | Data. |
| len | Number of bytes. |
- Returns
- 0 or a negative errno.
Referenced by pbl_flash_partition_write().
◆ FLASH