diff --git a/.github/workflows/pr-build-check.yml b/.github/workflows/pr-build-check.yml index ec22e34..32ca52d 100644 --- a/.github/workflows/pr-build-check.yml +++ b/.github/workflows/pr-build-check.yml @@ -148,7 +148,7 @@ jobs: cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release cmake --build build --target cYAML_test reginfo_test longse_test \ sensors_test anyka_test ambarella_test \ - hal_hisi_test novatek_test \ + hal_hisi_test novatek_test sstar_test \ report_test http_test mtd_alias_test \ nand_layout_test upgrade_env_test \ jffs2_test raw_image_test @@ -166,6 +166,7 @@ jobs: ./build/ambarella_test ./build/hal_hisi_test ./build/novatek_test + ./build/sstar_test # Run from the tree root: the fingerprint it compares against is # src/sensors_golden.txt, and a sensor that stopped being identified # has to fail here rather than be noticed on a camera in a ceiling. diff --git a/CLAUDE.md b/CLAUDE.md index a12dfb6..4531103 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -129,6 +129,10 @@ CMake knobs worth knowing: the sensor power-up, was run on an AK3918EV200 with OpenIPC's kernel. - `./build/ambarella_test`: the `/proc/cpuinfo` machine string the Ambarella HAL parses, same `CHECK` macro and same reason. +- `./build/sstar_test`: the model name `sstar_detect_cpu()` gives each + SigmaStar generation register value, answered by the test's own `mem_reg()` + (sstar.c is included, as novatek.c is). The family names those generations + print are checked at the end of `reginfo_test`. - `tools/test_pipeline.sh`: hardware-free end-to-end check of the sensor driver extraction pipeline (`trace_segment.py` -> `trace_to_driver.py` -> `gcc -fsyntax-only` -> `trace_diff.py`), plus the `--selftest` of every diff --git a/CMakeLists.txt b/CMakeLists.txt index 8605408..580f26f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -518,6 +518,14 @@ if(NOT ONLY_LIBRARY) target_compile_definitions(novatek_test PRIVATE STANDALONE_LIBRARY) target_link_libraries(novatek_test m Threads::Threads) + # The generation register's names, the one input sstar_detect_cpu() has, + # answered by the test's own mem_reg(); sstar.c is included for the same + # reason novatek.c is. + add_executable(sstar_test src/hal/sstar_test.c src/hal/common.c) + target_include_directories(sstar_test PRIVATE include src) + target_compile_definitions(sstar_test PRIVATE STANDALONE_LIBRARY) + target_link_libraries(sstar_test m Threads::Threads) + # Parsing only: longse.c itself pulls in cJSON and the HAL, and the part # worth testing off a camera is the version extraction, which is standalone. add_executable(longse_test src/boards/longse_test.c src/boards/longse.c diff --git a/src/chipid.c b/src/chipid.c index 8718496..8d10b1c 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -281,6 +281,10 @@ const char *getchipfamily() { case INFINITY3: return "infinity3"; #endif +#ifdef IPCHW_VENDOR_SSTAR + case INFINITY2M: + return "infinity2m"; +#endif #ifdef IPCHW_VENDOR_SSTAR case INFINITY5: return "infinity5"; diff --git a/src/hal/sstar.c b/src/hal/sstar.c index a7ccf99..4a6aad5 100644 --- a/src/hal/sstar.c +++ b/src/hal/sstar.c @@ -56,6 +56,13 @@ bool sstar_detect_cpu(char *chip_name) { chip_generation = val; switch (val) { + case INFINITY2M: + /* SSD201/SSD202 and the SSR62x NVR parts are one generation and + * nothing read here tells them apart, so the name is the group's, + * as for the others. An SSR621Q (Jooan JA-8108 NVR) with the BROM + * tag ...I2m_ROM... was reported as "unknown" before this case. */ + strcpy(chip_name, "SSD20X"); + break; case INFINITY5: strcpy(chip_name, "SSC32X"); break; diff --git a/src/hal/sstar_test.c b/src/hal/sstar_test.c new file mode 100644 index 0000000..cb11ae7 --- /dev/null +++ b/src/hal/sstar_test.c @@ -0,0 +1,87 @@ +/* The SigmaStar generation register as sstar_detect_cpu() names it. + * + * Each generation's name is pinned here: dropping or renaming a case puts that + * generation back to "unknown" in every report, which is what Infinity2M + * (0xF0) did until it had one (an SSR621Q in a Jooan JA-8108 NVR, BROM tag + * ...I2m_ROM...). + * + * CHECK rather than assert(), because the release flags carry -DNDEBUG and + * would compile an assert-based test into one that passes unconditionally. + * + * sstar.c is included rather than linked, for the same reason novatek_test.c + * includes novatek.c: the register read is mem_reg(), answered here. */ +#include +#include +#include +#include + +#include "hal/sstar.c" + +static int failures; + +#define CHECK(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, " FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ + failures++; \ + } \ + } while (0) + +static uint32_t generation_reg; /* what SSTAR_ADDR reads */ +static bool mmio_fails; /* /dev/mem withheld */ + +bool mem_reg(uint32_t addr, uint32_t *data, enum REG_OPS op) { + if (mmio_fails || op != OP_READ || addr != SSTAR_ADDR) + return false; + *data = generation_reg; + return true; +} + +/* The rest of sstar.c's externals; nothing below reads a file. */ +bool line_from_file(const char *filename, const char *re, char *buf, size_t n) { + (void)filename, (void)re, (void)buf, (void)n; + return false; +} +void disable_printk(void) {} +void restore_printk(void) {} +int chip_generation; +char chip_name[128]; + +static bool detects(uint32_t reg, const char *want) { + generation_reg = reg; + chip_generation = 0; + strcpy(chip_name, "unknown"); + char name[128] = "unknown"; + bool ok = sstar_detect_cpu(name); + if (!ok || strcmp(name, want) || chip_generation != (int)reg) { + fprintf(stderr, " 0x%02X: %s (%d), want %s\n", reg, name, ok, want); + return false; + } + return true; +} + +int main(void) { + CHECK(detects(INFINITY2M, "SSD20X")); + CHECK(detects(INFINITY5, "SSC32X")); + CHECK(detects(INFINITY6, "SSC32X")); + CHECK(detects(INFINITY6B, "SSC33X")); + CHECK(detects(INFINITY6E, "SSC33X")); + CHECK(detects(MERCURY6, "SSC35X")); + CHECK(detects(INFINITY6C, "SSC37X")); + CHECK(detects(INFINITY6F, "SSC37X")); + + /* A generation with no case is still SigmaStar's, just unnamed. */ + CHECK(detects(PIONEER3, "unknown")); + + /* No /dev/mem: not detected at all. */ + mmio_fails = true; + char name[128] = "unknown"; + CHECK(!sstar_detect_cpu(name)); + mmio_fails = false; + + if (failures) + fprintf(stderr, "sstar_test: %d failure(s)\n", failures); + else + printf("sstar_test: ok\n"); + return failures ? 1 : 0; +} diff --git a/src/reginfo_test.c b/src/reginfo_test.c index 030a383..8d709f5 100644 --- a/src/reginfo_test.c +++ b/src/reginfo_test.c @@ -1670,6 +1670,35 @@ static void test_xm(void) { } #endif +#ifdef IPCHW_VENDOR_SSTAR +/* The family the report prints for each SigmaStar generation that has one. + * getchipfamily() asks getchipname() first, which on a host finds no vendor + * and leaves chip_generation alone; the switch then answers from it. Runs + * last, since that detection attempt rewrites chip_name. */ +static void test_sstar_families(void) { + static const struct { + int generation; + const char *family; + } want[] = { + {INFINITY2M, "infinity2m"}, {INFINITY3, "infinity3"}, + {INFINITY5, "infinity5"}, {INFINITY6, "infinity6"}, + {INFINITY6B, "infinity6b0"}, {INFINITY6C, "infinity6c"}, + {INFINITY6E, "infinity6e"}, + }; + + puts("SigmaStar: family names"); + for (size_t i = 0; i < sizeof(want) / sizeof(*want); i++) { + as_chip(want[i].generation, "unknown"); + const char *got = getchipfamily(); + if (!got || strcmp(got, want[i].family)) { + fprintf(stderr, " FAIL 0x%02X: %s, want %s\n", want[i].generation, + got ? got : "(null)", want[i].family); + failures++; + } + } +} +#endif + int main(void) { /* Every register the tests below touch is one of these, not a camera's. */ padmux_set_io(&FAKE_IO); @@ -1719,6 +1748,9 @@ int main(void) { #endif test_refusals_do_not_exit(); test_table_integrity(); +#ifdef IPCHW_VENDOR_SSTAR + test_sstar_families(); +#endif if (failures) { fprintf(stderr, "\n%d check(s) failed\n", failures);