43static const char*
s_tag =
"NPU-LOAD";
56typedef enum : uint32_t {
57 k_ra8_npu_loader_align_mask =
59} ra8_npu_loader_const_t;
84static bool internal_npu_span_ok(uint32_t offset, uint32_t size, uint32_t limit)
89 if (offset > (limit - size)) {
123static ra8_err_t internal_npu_check_header(
const uint8_t* p,
126 uint32_t* out_rcount,
128 uint32_t* out_cbytes)
151 if (!internal_npu_span_ok(0U, total, blob_bytes)) {
172 if (!internal_npu_span_ok(coff, cbytes, total)) {
177 *out_rcount = rcount;
179 *out_cbytes = cbytes;
205static ra8_err_t internal_npu_verify_checksum(
const uint8_t* p, uint32_t total)
214 if (digest != stored) {
249static ra8_err_t internal_npu_place_region(
const uint8_t* p,
253 uint32_t* arena_used,
263 const uint32_t data_off =
267 if (!internal_npu_span_ok(data_off, size, total)) {
271 *out_base = (uint64_t)(uintptr_t)(p + data_off);
274 const uint32_t aligned =
275 (*arena_used + (uint32_t)k_ra8_npu_loader_align_mask) & ~(uint32_t)k_ra8_npu_loader_align_mask;
276 if (aligned > arena->
bytes) {
280 if (size > (arena->
bytes - aligned)) {
284 *out_base = (uint64_t)(uintptr_t)(arena->
base + aligned);
285 *arena_used = aligned + size;
316static ra8_err_t internal_npu_place_all_regions(
const uint8_t* p,
323 for (uint32_t r = 0U; r < rcount; r++) {
324 const uint32_t desc_off =
327 internal_npu_place_region(p, total, desc_off, arena, &used, &job->
region_base[r]);
364static ra8_err_t internal_npu_build_job(
const uint8_t* p,
370 uint32_t rcount = 0U;
372 uint32_t cbytes = 0U;
375 const ra8_err_t hdr = internal_npu_check_header(p, blob_bytes, &total, &rcount, &coff, &cbytes);
385 const ra8_err_t sum = internal_npu_verify_checksum(p, total);
390 const ra8_err_t rgn = internal_npu_place_all_regions(p, total, rcount, arena, &job);
409 return internal_npu_build_job((
const uint8_t*)blob, blob_bytes, arena, out_job);
static const char * s_tag
Logging / check tag.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Compile-time device selection for the RA8 multi-chip build (RA8D2 / RA8P1).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_checksum_mismatch
Stored / transmitted checksum does not match computed value.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
Arm Ethos-U55 NPU command/queue driver foundation (RA8P1-only).
.npub linkable-blob container for a Vela-compiled Ethos-U55 model
@ k_ra8_npu_blob_word_version
format version.
@ k_ra8_npu_blob_word_cmd_bytes
command-stream length in bytes.
@ k_ra8_npu_blob_word_region_count
number of region descriptors.
@ k_ra8_npu_blob_word_checksum
FNV-1a digest over the payload.
@ k_ra8_npu_blob_word_magic
magic == k_ra8_npu_blob_magic.
@ k_ra8_npu_blob_word_cmd_offset
byte offset to the command stream.
@ k_ra8_npu_blob_word_total_bytes
whole blob length in bytes.
@ k_ra8_npu_blob_magic
First word: "NPU1" little-endian.
@ k_ra8_npu_blob_version
Container format version.
@ k_ra8_npu_blob_rflag_baked
Region bytes are baked into the blob.
static uint32_t ra8_npu_blob_read_word(const uint8_t *buf, uint32_t byte_off)
Read one little-endian 32-bit word from a .npub byte buffer.
@ k_ra8_npu_blob_fnv_offset
FNV-1a 32-bit offset basis.
@ k_ra8_npu_blob_fnv_prime
FNV-1a 32-bit prime.
@ k_ra8_npu_blob_rdesc_size
region size in bytes.
@ k_ra8_npu_blob_rdesc_flags
region flags (ra8_npu_blob_rflag_t).
@ k_ra8_npu_blob_rdesc_data_offset
baked-data byte offset (if baked).
@ k_ra8_npu_blob_arena_align
Runtime-region alignment (bytes).
@ k_ra8_npu_blob_word_bytes
Bytes in one little-endian word.
@ k_ra8_npu_blob_header_bytes
Header length (8 words * 4).
@ k_ra8_npu_blob_region_desc_bytes
One region descriptor (4 words * 4).
int ra8_npu_loader_not_on_this_device_t
On-target loader: .npub Vela blob -> ra8_npu_job_t (RA8P1-only).
ra8_err_t ra8_npu_load(const void *blob, uint32_t blob_bytes, const ra8_npu_arena_t *arena, ra8_npu_job_t *out_job)
Validate a .npub blob and map it into an ra8_npu_job_t.
@ k_ra8_npu_region_count
Number of BASEPn region base-pointer pairs.
Caller-provided runtime arena for a model's RUNTIME regions.
uint32_t bytes
Runtime arena capacity in bytes (0 if no runtime rgn).
uint8_t * base
Runtime arena base in NPU-visible SRAM (writable).
One Ethos-U55 inference job: a command stream plus its tensor arenas.
uint8_t region_count
Number of region_base[] entries in use.
uint32_t cmd_stream_bytes
Command stream length in bytes (> 0).
uint64_t region_base[k_ra8_npu_region_count]
AXI base of each BASEPn arena.
const void * cmd_stream
Vela command stream base in SRAM.