alif — Alif Ensemble SoC functions
The alif module exposes port-specific functionality for the Alif
Ensemble SoC, including a block-device wrapper for the on-board OSPI flash
and a helper to dump SoC information from the Secure Enclave services.
Example:
import alif
alif.info()
flash = alif.Flash()
Functions
Classes
- class alif.Flash(*, start: int = -1, len: int = -1)
Creates a block-device object backed by the on-board OSPI flash. This class is only available when the firmware is built with OSPI support enabled.
When called with no arguments, returns the default singleton object covering the writable filesystem region of flash.
startis the byte offset into the flash storage region. Must be a multiple of the flash block size and within the flash storage range. Defaults to-1which means start at offset0.lenis the length in bytes of the flash region exposed by the object. Must be a multiple of the flash block size and not extend past the end of the flash storage region. Defaults to-1which means use all remaining bytes fromstart.The object also implements the buffer protocol, allowing read-only memory-mapped access to the flash region via the OSPI XIP base.
- readblocks(block_num: int, buf: bytearray) int
- readblocks(block_num: int, buf: bytearray, offset: int) int
Reads from the flash starting at the block
block_num(and an optional byteoffsetwithin that block) intobuf. The number of bytes read is determined by the length ofbuf.Returns
0on success or a negative error code.
- writeblocks(block_num: int, buf: bytes) int
- writeblocks(block_num: int, buf: bytes, offset: int) int
Writes
bufto the flash starting at the blockblock_num(and an optional byteoffsetwithin that block).When called without
offset, the affected blocks are erased before being written. When called withoffset, the data is written without erasing first (the caller must ensure the target region has already been erased).Returns
0on success or a negative error code.
- ioctl(cmd: int, arg: int) int
Performs a block-device control operation.
cmdis one of the standard MicroPythonMP_BLOCKDEV_IOCTL_*commands:1(init) — returns0.2(deinit) — returns0.3(sync) — returns0.4(block count) — returns the number of blocks in the region.5(block size) — returns the flash block size in bytes.6(block erase) — erases the block at indexargand returns the result of the erase operation.
Other
cmdvalues returnNone.