Repository navigation
axera: AX620U on Axera's SDK kernel (4.19.125), all vendor media modules load - #260
Conversation
…9.125) Verbatim copy of kernel/linux/linux-4.19.125 from the Axera AX620E SDK (sipeed maix_ax620e_sdk, kernel HEAD fd3114bfd) on top of vanilla v4.19.125, so this commit is exactly Axera's diff against upstream: mach-axera (holding-pen SMP), drivers/clk/axera, drivers/pinctrl/axera, drivers/soc/axera, the DesignWare SPI/SPI-NAND driver Axera boots from, dwmac-axera, ax_printk/AXLOG, AX620E/AX620Q/AX630C devicetrees and defconfigs.
The SDK kernel builds only inside the SDK checkout: it compiles the OSAL from ../../../../../osal, the board pinmux tables from build/projects/ $(PROJECT) and moves the %.dtb/dtbs rules to boot/dts/axera. - import the OSAL (kernel/osal/linux/kernel + kernel/osal/include of the same SDK) as drivers/soc/axera/osal, built in (=y, as the SDK does) or as ax_osal.ko (=m); - AXERA_AX620E_PINMUX gates the SDK board pinmux tables (default y); - restore the upstream %.dtb/dtbs rules so buildroot's in-tree DTS handling works; SDK boards build as axera/<board>.dtb; - uvc_video: 64-bit modulo on arm32 (__aeabi_uldivmod link error).
AX620U is a different die from AX620E (own register map, root
compatible "axera,ax620x"), but its vendor kernel is the same Axera
4.19.125 BSP lineage, so the closed AX620U media modules (ax_osal,
ax_sys, ax_cmm, ... ax_audio, ax_pcal6416a, Xm*) load against this
kernel with the config below: vermagic "4.19.125 SMP preempt
mod_unload ARMv7 p2v8", every symbol they import resolves, and the
struct layouts they use match (the platform_device/driver fields the
SDK adds are in the AX620U BSP too).
- ax620u.dts: the stock camera devicetree (JFtech IPC_AX620U_A8 FIT,
fdt-1), with the SPI-NAND controller bound by the SDK spi-axera-mmio
driver ("snps,dwc-ssi-1.03a", flashclk + pclk).
- clk-ax620u: fixed-rate provider for the nine ax620x clock syscons
(the AX620U clock driver is not in the SDK; clk-ax620e binds the same
compatibles with AX620E's layout, so it is off for this board).
- mach-axera: the SDK holding pen also serves enable-method
"axera,ax620x-smp" (same /cpus/secondary-boot-reg release): 4 CPUs.
- ax620u_compat: the AX620U kernel's ax_printk/ax_vprintk take printk's
arguments (fmt first) where the SDK's AXLOG ones take (id, tag, level,
fmt): with AXERA_AX620U_COMPAT the SDK's become axlog_printk/
axlog_vprintk in-tree and the printk-style pair is exported. Also
ax_special_rtc_lock/unlock and read_adc_value (ax_rtc, ax_hwinfo).
- axera_ax620u_defconfig: the stock camera kernel's own config (from
its /proc/config.gz) moved onto this tree: ARCH_AX620E, SDK drivers
for AX620E-only blocks off, DRM off (display_dummy provides
ax_display_register for ax_vo), memory_dump off, OVERLAY_FS on. The
vendor modules bring their own OSAL, so AXERA_OSAL is off.
Boots in QEMU (-M ax620u) through the stock U-Boot from SPI NAND:
4 CPUs, rootfs on mtdblock4 through the SDK SPI-NAND driver, eth0; all
28 stock modules insmod in the stock loader's order with no oops.
Backport of the v5.5 behaviour (mtd_set_dev_defaults reads "label"): AX620U's devicetree labels its SPI NAND "spi4.0_nand", the mtd id the stock Xiongmai kernel uses, so the mtdparts= in the U-Boot env of every deployed camera keeps applying.
…620U's - axera-axi-dmac: devm_reset_control_get_optional() returns NULL for a devicetree without the reset, and IS_ERR_OR_NULL + PTR_ERR(NULL) ended the probe with 0 and no DMA device; AX620U's node (no reset, clock "core-clk") then left ax_dma_hal without a channel. Take NULL as no reset and fall back to the first clock. - fs/proc/axlogctl.c registers ax_proc/logctl, which AX620U's closed ax_logctl.ko creates itself (proc_dir_entry already registered warning): not built with AXERA_AX620U_COMPAT.
The SDK driver caps dma-channels at 1 (AX620E's DMAC); AX620U's devicetree has 2, so parse_device_properties() refused it (-EINVAL), no DMA device existed and ax_dma_hal could not get a channel (no /dev/axi_dma_hal). Allow up to 8, upstream dw-axi-dmac's limit; the stock AX620U kernel reports "DesignWare AXI DMA Controller, 2 channels" for the same node.
Same DesignWare timer-in-PWM-mode channels; AX620U's devicetree gives no clock-register window (the SDK driver pokes AX620E's clock block directly), so its channel clocks stay as the bootloader left them. The stock Xiongmai App writes /sys/class/pwm/pwmchip0/export without checking fopen() and crashes when no pwmchip exists.
….125 bring-up The previous axera-ax620u branch (vanilla v4.19.125 + a minimal defconfig and devicetree) had no Axera clock, SMP, OSAL or driver support, so the vendor ax_*.ko media modules could not run on it. This branch keeps the SDK-based tree; the old history stays reachable through this merge.
PR Summary by QodoPort AX620U camera support to Axera's 4.19.125 SDK kernel
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
cipher_create_handle() cleared s_cipher_chn[i] before checking that the scan found a free channel, so a fifth handle cleared the memory after the four-entry array. The RSA sign and verify ioctls copy u32_hash_size / 4 words of hash_result[16] into the command token without bounding u32_hash_size. Clear the channel only once one is found and reject a hash larger than hash_result[]. Not built by axera_ax620u_defconfig (CRYPTO_HW is off); AX620E only.
Backport of upstream commit d42334578eba ("exfat: check if filename
entries exceeds max filename length", v6.5) to the exfat copy in this
tree: a directory entry set with more file-name entries than
MAX_NAME_LENGTH allows overran the name buffer in
exfat_get_uniname_from_ext_entry() and exfat_find_dir_entry().
…free - draw_a_frame(): nothing ever maps a display into screen_base (frames reach user space through /proc/nanokvm), so the worker would memcpy host data to NULL; return early without a destination. RGB565 was decoded as a fixed 480x480 image into a 320x170x4 buffer: decode the received pixels only, bounded by rgb888x_buf. - lb_free_func() freed the function object while the worker thread still ran on it and lb_opts->ctx still pointed to it, so lb_free_instance() later used freed memory. Release the thread, procfs, kfifos and framebuffer file in lb_free_func() and clear ctx. Sipeed NanoKVM display gadget; not built by axera_ax620u_defconfig.
The /proc tool node (raw I2C reads/writes, reset, firmware update) was created 0777; make it 0600. Its read handler copied up to count bytes out of a buffer sized from a capped length, and its write handler strcpy()'d a not NUL-terminated user command into the 128-byte fw_file_name. Allocate at least count bytes (count limited to 64 KiB, at least the 4-byte status), and copy the name bounded and terminated. Sipeed board touchscreen; not built by axera_ax620u_defconfig.
The SDK relaxed (i_mode & 0677) != 0600 to (i_mode & 0600) != 0600, so a crash reused a pre-existing group/world-readable core file and wrote the process memory into it. Back to upstream.
The SDK replaced 'if (arm_pm_restart)' with 'if (0)' so Axera boards reboot through their restart handler instead of the PSCI/machine hook, which also left every board that only has arm_pm_restart halted. Run the restart handlers first and fall back to arm_pm_restart (the order upstream later adopted by turning arm_pm_restart into a handler). AX620U has no PSCI node and reboots through its restart handler either way.
The SDK commented out the args_count != of_reset_n_cells check for every reset controller because its AX620E controller mixes 3-, 4- and 10-cell specifiers in one node (its of_xlate checks args_count itself). Keep the check unless that driver is built; AX620U does not build it.
The SDK compiled out the 'nothing to do' return in clk_core_set_rate_nolock() for every clock provider, so setting a clock to its current rate ran the full notifier/set_rate path. The SDK gives no reason; keep its behaviour only with the AX620E clock driver it ships with, and restore upstream everywhere else. AX620U uses fixed-rate clocks (COMMON_CLK_AX620U), so nothing changes there.
serial8250_handle_irq() reads UART_LSR twice in the SDK and carried only BI over from the first read; reading LSR clears OE/PE/FE on 16550-class UARTs (AX620U's snps,dw-apb-uart included), so overrun, parity and framing errors were never reported. OR both reads.
stmmac_tx_timeout() only printed a debug line in the SDK; restore upstream's stmmac_global_err() so a stuck TX DMA resets the interface (AX620U eth0 is axera,dwmac-4.10a). The SDK's 200 s TX_TIMEO for DWMAC_AXERA is unchanged.
The SDK skipped the software wait in mmc_sleep() (and its new mmc_awake()) whenever an R1B response was used, so a host without MMC_CAP_WAIT_WHILE_BUSY could send the next command while the card was still busy, and it logged every sleep with pr_info. Restore upstream's condition and drop the extra pr_info.
The SDK dropped SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME for every generic dmaengine PCM to work around tinyalsa not resuming after suspend, so pause/resume returned -ENOSYS on every card. Back to upstream. AX620U's ALSA card (vendor ax_audio.ko) has its own PCM and does not use this code.
logctl_proc_write() parsed into two 64-byte stack arrays with widthless %s, and logctl_proc_init() registered the node even when axera_logctl_init() failed, leaving its handlers to dereference a NULL s_logctl_cfg. Use %63s and return the init error instead. Not built with AXERA_AX620U_COMPAT (AX620U's ax_logctl.ko owns the node).
The SDK's phy_reg sysfs attribute (on every PHY) wrote the page register 0x1f for each access and left it there, unlocked, so the PHY driver's next access could land on the diagnostic's page. Save the page, access and restore it under the MDIO bus lock; registers are 0..31.
…ig option The SDK defined SPI_NOR_WRITE_ENABLE_FOR_VOLATILE_STATUS_REGISTER at file scope, so every SPI-NOR status register write (write_sr_and_check, write_sr_cr, the unlock in spi_nor_init) used WRENVSR (50h) instead of WREN (06h); on Micron/ST parts 50h is CLFSR and the write is ignored. Move it behind MTD_SPI_NOR_WRENVSR, default y only on ARCH_AXERA so Axera's NOR boards keep their behaviour. AX620U does not build SPI-NOR.
The SDK's dw_spi_transfer_one() switches any DMA-eligible transfer to 32- or 16-bit frames by length, whatever word size the caller asked for. That is how its APB SSI DMA (APB_SPI_DW_DMA) moves data; keep it to that DMA so other can_dma() users keep their wire format. On AX620U APB_SPI_DW_DMA is off, the dw-apb-ssi nodes are disabled and the SPI-NAND is on the separate spi-axera-mmio driver, so nothing there reaches this path.
The SDK's probe read the optional "ax_clk_id" into an uninitialised int, ignored a missing property, and always ioremapped the AX620E peripheral clock block (0x4870000) to set its I2C mux and gate the bit for that id. AX620U's ten designware-i2c nodes have no ax_clk_id and a different register map, so every probe wrote AX620E bits at an address that is not that block on AX620U. Use the AX620E block only when ax_clk_id is present (and < 8); without it gate the devicetree clock the upstream way (i2c_dw_prepare_clk), and skip the RISC-V ownership bit that is indexed by the same id. The timings keep the SDK's 208 MHz basis: AX620U's clocks are fixed-rate stand-ins (clk-ax620u), so their rate would not be better.
It declares #!/bin/sh but used bash's [[ ]], so under dash every firmware-type test failed and no reserved-memory edit was made. Use [ "$A" = "$B" ].
The SDK's probe read the optional "ax_clk_id" into an uninitialised int, ignored a missing property, and always ioremapped the AX620E peripheral clock block (0x4870000) to set its I2C mux and gate the bit for that id. AX620U's ten designware-i2c nodes have no ax_clk_id and a different register map, so every probe wrote AX620E bits at an address that is not that block on AX620U. Use the AX620E block only when ax_clk_id is present (and < 8); without it gate the devicetree clock instead (the SDK removed i2c_dw_prepare_clk()), and skip the RISC-V ownership bit that is indexed by the same id. The timings keep the SDK's 208 MHz basis: AX620U's clocks are fixed-rate stand-ins (clk-ax620u), so their rate would not be better.
|
Thanks for the review. The import commit stays verbatim (it documents Axera's diff); the fixes are follow-up commits on top (743fcad..1f6d97f), one per topic. Memory-safety in Axera's drivers
Generic code Axera changed: upstream behaviour restored, or limited to the hardware that needs the vendor change
Verification: I built axera_ax620u_defconfig with the OpenIPC gcc 13.3 toolchain. The touched files that the camera config does not build were compile-tested with a config that enables them (crypto, f_udisp, spi-nor, axlogctl, hyn as an external module). I booted the new kernel in QEMU ( |
Replaces the minimal vanilla-4.19.125 AX620U bring-up with Axera's own SDK kernel (4.19.125 — exactly the version the AX620U camera's vendor media modules are built against) plus AX620U camera support. On the old branch there was no Axera clock, SMP, OSAL or driver support, so none of the vendor
ax_*.kocould run; on this one all of them load.What's in it
import the Axera AX620E SDK kernel— Axera's tree as shipped, so that commit is Axera's diff against upstream 4.19.125 (reviewable on its own).drivers/soc/axera/osal); board pinmux tables behind an option; upstream.dtbrules restored for buildroot; a 64-bit modulo link fix in uvc_video.axera,ax620x) camera support: devicetree from the stock camera's FIT; a fixed-rate clock provider (clk-ax620u); theaxera,ax620x-smpenable-method on the SDK's SMP code (all 4 CPUs); the AX620U modules'ax_printk/ax_vprintkconvention plusax_special_rtc_lock/unlock,read_adc_value(AXERA_AX620U_COMPAT);axera_ax620u_defconfig(the stock camera's config on this tree).label(keeps the stockspi4.0_nandmtd id); loop devices; AXI DMAC probes with an optional reset and allows AX620U's 2 channels; the SDK PWM driver bindsaxera,ax620x-pwm(the vendor App segfaults on a missing pwmchip).axera-ax620uso this PR merges cleanly; the tree is the SDK-based one.Finding worth knowing: AX620U is not register-compatible with AX620E (own map, UART at 0x4990000, own clock layout), but its kernel code base is the same lineage, so the vendor modules' struct layouts match the SDK tree; the only interface difference found is
ax_printk's argument order.Tested (QEMU, OpenIPC/qemu-bench
-M ax620u -smp 4)OpenIPC U-Boot → this kernel, 4 CPUs → UBIFS root from SPI NAND (standard OpenIPC all-in-UBI layout) with the
rootfs_dataoverlay persisting across reboot → login, DHCP, SSH; all 28 vendor modules load (ax_audio registers its ALSA card, ax_pcal6416a binds) with 0 oops/WARNING; the stock vendor camera App run on this kernel streams 3840x2160 HEVC over RTSP with 0 decode errors.Not yet: a real AX620U clock driver (every clock is a fixed 24 MHz stand-in — fine in QEMU, UART/SPI rates on real hardware unverified). Nothing tested on real hardware yet.
Used by the AX620U part of OpenIPC/firmware#2670.