Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions br-ext-chip-anyka/board/ak3918ev300/ak3918ev200.generic.config
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion br-ext-chip-anyka/configs/ak3918ev200_lite_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions general/package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions general/package/anyka-osdrv-ak3918ev200/Config.in
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
################################################################################
#
# anyka-osdrv-ak3918ev200
#
################################################################################

ANYKA_OSDRV_AK3918EV200_VERSION =
ANYKA_OSDRV_AK3918EV200_SITE =
ANYKA_OSDRV_AK3918EV200_LICENSE = PROPRIETARY

# files/sensor/<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/<name>.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))
37 changes: 37 additions & 0 deletions general/package/anyka-osdrv-ak3918ev200/files/script/load_anyka
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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("<HH", data, mod)
if mid != i or msize != size:
if i == 0:
return
sys.exit(f"style at {off:#x}: module {i} is id {mid:#x} size {msize}")
mod += size
sid, ssize = struct.unpack_from("<HH", data, mod)
# Unlike the modules, this size excludes the 4-byte block header.
if sid != 0x1c or ssize % 4 or mod + 4 + ssize > 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("<I", data, 0x14)[0]
regs = found[0][1]
out = []
for body, _ in found:
style = bytearray(body + regs)
struct.pack_into("<I", style, 0, len(found))
style[4:4 + len(VERSION)] = VERSION
struct.pack_into("<I", style, 0x24, len(style))
if struct.unpack_from("<I", style, 0x14)[0] != sensor_id:
sys.exit("styles disagree on the sensor id")
out.append(bytes(style))
open(dst, "wb").write(b"".join(out))
print(f"{dst}: sensor {sensor_id:#x}, {len(out)} styles x {len(out[0])} bytes, "
f"{(len(regs) - 4) // 4} sensor registers, last {regs[-4:].hex()}")


if __name__ == "__main__":
if len(sys.argv) != 3:
sys.exit(f"usage: {sys.argv[0]} vendor.conf isp.conf")
main(sys.argv[1], sys.argv[2])
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading