Skip to content

axera: an Axera HAL for the AX620E and AX620U - #290

Merged
dimerr merged 4 commits into
masterfrom
axera-hal
Nov 19, 2026
Merged

dimerr merged 4 commits into
masterfrom
axera-hal

Conversation

@dimerr

@dimerr dimerr commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Adds an Axera vendor HAL so ipcinfo recognises Axera AX620E and AX620U cameras.

  • Detection from the root devicetree compatible: axera,ax620e (AX620E/AX630C/AX620Q) and axera,ax620x (what the AX620U camera's own devicetree says, mapped to the ax620u family OpenIPC builds). Registered on both the ARM and arm64 paths, since AX620E runs an arm64 kernel.
  • axera added to the optional libipchw vendors.

Why it matters: OpenIPC's vendor init only runs the chip's driver loader (load_axera) when ipcinfo -v names the vendor; without this it printed generic/unknown and the Axera media drivers never loaded.

Tested inside OpenIPC firmware images for both chips (OpenIPC/firmware#2670) on the OpenIPC/qemu-bench ax620e and ax620u machines: ipcinfo -v/-c/-f print axera/ax620e/ax620e (sensor sc450ai) and axera/ax620u/ax620u, and init loads all vendor modules. Not yet run on real hardware.

Detects the SoC from the kernel's root devicetree compatible: AX620E,
AX630C and AX620Q devicetrees say "axera,ax620e", AX620U's (real
deployed camera firmware) says "axera,ax620x", which is mapped to the
ax620u family OpenIPC builds. Registered for both the ARM and arm64
paths (AX620E runs an arm64 kernel). With it ipcinfo -v/-c/-f report
axera/<soc>/<family>, so OpenIPC's vendor init runs load_axera for the
Axera media drivers; the sensor is reported from the devicetree.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add Axera HAL detection for AX620E and AX620U

✨ Enhancement ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Recognize Axera SoCs from devicetree compatibles, mapping AX620U’s ax620x identifier to its
 OpenIPC family.
• Register the HAL on ARM and arm64 so ipcinfo reports the vendor needed by OpenIPC init.
• Add optional vendor selection and chip-specific sensor I2C adapters.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: camera hardware diagnostics.
  • The changed detector supplies the vendor, chip generation, family name, and model used by the diagnostic path.
  • These are one bounded hardware-identification behavior even though detection is registered in chipid.c and implemented in the Axera HAL; the propagation is evidenced by the detector registration and the assignments to chip_generation and chip_name.
  • The detector configures the Axera sensor address candidates and preferred adapter, which the existing sensor probe consumes.
  • This is a distinct end-to-end outcome from naming the chip, but it remains within the same bounded camera diagnostics integration rather than an independent deployment scope.
Sources

src/hal/axera.c[117-124]

    bool read = mem_reg(regs[e][0], &a, OP_READ);

    mem_reg(regs[e][1], &b, OP_READ);
    chip_generation = e ? AXERA_AX620E : AXERA_AX620U;
    i2c_adapter_nr = e ? 6 : 8;
    strcpy(chip_name, !e     ? axera_ax620u_name(a, b)
                      : read ? axera_ax620e_name(a, b)
                             : ax620e_names[0]);
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Data transformation

  • Before: no Axera path existed in this repository, so Axera systems were not classified by this detector.
  • After: the change introduces two family-specific register maps, a device-tree compatibility gate, eFuse-versus-DUMMY_SW9 precedence, an unfused/default mapping, Hamming(7,4) correction, AX620U DDR/bond classification, and global sensor-bus setup.
  • The new correctness conditions are that the compatible entry selects the correct register map, the eFuse value takes precedence when present, fallback values are used only in the intended zero/read-failure cases, and the resulting bus/model remain consistent.
  • The Hamming decoder is a nontrivial transformation; the interacting branches arise from family selection, register-read success, zero/unfused state, and fallback precedence.
  • The existing sensor probe and memory-mapping helpers are reused rather than counted as newly complex, although the new global configuration creates the runtime dependency on their values.
Sources

src/hal/axera.c[117-124]

    bool read = mem_reg(regs[e][0], &a, OP_READ);

    mem_reg(regs[e][1], &b, OP_READ);
    chip_generation = e ? AXERA_AX620E : AXERA_AX620U;
    i2c_adapter_nr = e ? 6 : 8;
    strcpy(chip_name, !e     ? axera_ax620u_name(a, b)
                      : read ? axera_ax620e_name(a, b)
                             : ax620e_names[0]);
Potential damage 🟡 Medium 🩹 Incorrect results

  • A wrong decoded type or family branch produces a wrong but syntactically valid hardware identity.
  • This affects diagnostic/reporting output and any later code that selects behavior from chip_generation.
  • The equal-importance baseline is used; no source declaration makes this capability more or less important than the others.
  • Reverting the code restores the previous behavior.
  • A wrong report is otherwise recoverable by rerunning detection after correcting the source/register condition; no persistent state repair or external compensation is required.
Sources

src/hal/axera.c[117-124]

    bool read = mem_reg(regs[e][0], &a, OP_READ);

    mem_reg(regs[e][1], &b, OP_READ);
    chip_generation = e ? AXERA_AX620E : AXERA_AX620U;
    i2c_adapter_nr = e ? 6 : 8;
    strcpy(chip_name, !e     ? axera_ax620u_name(a, b)
                      : read ? axera_ax620e_name(a, b)
                             : ax620e_names[0]);
Assessed commit 61e6699
Diagram

graph TD
  BUILD["Vendor selection"] --> DETECT["Chip detection"] --> HAL["Axera HAL"] --> I2C["Sensor I2C"]
  DT["Root compatible"] --> HAL
  HAL --> IPC["ipcinfo identity"] --> INIT["OpenIPC init"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Allowlist known Axera compatibles
  • ➕ Avoids identifying future, unsupported Axera chips as supported.
  • ➖ Requires an update for each newly supported compatible.
  • ➖ Provides less automatic coverage than the current Axera-compatible pattern.

Recommendation: Keep the separate HAL and devicetree-based detection: they fit the existing vendor dispatch model and avoid relying on an undocumented chip-ID register. Consider an exact compatible allowlist if reporting an untested future Axera chip as supported would cause unsafe downstream initialization.

Files changed (6) +74 / -1

Enhancement (5) +73 / -0
chipid.cRegister Axera detection on ARM and arm64 +7/-0

Register Axera detection on ARM and arm64

• Adds Axera detector and HAL setup entries to both architecture-specific manufacturer tables, overriding the reported vendor when detection succeeds.

src/chipid.c

chipid.hDefine the Axera vendor name +1/-0

Define the Axera vendor name

• Introduces the vendor string used by the detection table and vendor reporting.

src/chipid.h

axera.cDetect Axera SoCs and configure sensor I2C +55/-0

Detect Axera SoCs and configure sensor I2C

• Reads the root devicetree compatible to identify Axera chips, translating 'ax620x' to 'ax620u'. Configures AX620U to use I2C adapter 8 and other detected Axera chips to use adapter 6, alongside candidate sensor addresses.

src/hal/axera.c

axera.hDeclare the Axera HAL entry points +9/-0

Declare the Axera HAL entry points

• Declares the SoC detector and HAL setup functions for manufacturer-table dispatch.

src/hal/axera.h

common.hExpose Axera declarations to common HAL consumers +1/-0

Expose Axera declarations to common HAL consumers

• Includes the new Axera header alongside the existing vendor HAL headers.

src/hal/common.h

Other (1) +1 / -1
CMakeLists.txtMake Axera an optional vendor HAL +1/-1

Make Axera an optional vendor HAL

• Adds Axera to the vendor list used to compile HAL sources and definitions for the executable and selectable libipchw builds.

CMakeLists.txt

dimerr pushed a commit to OpenIPC/firmware that referenced this pull request Nov 18, 2026
The AX620E patch covers AX620U too (axera,ax620x maps to ax620u); the
AX620U-only copy would fail to apply on top of it. Carried until
OpenIPC/ipctool#290 is in a release.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Some Axera cameras remain unidentified ✓ Resolved
Description
axera_detect_cpu() passes the root devicetree's NUL-separated compatible property to
line_from_file(), whose regex search stops at the first embedded NUL. When a board-specific
compatible string precedes axera,ax620e or axera,ax620x, detection fails, so vendor
identification does not select the Axera HAL.


Remediation recommended

2. Axera chip generation stays unset ✓ Resolved
Description
axera_detect_cpu fills only chip_name and never sets the global chip_generation, so it stays 0
for every Axera part. Padmux, clock-family and boot-table lookups keyed on that value have no Axera
entry, and the PR adds no per-generation table; unlike the documented Ambarella exception, nothing
explains the omission.

3. Axera detector listed twice per build ✓ Resolved
Description
The Axera detector and setup entries appear twice in manufacturers[], once in the ARM block and
once after the arm64 block, and neither copy has an __arm__ or __aarch64__ guard. Every build
compiles both, and on non-Axera boards detection runs a second time against
/proc/device-tree/compatible; a later reader who drops one copy as redundant would also break the
intended ARM/arm64 split.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

The root compatible is a list of NUL-separated strings and a board
string usually comes first, so the Axera entry is searched for among
all of them instead of only the first. One manufacturers[] entry under
an __arm__/__aarch64__ guard replaces the two per-ABI copies.
chip_generation stays 0 on purpose, as for Ambarella: ipctool has no
pad-mux, clock or boot ROM tables for Axera.
@dimerr

dimerr commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed Qodo's review in the latest commit:

  1. Board compatible before the Axera one — fixed: /proc/device-tree/compatible is now read whole and every NUL-separated entry is checked (e.g. xm,ipc then axera,ax620x → ax620u).
  2. chip_generation unset — intentional, now documented in the code the same way as the Ambarella HAL: ipctool has no Axera pad-mux, clock or boot-ROM tables, so 0 sends those paths to their no-table answer and getchipfamily() back to the name.
  3. Detector listed twice — the two copies were in the __arm__ and __aarch64__ blocks (only one compiled per build), but a single entry under an __arm__ || __aarch64__ guard is cleaner; done.

Every AX620E-family devicetree says "axera,ax620e", whether the die is
an AX620Q, AX630C or AX620QX, so the compatible now only picks the
family and gates the register reads; the part comes from hardware.

AX620E family: the SDK BL1 (board.c get_misc_info()) reads eFuse block
2 through EFSC0's shadow register, 0x02200000 + 0x58 + 2 * 4, takes
bits 31:24 as a Hamming(7,4)-coded chip type and stores the decoded
value in DUMMY_SW9 (0x02340220). ipctool decodes the fuse word the same
way, falls back to DUMMY_SW9 when the word reads 0, and treats 0 as
AX630C as BL1 does: ax620q, ax620qx, ax620v200, ax630c, ax631,
ax620qz, ax620qp, ax620qe or ax620qf.

AX620U family, from the stock ax_hwinfo.ko and ax_sys.ko: bit 24 of
the DDR controller's 0x00102068 clear is AX620U; set, the bond option
register 0x0222001C with all of 0x191800 is AX620D, otherwise AX620A.

ipcinfo -f keeps the family OpenIPC builds (ax620e, ax620u) through a
chip_generation per family. Without /dev/mem the family name is the
model. axera_test checks the decode against BL1's own decoder on all
256 codes, every listed type with each single-bit error, and the
AX620U rule.
@dimerr

dimerr commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 8755ade: ipctool now gets the model from hardware registers instead of the devicetree. The compatible tells only the family: every AX620E-family part says axera,ax620e, and AX620U says axera,ax620x. ipctool uses it only to choose which registers to read.

AX620E family (AX620Q, AX630C, AX620QX, …)

  • Source: the SDK's BL1, boot/bl1/board/board.c get_misc_info(). It reads eFuse block 2 (CHIP_BOND_BLK) and takes bits 31:24 as the chip type.
  • efuse_read() (boot/bl1/driver/secure/efuse_drv.c) is a plain load from EFSC0's shadow register: 0x02200000 + EFSC_SHADOW_0 (0x58) + blk*4, i.e. 0x02200060. No read sequence is needed, so /dev/mem sees the same word.
  • The byte is Hamming(7,4)-coded: the type is in bits 6:3 and the parity in bits 2:0. ipctool decodes it the way hanming_decode_74() does, including single-bit correction. A 0 result means AX630C, as in BL1's store_chip_type().
  • BL1 also writes the decoded type to DUMMY_SW9 (0x02340220). ipctool uses that only when the fuse word reads 0, which is also what a shadow register closed to the normal world would return.
  • Possible names (chip_type_e): ax620q, ax620qx, ax620v200, ax630c, ax631, ax620qz, ax620qp, ax620qe, ax620qf.

AX620U family (AX620U, AX620A, AX620D)

  • Source: the stock firmware's own ax_hwinfo.ko (ax_chip_type_proc_show) and ax_sys.ko (ax_ddr_bits_read), disassembled.
  • If bit 24 of DDRMC 0x00102068 is clear, the part is AX620U.
  • If it is set, the part is AX620D when bond option 0x0222001C has all of 0x191800 set, and AX620A otherwise.
  • 0x00102068 is not a fuse: the SPL programs it for the board's DRAM (0x00010000 on the stock AX620U). Still, it is the vendor's own test.

Families and fallback

  • ipcinfo -f still prints the family OpenIPC builds (ax620e / ax620u), through one chip_generation per family.
  • Without /dev/mem, the family name is reported as the model.

Tests

  • axera_test, added to CI, checks the decode against BL1's decoder on all 256 codes, each type with every single-bit error, and the AX620U rule.
  • QEMU: axera: chip= sets the part the eFuse and bond registers report qemu-bench#346 models the eFuse shadow, DUMMY_SW9 and the AX620U registers behind a chip= property. Results from OpenIPC kernels with an initramfs and static musl builds of this branch:
    • -M ax620e: ipcinfo -v -c -f → axera / ax620q / ax620e
    • -M ax620u: → axera / ax620u / ax620u
    • -M ax620u,chip=ax620d: → axera / ax620d / ax620u
  • On the stock AX620E dump with the same preset, the real BL1 decodes the fuse word and the firmware logs this chip type is AX620Q_CHIP, so the encoding matches the vendor's.

The arm32 size check failed: ipcinfo grew 1602 bytes (51931 -> 53533),
over the 1024 the workflow allows. Now 996 (-> 52927); IPCHW_VENDORS=none
is unchanged at 0.

- /proc/device-tree/compatible through open/read, which ipcinfo already
  imports, not fopen/fread (fread was a new import).
- One register-read path for both families instead of two inlined copies.
- The part names as an inline char table, not pointers (one relocation
  each in the PIE).
- No private i2c opener: it ignored the bus number it was passed, so the
  sweep over other buses in sensors.c reopened i2c-6/8 every time. The
  fallback opener, with i2c_adapter_nr set at detection, does it right.
- The decode helpers are static and axera_test.c includes axera.c, as
  novatek_test does.
- ipcinfo (STANDALONE_LIBRARY) takes the type from the fuse's data bits,
  which is the type verbatim on a clean fuse; ipctool keeps BL1's
  single-bit correction, and axera_test checks that one against BL1.
- A type the SDK does not list is named by the family, ax620e.
@dimerr

dimerr commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

The arm32 failure was the ipcinfo size step, not the build. With IPCHW_VENDORS=all, ipcinfo grew 1602 bytes against the base (51931 -> 53533 in size(1) text+data+bss), and the workflow allows 1024. With none the delta was already 0.

61e6699 brings it to 51931 -> 52927 (+996), and none stays at +0. Every check passes now. I reproduced the numbers locally with the CI toolchain and the same configure.

Where the bytes went, and what changed:

  • stdio: the HAL read /proc/device-tree/compatible with fopen/fread, and fread was a new import. It now uses open/read, which ipcinfo already imports. It still checks every NUL-separated entry.
  • Duplicate code: axera_identify() was inlined twice, once per family. There is now one register-read path, with the addresses in a small table.
  • Pointer name table: in the PIE, each pointer costs a relocation. The names are now an inline char[][10] table.
  • Private i2c opener: it ignored the bus number it was given, so the sweep over other buses in sensors.c reopened i2c-6/8 every time. It's gone. Detection sets i2c_adapter_nr (6 for AX620E, 8 for AX620U) and the fallback opener uses it.
  • Test-only externs: the decode helpers are now static, and axera_test.c includes axera.c, as novatek_test.c does.
  • Hamming correction: ipcinfo (STANDALONE_LIBRARY) reads the type from the fuse's data bits 6:3. The code is systematic, so on a clean fuse those bits are the type itself. ipctool keeps BL1's single-bit correction, and axera_test still checks that version against BL1's hanming_decode_74() on every code. This follows the CLAUDE.md rule that ipcinfo carries the least that works.
  • Unlisted type codes: a code the SDK doesn't list now gives the family name, ax620e, instead of NULL.

The budget is unchanged.

@dimerr
dimerr merged commit b1f0324 into master Nov 19, 2026
5 checks passed
@dimerr
dimerr deleted the axera-hal branch November 19, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant