diff --git a/br-ext-chip-anyka/board/ak3918ev300/ak3918ev200.generic.config b/br-ext-chip-anyka/board/ak3918ev300/ak3918ev200.generic.config index 2256e25a53..4a0db78e8e 100644 --- a/br-ext-chip-anyka/board/ak3918ev300/ak3918ev200.generic.config +++ b/br-ext-chip-anyka/board/ak3918ev300/ak3918ev200.generic.config @@ -17,7 +17,7 @@ CONFIG_NEED_DMA_MAP_STATE=y CONFIG_ARCH_SUPPORTS_UPROBES=y CONFIG_VECTORS_BASE=0xffff0000 # CONFIG_ARM_PATCH_PHYS_VIRT is not set -CONFIG_PHYS_OFFSET=0x81800000 +CONFIG_PHYS_OFFSET=0x80000000 CONFIG_GENERIC_BUG=y CONFIG_PGTABLE_LEVELS=2 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" @@ -280,6 +280,7 @@ CONFIG_VIDEO_RESERVED_MEM_SIZE=0x1800000 # CONFIG_MACH_AK39EV330 is not set CONFIG_MACH_AK3918EV200=y CONFIG_AK39_SYSCTRL_5TIMERS=y +CONFIG_AK_RMEM=y CONFIG_AK3918_FAMILY=y CONFIG_AK_OPENIPC_DTB="ak3918ev200-demb" CONFIG_CPU_AK3918EV200=y @@ -1442,7 +1443,6 @@ CONFIG_VIDEO_V4L2=y # CONFIG_VIDEO_FIXED_MINOR_RANGES is not set CONFIG_V4L2_MEM2MEM_DEV=y CONFIG_VIDEOBUF_GEN=y -CONFIG_VIDEOBUF_DMA_CONTIG=y CONFIG_VIDEOBUF2_CORE=y CONFIG_VIDEOBUF2_MEMOPS=y CONFIG_VIDEOBUF2_DMA_CONTIG=y @@ -1457,23 +1457,32 @@ CONFIG_VIDEOBUF2_DMA_CONTIG=y # Anyka platform video devices # CONFIG_VIDEO_AK_VENC=y +CONFIG_VIDEO_AK_CAM=y +CONFIG_VIDEO_AK_CAM_SENSOR=y CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_SOC_CAMERA=y CONFIG_SOC_CAMERA_PLATFORM=y -CONFIG_VIDEO_AK=y +# CONFIG_VIDEO_AK is not set CONFIG_AK_ISP_CORE=y CONFIG_SENSOR_GC1084=y CONFIG_SENSOR_AR0130_ISP2=y CONFIG_SENSOR_BF3703=y CONFIG_SENSOR_F22_F23_F28_F35_F37=y +CONFIG_SENSOR_GC1024=y +CONFIG_SENSOR_GC1034=y CONFIG_SENSOR_GC1054=y CONFIG_SENSOR_GC2053=y +CONFIG_SENSOR_H62=y CONFIG_SENSOR_H63=y CONFIG_SENSOR_H65=y CONFIG_SENSOR_IMX307=y CONFIG_SENSOR_PS5260=y +CONFIG_SENSOR_SC1135=y +CONFIG_SENSOR_SC1145=y CONFIG_SENSOR_SC1235=y CONFIG_SENSOR_SC1245=y +CONFIG_SENSOR_SC1345=y +CONFIG_SENSOR_SC2232=y CONFIG_SENSOR_SC2232H_SC2135E=y CONFIG_SENSOR_SC2235=y CONFIG_SENSOR_SC2239_SC2332_SC2335=y diff --git a/br-ext-chip-anyka/configs/ak3918ev200_lite_defconfig b/br-ext-chip-anyka/configs/ak3918ev200_lite_defconfig index f4ab875f2c..96734ea9e2 100644 --- a/br-ext-chip-anyka/configs/ak3918ev200_lite_defconfig +++ b/br-ext-chip-anyka/configs/ak3918ev200_lite_defconfig @@ -20,7 +20,7 @@ BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(EXTERNAL_VENDOR)/board/$(OPENIPC_SOC_FAMI # The uImage is the zImage with the board's DTB appended # (CONFIG_ARM_APPENDED_DTB), built by the kernel itself as on hisilicon. BR2_LINUX_KERNEL_UIMAGE=y -BR2_LINUX_KERNEL_UIMAGE_LOADADDR="0x81808000" +BR2_LINUX_KERNEL_UIMAGE_LOADADDR="0x80008000" BR2_LINUX_KERNEL_XZ=y # Filesystem @@ -49,6 +49,7 @@ BR2_OPENIPC_VARIANT="lite" BR2_OPENIPC_FLASH_SIZE="8" # Packages +BR2_PACKAGE_ANYKA_OSDRV_AK3918EV200=y BR2_PACKAGE_DROPBEAR_OPENIPC=y BR2_PACKAGE_IPCTOOL=y BR2_PACKAGE_LIBCURL_OPENIPC=y diff --git a/general/package/Config.in b/general/package/Config.in index c1f2e11cf7..f98e360ee8 100644 --- a/general/package/Config.in +++ b/general/package/Config.in @@ -3,6 +3,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/aic8800-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/allwinner-osdrv-v83x/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/allwinner-osdrv-v85x/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/anyka-osdrv-ak3918av130/Config.in" +source "$BR2_EXTERNAL_GENERAL_PATH/package/anyka-osdrv-ak3918ev200/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/atbm-wifi/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/atbm603x-comb-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/atbm60xx/Config.in" diff --git a/general/package/anyka-osdrv-ak3918ev200/Config.in b/general/package/anyka-osdrv-ak3918ev200/Config.in new file mode 100644 index 0000000000..b6435cb67d --- /dev/null +++ b/general/package/anyka-osdrv-ak3918ev200/Config.in @@ -0,0 +1,11 @@ +config BR2_PACKAGE_ANYKA_OSDRV_AK3918EV200 + bool "anyka-osdrv-ak3918ev200" + depends on BR2_LINUX_KERNEL + help + Anyka AK3918EV200 support files: the sensors' ISP tuning in + /etc/sensor, which the kernel's ISP driver loads by sensor name, + and the load_anyka script that keeps the bootloader's video + memory split (osmem, rmem) in the form the kernel expects. + The drivers themselves are built into the kernel. + + https://openipc.org diff --git a/general/package/anyka-osdrv-ak3918ev200/anyka-osdrv-ak3918ev200.mk b/general/package/anyka-osdrv-ak3918ev200/anyka-osdrv-ak3918ev200.mk new file mode 100644 index 0000000000..0523bc9fc5 --- /dev/null +++ b/general/package/anyka-osdrv-ak3918ev200/anyka-osdrv-ak3918ev200.mk @@ -0,0 +1,50 @@ +################################################################################ +# +# anyka-osdrv-ak3918ev200 +# +################################################################################ + +ANYKA_OSDRV_AK3918EV200_VERSION = +ANYKA_OSDRV_AK3918EV200_SITE = +ANYKA_OSDRV_AK3918EV200_LICENSE = PROPRIETARY + +# files/sensor/.conf is the ISP tuning of one sensor, named as +# ipctool names the sensor (`ipcinfo -s`), not always as the vendor did. +# The kernel's ISP driver (drivers/misc/ak_isp_tuning.c) reads +# /etc/sensor/.conf for the +# sensor it detected when capture first starts, so every file here is +# reachable and only the detected sensor's is read. +# +# Every file is a vendor tuning from the stock firmware of an AK3918EV200 +# camera, converted from the vendor's "3.0xx" layout to the "3.05_032401" +# one the kernel validates with files/sensor/convert-3.004.py. The +# conversion changes header fields only (version string, style count and +# style size) and gives each style style 0's sensor register list, the +# only one the kernel writes; no tuning value is changed. +# +# gc1004.conf isp_gc1024.conf v3.000 AK3918EV200 camera +# gc1034.conf isp_gc1034_0.conf v3.001 V380E2 camera +# jxh62.conf isp_h62.conf v3.004 AnyCloud39EV300 SDK +# (UVC_check_sensor; a webcam tuning, the only H62 one) +# sc1135.conf isp_sc1135_0.conf v3.015 V380E2 camera +# sc1145.conf isp_sc1145.conf v3.006 AK3918EV200 camera +# sc1235.conf isp_sc1235.conf v3.012 AK3918EV200 camera +# sc1345.conf isp_sc1345_dvp.conf v3.004 Gwell camera +# sc2145h.conf isp_sc1245.conf v3.011 AK3918EV200 camera +# sc2235p.conf isp_sc2232.conf v3.000 V380E2 camera +# +# Where a camera carried several, the newest generic one was taken. The +# EV300 and EV330 tunings ("4.x", "5.x") are laid out for other ISP +# libraries and are not usable here. + +define ANYKA_OSDRV_AK3918EV200_INSTALL_TARGET_CMDS + $(INSTALL) -m 755 -d $(TARGET_DIR)/etc/sensor + $(INSTALL) -m 644 -t $(TARGET_DIR)/etc/sensor \ + $(ANYKA_OSDRV_AK3918EV200_PKGDIR)/files/sensor/*.conf + + $(INSTALL) -m 755 -d $(TARGET_DIR)/usr/bin + $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin \ + $(ANYKA_OSDRV_AK3918EV200_PKGDIR)/files/script/load_anyka +endef + +$(eval $(generic-package)) diff --git a/general/package/anyka-osdrv-ak3918ev200/files/script/load_anyka b/general/package/anyka-osdrv-ak3918ev200/files/script/load_anyka new file mode 100755 index 0000000000..e755b08238 --- /dev/null +++ b/general/package/anyka-osdrv-ak3918ev200/files/script/load_anyka @@ -0,0 +1,37 @@ +#!/bin/sh +# +# AK3918EV200: the ISP, encoder and sensor drivers are built into the +# kernel, so there is nothing to load. The kernel gets its memory split as +# on the other OpenIPC SoCs: Linux has osmem (bootargs mem=${osmem}) and the +# video drivers the rest of totalmem. An environment that leaves video less +# than the vendor firmware's 24 MiB -- all of totalmem to Linux, as before +# this split existed, or any osmem too close to it -- cannot capture; it +# is brought down to the vendor split, once, and the camera rebooted. + +vendor=$(ipcinfo -v) +video_mem=24 + +log_vendor() { + logger -s -p daemon.info -t "${vendor:-anyka}" "$1" +} + +check_mem() { + total=$(fw_printenv -n totalmem 2>/dev/null | tr -d 'M') + os=$(fw_printenv -n osmem 2>/dev/null | tr -d 'M') + [ -n "$total" ] && [ "$total" -gt "$video_mem" ] || return + [ -z "$os" ] || [ $((total - os)) -lt "$video_mem" ] || return + + fw_setenv osmem "$((total - video_mem))M" || return + log_vendor "osmem $((total - video_mem))M of ${total}M, video ${video_mem}M; rebooting" + reboot +} + +case "$1" in + -i) + check_mem + ;; + *) + echo "Usage: $0 -i" + exit 1 + ;; +esac diff --git a/general/package/anyka-osdrv-ak3918ev200/files/sensor/convert-3.004.py b/general/package/anyka-osdrv-ak3918ev200/files/sensor/convert-3.004.py new file mode 100755 index 0000000000..942480c10f --- /dev/null +++ b/general/package/anyka-osdrv-ak3918ev200/files/sensor/convert-3.004.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +"""Convert an Anyka EV200 "3.004" ISP tuning file to the "3.05_032401" +layout that drivers/misc/ak_isp_tuning.c accepts. + +Both layouts carry the same 0x200-byte style header and the same 24 +modules (IDs 0x00-0x17) with identical sizes; each style ends with a +0x1c block holding the sensor register list. The kernel additionally +wants every style to be the same size (header field 0x24) and the file +to hold exactly header[0] styles. The 3.004 files give styles of +different length (the register lists differ) and a stale style count. + +Only style 0's register list is ever written to the sensor (the kernel +initialises the sensor from style 0 only), so later styles get style 0's +register list, which makes all styles the same size. +""" +import struct +import sys + +HEADER = 0x200 +VERSION = b"3.05_032401\0" +SIZES = [186, 192, 876, 2268, 1088, 86, 22, 876, 136, 106, 9966, 11096, + 206, 64, 6, 14, 4188, 260, 46, 528, 240, 30, 306, 996] + + +def styles(data): + off = 0 + while off + HEADER + 4 <= len(data): + mod = off + HEADER + for i, size in enumerate(SIZES): + mid, msize = struct.unpack_from(" len(data): + sys.exit(f"style at {off:#x}: sensor block id {sid:#x} size {ssize}") + yield data[off:mod], data[mod:mod + 4 + ssize] + off = mod + 4 + ssize + + +def main(src, dst): + data = open(src, "rb").read() + found = list(styles(data)) + if not found: + sys.exit("no styles found") + sensor_id = struct.unpack_from("