Skip to content
Draft
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
6 changes: 5 additions & 1 deletion .github/workflows/pr-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ jobs:
run: |
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --target cYAML_test reginfo_test longse_test \
sensors_test anyka_test hal_hisi_test \
sensors_test anyka_test novatek_test \
novatek_arm_test novatek_aarch64_test hal_hisi_test \
report_test http_test mtd_alias_test \
nand_layout_test
./build/cYAML_test
Expand All @@ -150,6 +151,9 @@ jobs:
./build/reginfo_test
./build/longse_test
./build/anyka_test
./build/novatek_test
./build/novatek_arm_test
./build/novatek_aarch64_test
./build/hal_hisi_test
# Run from the tree root: the fingerprint it compares against is
# src/sensors_golden.txt, and a sensor that stopped being identified
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,21 @@ if(NOT ONLY_LIBRARY)
target_include_directories(anyka_test PRIVATE include src)
target_link_libraries(anyka_test m Threads::Threads)

# Includes novatek.c so only its hardware file paths are redirected.
# Not STANDALONE_LIBRARY: the NA51023 code is ipctool-only, so the test
# is built the way ipctool is.
foreach(_nvt_test novatek_test novatek_arm_test novatek_aarch64_test)
add_executable(${_nvt_test} src/hal/novatek_test.c src/hal/common.c
src/sensors.c src/tools.c src/cjson/cJSON.c
${VERSION_OBJ})
target_include_directories(${_nvt_test} PRIVATE include src)
target_compile_definitions(${_nvt_test} PRIVATE IPCHW_VENDOR_NOVATEK)
target_link_libraries(${_nvt_test} m Threads::Threads
"-Wl,--wrap=open" "-Wl,--wrap=disable_printk")
endforeach()
target_compile_definitions(novatek_arm_test PRIVATE NOVATEK_TEST_ARM)
target_compile_definitions(novatek_aarch64_test PRIVATE NOVATEK_TEST_AARCH64)

# The body `ipctool upload` sends: part framing, the backup's layout and
# the length that must match it, and openipc.org's answer. Off a camera,
# like the others.
Expand Down
8 changes: 8 additions & 0 deletions src/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ static const manufacturers_t manufacturers[] = {
{"isvp", ingenic_detect_cpu, VENDOR_INGENIC, setup_hal_ingenic},
{"ingenic", ingenic_detect_cpu, VENDOR_INGENIC, setup_hal_ingenic},
#endif
#if defined(IPCHW_VENDOR_NOVATEK) && !defined(STANDALONE_LIBRARY)
{NULL, novatek_detect_mips_cpu, VENDOR_NOVATEK, novatek_setup_hal},
#endif
#endif
#ifdef __arm__
#ifdef IPCHW_VENDOR_SSTAR
Expand Down Expand Up @@ -238,6 +241,11 @@ const char *getchipname() {
const char *getchipfamily() {
const char *chip_name = getchipname();
switch (chip_generation) {
#if defined(IPCHW_VENDOR_NOVATEK) && !defined(STANDALONE_LIBRARY) && \
(defined(mips) || defined(__mips__) || defined(__mips))
case CHIP_NA51023:
return "nt9851x";
#endif
#ifdef IPCHW_HISI_V1
case HISI_V1:
return "hi3516cv100";
Expand Down
65 changes: 64 additions & 1 deletion src/hal/novatek.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,51 @@ static bool nvt_get_chip_id() {
return true;
}

#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
static void nvt_refine_na51023(char *chip_name) {
char buf[16];

/* The device-tree model names a die shared by more than one part.
* Parse the factory declaration as data; never source it. Missing or
* different profiles retain the NA51023 identity. */
chip_generation = CHIP_NA51023;
if (line_from_file("/etc/profile_prjcfg",
"^export CHIP=\"(98513)\"[[:space:]]*$", buf,
sizeof(buf)))
strcpy(chip_name, "NT98513");
}

bool novatek_detect_mips_cpu(char *chip_name) {
char buf[16];

/* Only this MIPS model has a verified identity and rejecting HAL.
* Other Novatek models and the ARM chip-ID proc ABI must not select
* the existing ARM sensor/HDAL backend through MIPS dispatch. */
if (!line_from_file("/proc/device-tree/model",
"^Novatek (NA51023)([[:space:]]|$)", buf, sizeof(buf)))
return false;
strcpy(chip_name, buf);
nvt_refine_na51023(chip_name);
return true;
}
#endif

bool novatek_detect_cpu(char *chip_name) {
char buf[256];

if(nvt_get_chip_id())
return true;

if (!line_from_file("/proc/device-tree/model", "Novatek ([A-Z]+[0-9]+)",
if (!line_from_file("/proc/device-tree/model",
#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
"^Novatek ([A-Z]+[0-9]+)([[:space:]]|$)",
#else
/* Keep the existing ARM/AArch64 parser unchanged.
* The new MIPS route has its own strict detector. */
"Novatek ([A-Z]+[0-9]+)",
#endif
buf, sizeof(buf))) {
/* NA51055 has a pad table and no part name the ID can give; with
* no device-tree model either, the die is the name. */
Expand All @@ -76,6 +114,12 @@ bool novatek_detect_cpu(char *chip_name) {

strcpy(chip_name, buf);

#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
if (!strcmp(buf, "NA51023"))
nvt_refine_na51023(chip_name);
#endif

return true;
}

Expand Down Expand Up @@ -118,7 +162,26 @@ static int novatek_open_i2c_fd(int i2c_adapter_nr) {
return universal_open_sensor_fd(adapter_name);
}

#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
static int novatek_no_sensor_bus(int adapter_nr) {
(void)adapter_nr;
return -1;
}
#endif

void novatek_setup_hal() {
#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
/* This MIPS generation delegates media to uITRON. The ARM HDAL memory
* report, sensor I2C bus and register tables below are not its ABI. */
if (chip_generation == CHIP_NA51023) {
possible_i2c_addrs = NULL;
open_i2c_sensor_fd = novatek_no_sensor_bus;
open_spi_sensor_fd = NULL;
return;
}
#endif
possible_i2c_addrs = novatek_possible_i2c_addrs;
i2c_change_addr = i2c_changenshift_addr;
open_i2c_sensor_fd = novatek_open_i2c_fd;
Expand Down
10 changes: 10 additions & 0 deletions src/hal/novatek.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <stdbool.h>

bool novatek_detect_cpu(char *chip_name);
/* NA51023 (MIPS, sold as NT98513) is identified by ipctool alone. No camera
* that carries libipchw is one, so the library must not pay for it: ipcinfo
* ships on boards whose rootfs leaves tens of KB spare. */
#if (defined(mips) || defined(__mips__) || defined(__mips)) && \
!defined(STANDALONE_LIBRARY)
bool novatek_detect_mips_cpu(char *chip_name);
#endif
unsigned long novatek_totalmem(unsigned long *media_mem);
void novatek_setup_hal();

Expand All @@ -22,6 +29,9 @@ void novatek_setup_hal();
/* TOP + 0xF0 bits [31:16], also /proc/nvt_info/nvt_pinmux/chip_id. One ID
* per die; the parts cut from a die are told apart by eFuse/OTP words. */
enum CHIP_ID {
/* Software family discriminator, not a TOP chip-ID register value.
* The MIPS SDK supplies a device-tree model but no verified chip_id. */
CHIP_NA51023 = 0x51023,
CHIP_NA51055 = 0x4821, // NT9852x: NT98520, NT98525
CHIP_NA51084 = 0x5021, // NT98528, NT98529 (the 1.2 GHz part, by OTP)
CHIP_NA51089 = 0x7021, // NT98562 (64 MB internal RAM),
Expand Down
Loading
Loading