Repository navigation
axera: AX620E camera support on 5.15.73, ported from Axera's SDK kernel - #259
Conversation
From the Axera maix_ax620e_sdk 4.19.125 kernel: the display, mailbox, hrtimer, apb timer and board-info headers the vendor drivers use, and the dt-binding headers of the AX620E devicetree. ax_printk.h is rewritten for 5.15: the vendor modules call _ax_printk(id, tag, level, fmt, ...).
…rivers Ported from the Axera SDK 4.19.125 kernel. Without them every AX620E device with resets or GPIOs (Ethernet, the SPI NOR chip select on GPIO2_29) defers forever. GPIO numbering stays static in probe order as in the vendor kernel: the Xiongmai XmGpio.ko asks for legacy GPIO numbers. The reset controller takes #reset-cells from the node (5.15's reset core checks it before of_xlate).
…rs, PWM) The AX620E vendor 5.15 devicetree points the UARTs at periph UART0_EB/PCLK_UART0_EB (baudclk/apb_pclk) instead of a clock-frequency; without those clocks dw8250 fails with "clock rate not defined". Add the UART source mux (MUX0[18:17], as the SDK's 8250_axera.c sets it) and every EB0..EB3 gate the binding header lists; the bit of each follows the header's ID order, which matches every gate the SDK driver already had.
The Axera UART is a plain DesignWare APB UART; the vendor devicetree names it axera,ax-apb-uart. Match it in 8250_dw and as an earlycon.
…ay stubs
The Axera SDK SoC drivers the vendor media modules and their user space
expect: /proc/ax_proc/{chip_type,board_id,uid} (ax_hwinfo),
ax_os_mem_* per-module allocation accounting, ax_hrtimer on the DW
timer, the DDR bandwidth limiter, /dev/ax_sysmap, the APB/periph
timer32 channels and ax_display_register() stubs for builds without
DRM. Ported to 5.15 (proc_ops, ax_printk.h).
The closed AX620E modules (ax_sys, ax_cmm, ax_pool, ax_npu, ax_ivps, ax_venc, ...) are built against Axera's 5.15.73 kernel, which carries the OSAL (AX_OSAL_*) built in and creates /proc/ax_proc at boot. This is the SDK's kernel/osal/linux OSAL with the export names of the vendor 5.15 kernel (AX_OSAL_SYNC_wait_* without the leading __, checked against the stock kernel's code), plus: - /proc/ax_proc, /proc/ax_proc/version and the ax_printk log (/proc/ax_proc/kmsg; errors also go to the kernel log), which the vendor kernel keeps in fs/proc and kernel/printk; - platform_device/platform_driver pointers OSAL's platform and devfreq wrappers hang their data on, as in the vendor kernel. With this all 265 kernel imports of the 21 stock modules resolve.
…MAPER The AX620E boot flash sits on a DW SSI (snps,dwc-ssi-1.03a) with a GPIO chip select. Axera's driver (from the SDK 4.19.125 kernel) runs it polled with enhanced dual/quad reads and AX_DMAPER receive DMA; the upstream spi-dw core needs the EEPROM-read mode and the IRQ instead. Ported to 5.15 as SPI_AXERA/SPI_AXERA_MMIO/SPI_AXERA_DMA, plus the AX_DMAPER dmaengine driver (axera,dma-per). The polled loop gets a one second timeout so a dead controller no longer hangs the boot.
From the Axera SDK 4.19.125 kernel: clocks, EMAC/EPHY resets (the EPHY must be taken out of shutdown and reset before the MAC sees a PHY), RMII/RGMII selection and speed setup for axera,dwmac-4.10a.
From the Axera SDK 4.19.125 kernel: the Ethernet PHY built into the AX620E (id 0x00441400) the IP cameras use over RMII.
stmmac_probe_config_dt() only knows snps,dwmac-4.10a as GMAC4; under axera,dwmac-4.10a the core came up as a DWMAC100 with no PHY. Do in the glue what the SDK did by patching stmmac_platform.c.
ax620e-xm-ipc.dts is the devicetree the camera's stock 5.15.73 kernel boots with (FIT in /boot/uImage of the IVG-A6 firmware), turned back into source with labels (dtb -> dts, phandles -> &labels named after the SDK's AX620E.dtsi; it compiles back to the same tree). It keeps the vendor nodes (axera,cmm, axera,sys, axera,npu, venc, ivps, ...) the closed media modules bind to, the spin-table CPU release (the NOR camera has no ATF) and leaves bootargs to U-Boot. ax620e_xm_ipc_defconfig: a camera kernel for it, built in what the board needs (clocks, pinctrl, GPIO, resets, vendor SPI NOR, DMAPER, EQOS + EPHY, UART, I2C, watchdog, OSAL), squashfs xz + jffs2 + overlay on MTD, modules on. Matches the vendor kernel where the closed ax_*.ko depend on it: SMP, PREEMPT, HZ=100, module unload, no modversions, and KPROBES (struct module is 0x300 bytes with exit at 0x2e0 in the vendor .ko). Build with an empty LOCALVERSION: the modules' vermagic is 5.15.73.
The AX620E vendor kernel calls its boot NOR spi_nor.0, and the camera's U-Boot environment and user space pass mtdparts=spi_nor.0:...; without it the partitions are never created. Take the name from the flash node's label property when there is one (dev_name() otherwise).
From the Axera SDK 4.19.125 kernel, ported to 5.15. Without PSCI (the NOR cameras have no ATF) the watchdog's restart handler is the only way to reboot; without it "reboot" hangs. The AX620E vendor 5.15 devicetree has one reg and none of the SDK's clk_set/aclk/pclk/arst/prst cells (the bootloader leaves the block clocked and out of reset), so that block is optional. The watchdog is left stopped until user space opens it, as the vendor kernel does: the Xiongmai user space opens /dev/watchdog and gives up when its own ioctl fails, which must not end in a reset.
PR Summary by QodoAdd AX620E camera support to the 5.15.73 Axera kernel
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
…led open AX_OSAL_DEV_i2c_read() uses one 4-byte stack buffer for the register address and the reply but took both lengths from the caller: reject anything but the 8/16-bit addresses and values it decodes. The platform resource helpers copied strlen(name) bytes into the 32-byte AXERA_RESOURCE.name: an unnamed resource dereferenced NULL, a long one overran the caller's struct. Copy with strscpy(). osal_open() leaked its per-file data when the module's open callback failed (release is not called after a failed open).
A 32-byte write to the bw_limiter register entry filled kbuf[32] with no terminator before sscanf(). Accept at most 31 bytes and terminate.
Probe passed an uninitialised clk_id to the gate writes whenever the node had no SDK "ax_clk_id" property, which is the case for every GPIO node of the AX620E devicetree: those carry clocks = <clk_gpio>, <pclk_gpio> instead. Enable those through the clock framework, keep "ax_clk_id" as the fallback for SDK devicetrees, and pass reset lookup errors (-EPROBE_DEFER) through instead of -ENODEV.
remove() freed the shared IRQ with a NULL dev_id, so the handler stayed installed (and the core warned) after the state it uses was gone. And probe trusted the lp-status element count from the devicetree although the arrays it fills hold LP_GPIO_MAX (8) entries.
A failed IRQ request called watchdog_unregister_device() on the not yet assigned (and not registered) wdd pointer; just unwind the proc entry. A failed proc_create() or a missing SDK clock/reset cell returned 0 instead of an error.
…n remove Probe returned 0 when dma_pool_create() or kmem_cache_create() failed (with the OF controller already registered and descriptors to be allocated from a NULL cache), and its error path unwound only the request-register mapping. remove() emptied the channel list by hand before the managed dmaengine unregistration ran, so the channels were never unregistered, and it leaked the descriptor pool and the mapping. Allocate the pool and cache first, register the device unmanaged, unwind every step on failure, and tear down in reverse order on remove.
The interrupt handler called timer callbacks with ax_hrtimer_lock held, so a callback that stopped or started a timer deadlocked on it. Expired callback timers now leave the tree under the lock and their callbacks run after it is dropped; a timer whose callback asks for a restart is queued again unless it was stopped meanwhile. ax_hrtimer_destroy() freed a timer that could still be in the tree or in its callback: it now detaches a queued timer and waits for a running callback first. A queued timer can no longer be started twice, the hardware's current-timer pointer no longer outlives the tree's last timer, and AX_OSAL_DEV_hrtimer_alloc() checks the allocation.
…acks The interrupt handler rearmed the timer and queued the owner's callback without looking at the state that close() clears, and close() did not wait for either: a racing interrupt could rearm a closed, clock-gated timer, and a queued callback could still run for the former owner. Check the state under the lock in the handler (and take the lock with interrupts off elsewhere), then synchronize with the IRQ and cancel the work in close() before gating the clocks. Also: check the timer index before using it, set up the lock and work before requesting the IRQ, and return the IRQ request's error.
/dev/ax_sysmap mapped any physical range the caller named, and forced PTE_WRITE|PTE_DIRTY into the protection even for a PROT_READ mapping. Its user is the MSP library (libax_sys AX_SYS_Mmap/MmapCache and the dump tools built on it), which maps CMM buffers by physical address; the CMM is the DRAM above the kernel's mem= that ax_cmm hands out. Treat it like /dev/mem: require CAP_SYS_RAWIO, refuse ranges that overlap System RAM or wrap around, add the write/dirty bits only to writable mappings, create the node 0600 and report misc_register() failures.
…rs on The glue only knew the SDK's phy-rst-gpio, so the external PHY reset of a board that uses the standard phy-reset-gpios (ax630c.dts) was never toggled. Look the line up with the descriptor API under both names: phy-reset-gpios follows its flags, phy-rst-gpio keeps the SDK's raw "low = reset" driving. Lookup errors, -EPROBE_DEFER included, now fail probe, as do the errors of axera_dwmac_get_dts() and of the reset control lookups, which probe used to ignore before running the EMAC/EPHY reset sequence with error pointers.
The vendor devicetree (and the SDK's AX620E.dtsi) give gzipd a size of <0x1 0x0>, i.e. 4 GiB over RAM and every other device. The SDK driver ioremaps 0x4000 of it; the next block (hwspinlock) is at 0x10420000.
ax620e_lite and ax620u_lite build against the kernels in OpenIPC/linux#259 and #260; the axera-ax620e/u branch tarballs CI downloads do not have them yet. List both boards in UNBUILT_BOARDS with that reason, their board directories in UNBUILT_FAMILIES and their osdrv packages in NOT_BUILT, so --self-test passes; they move into ALL_BOARDS once the kernels merge.
The enhanced (dual/quad) transfer path, which this driver always uses, runs a transfer TX-only or RX-only: with both buffers set it dropped the receive side and still reported success. Advertise SPI_CONTROLLER_HALF_DUPLEX so that the core refuses such transfers (spi-mem, i.e. the NOR, only issues one-direction transfers). dw_spi_dma_register() was called under CONFIG_SPI_DW_DMA, the SDK's name for the option, which this port renamed to CONFIG_SPI_AXERA_DMA: the DMA code was built but never used and every NOR transfer was PIO. Call it unconditionally, the header stubs it without SPI_AXERA_DMA. As in the SDK (SPI_DW_DMA=y), transfers longer than the FIFO now go over AX_DMAPER.
|
Thanks for the review. All 19 findings were real, and each is now fixed in its own commit on top of the branch (c277dfd..acc58f2):
Re-verified in QEMU (
Compile-checked as well: timer32 and deb-gpio-lp, which the defconfig does not enable. |
|
Re-review follow-up: Qodo marked 18 of the 19 findings resolved and raised no new ones. #5 (ax_wdt uses an uninitialised ret = devm_request_irq(&pdev->dev, ax_wdt->irq, ax_wdt_interrupt,
IRQF_SHARED, KBUILD_MODNAME, ax_wdt);
if (ret) {
pr_err("err %d\n", ret);
goto err_proc;
}The snippet the finding quotes is from the original diff, not from the current head. |
Axera's kernel support for the AX620E IP-camera SoC (2x Cortex-A53), ported from Axera's SDK kernel (4.19.125) to 5.15.73 — the version the AX620E camera's vendor media modules (
ax_*.ko) are built against. With it, OpenIPC firmware for the AX620E boots and loads the full vendor driver stack.What's in it (13 commits on
axera-ax620e)axera,ax-apb-gpio) and reset-controller drivers; the remaining peripheral clock gates (UART, GPIO, I2C, timers, PWM); the Axera UART in8250_dw./proc/ax_proc(the ~265 kernel symbols the vendorax_*.koimport all resolve).label(the stock layout'sspi_nor.0).ax_wdt), which is also the reboot path.arm64: dts: axera: the Xiongmai AX620E IP camera devicetree (from the stock camera's own DTB, compiles back to an identical tree) andax620e_xm_ipc_defconfig.Vendor-module ABI notes: the stock kernel runs at HZ=100, the modules' module layout only matches with
CONFIG_KPROBES=y, and the release string must be exactly5.15.73.Tested (QEMU, OpenIPC/qemu-bench
-M ax620e)OpenIPC U-Boot → this kernel on both CPUs (vendor spin-table) → rootfs from NOR via the vendor SPI driver with the jffs2 overlay → login, DHCP, SSH;
load_axeraloads all 21 vendor modules with no oops (ax_vdecreports "Unknown HW" exactly as on the stock firmware, because QEMU has no decoder model); watchdog reboot works.Not yet ported: RTC, thermal, SD, USB, audio, display; no mtdsplit. Not yet verified on real hardware: EPHY setup, watchdog reboot sequence, dual-mode SPI reads, clock-gate bits derived from the binding's ID order.
Used by the AX620E part of OpenIPC/firmware#2670.