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
70 changes: 45 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,35 @@ endif()

include_directories(./src/)

set(COMMON_LIB_SRC
# Vendor HALs are only reachable through the detection table in chipid.c, so a
# consumer that already knows its SoC family can drop the ones it can never run
# on. The HiSilicon HAL stays in unconditionally — chipid.c dispatches to it
# directly rather than through the table. Affects libipchw only; the ipctool
# executable is a diagnostic tool and always carries every vendor.
set(IPCHW_OPTIONAL_VENDORS
allwinner bcm fh gm ingenic novatek rockchip sstar tegra xilinx xm)
set(IPCHW_VENDORS "all" CACHE STRING
"Vendor HALs to compile into libipchw: 'all', 'none', or a ;-separated \
subset of: ${IPCHW_OPTIONAL_VENDORS}")

if(IPCHW_VENDORS STREQUAL "all")
set(_ipchw_selected ${IPCHW_OPTIONAL_VENDORS})
elseif(IPCHW_VENDORS STREQUAL "none")
set(_ipchw_selected "")
else()
set(_ipchw_selected ${IPCHW_VENDORS})
endif()

set(COMMON_LIB_SRC_BASE
src/chipid.c
src/chipid.h
src/cjson/cJSON.c
src/cjson/cJSON.h
src/hal/allwinner.c
src/hal/allwinner.h
src/hal/bcm.c
src/hal/bcm.h
src/hal/common.c
src/hal/common.h
src/hal/fh.c
src/hal/fh.h
src/hal/gm.c
src/hal/gm.h
src/hal/hisi/hal_hisi.c
src/hal/hisi/hal_hisi.h
src/hal/hisi/ispreg.c
src/hal/ingenic.c
src/hal/ingenic.h
src/hal/novatek.c
src/hal/novatek.h
src/hal/rockchip.c
src/hal/rockchip.h
src/hal/sstar.c
src/hal/sstar.h
src/hal/tegra.c
src/hal/tegra.h
src/hal/xilinx.c
src/hal/xilinx.h
src/hal/xm.c
src/hal/xm.h
src/hwinfo.c
src/hwinfo.h
src/mmap.h
Expand All @@ -76,6 +73,28 @@ set(COMMON_LIB_SRC
src/tools.h
src/version.h)

# Full set, used by the ipctool executable
set(COMMON_LIB_SRC_ALL ${COMMON_LIB_SRC_BASE})
foreach(_v IN LISTS IPCHW_OPTIONAL_VENDORS)
list(APPEND COMMON_LIB_SRC_ALL src/hal/${_v}.c src/hal/${_v}.h)
string(TOUPPER ${_v} _V)
list(APPEND IPCHW_ALL_VENDOR_DEFS IPCHW_VENDOR_${_V})
endforeach()

# Selected subset, used by libipchw
set(COMMON_LIB_SRC ${COMMON_LIB_SRC_BASE})
foreach(_v IN LISTS _ipchw_selected)
if(NOT _v IN_LIST IPCHW_OPTIONAL_VENDORS)
message(FATAL_ERROR
"IPCHW_VENDORS: unknown vendor '${_v}'; "
"expected 'all', 'none', or a subset of ${IPCHW_OPTIONAL_VENDORS}")
endif()
list(APPEND COMMON_LIB_SRC src/hal/${_v}.c src/hal/${_v}.h)
string(TOUPPER ${_v} _V)
list(APPEND IPCHW_VENDOR_DEFS IPCHW_VENDOR_${_V})
endforeach()
message(STATUS "libipchw vendor HALs: hisi ${_ipchw_selected}")

set(IPCTOOL_SRC
src/backup.c
src/backup.h
Expand Down Expand Up @@ -161,11 +180,12 @@ set(CYAML_TEST_SRC
src/cjson/cYAML.h)

add_library(ipchw STATIC ${COMMON_LIB_SRC})
target_compile_definitions(ipchw PUBLIC STANDALONE_LIBRARY)
target_compile_definitions(ipchw PUBLIC STANDALONE_LIBRARY ${IPCHW_VENDOR_DEFS})
target_link_libraries(ipchw m)

if(NOT ONLY_LIBRARY)
add_executable(ipctool ${IPCTOOL_SRC} ${COMMON_LIB_SRC})
add_executable(ipctool ${IPCTOOL_SRC} ${COMMON_LIB_SRC_ALL})
target_compile_definitions(ipctool PRIVATE ${IPCHW_ALL_VENDOR_DEFS})

target_link_libraries(ipctool m)
install(TARGETS ipctool RUNTIME DESTINATION /usr/bin/)
Expand Down
2 changes: 2 additions & 0 deletions example/ipcinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ static void print_serial() {
const char *vendor = getchipvendor();
if (strstr(vendor, VENDOR_HISI) || strstr(vendor, VENDOR_GOKE))
hisi_ev300_get_die_id(serial, sizeof serial);
#ifdef IPCHW_VENDOR_SSTAR
if (strstr(vendor, VENDOR_SSTAR))
sstar_get_die_id(serial, sizeof serial);
#endif

if (!serial)
exit(EXIT_FAILURE);
Expand Down
32 changes: 31 additions & 1 deletion src/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,49 @@ typedef struct {

static const manufacturers_t manufacturers[] = {
#if defined(mips) || defined(__mips__) || defined(__mips)
#ifdef IPCHW_VENDOR_INGENIC
{"isvp", ingenic_detect_cpu, VENDOR_INGENIC, setup_hal_ingenic},
{"ingenic", ingenic_detect_cpu, VENDOR_INGENIC, setup_hal_ingenic},
#endif
#endif
#ifdef __arm__
#ifdef IPCHW_VENDOR_SSTAR
{"SStar", sstar_detect_cpu, VENDOR_SSTAR, sstar_setup_hal},
{"MStar", mstar_detect_cpu, NULL, sstar_setup_hal},
#endif
#ifdef IPCHW_VENDOR_NOVATEK
{"Novatek", novatek_detect_cpu, VENDOR_NOVATEK, novatek_setup_hal},
#endif
#ifdef IPCHW_VENDOR_GM
{"Grain", gm_detect_cpu, VENDOR_GM, gm_setup_hal},
#endif
#ifdef IPCHW_VENDOR_FH
{"FH", fh_detect_cpu, VENDOR_FH, fh_setup_hal},
#endif
#ifdef IPCHW_VENDOR_ROCKCHIP
{NULL /* Generic */, rockchip_detect_cpu, VENDOR_ROCKCHIP, rockchip_setup_hal},
#endif
#ifdef IPCHW_VENDOR_XILINX
{"Xilinx", xilinx_detect_cpu, NULL, xilinx_setup_hal},
#endif
#ifdef IPCHW_VENDOR_BCM
{"BCM", bcm_detect_cpu, VENDOR_BCM, bcm_setup_hal},
{NULL, allwinner_detect_cpu, VENDOR_ALLWINNER, allwinner_setup_hal}
#endif
#ifdef IPCHW_VENDOR_ALLWINNER
{NULL, allwinner_detect_cpu, VENDOR_ALLWINNER, allwinner_setup_hal},
#endif
#endif
#if defined(__aarch64__) || defined(_M_ARM64)
#ifdef IPCHW_VENDOR_NOVATEK
{NULL, novatek_detect_cpu, VENDOR_NOVATEK, novatek_setup_hal},
#endif
#ifdef IPCHW_VENDOR_TEGRA
{NULL, tegra_detect_cpu, "Nvidia", tegra_setup_hal},
#endif
#endif
/* Sentinel, so the array stays well-formed when every optional vendor is
* compiled out; generic_detect_cpu() skips entries without a detect_fn. */
{NULL, NULL, NULL, NULL},
};

static bool generic_detect_cpu() {
Expand All @@ -77,6 +102,9 @@ static bool generic_detect_cpu() {
strcpy(chip_manufacturer, buf);

for (size_t i = 0; i < ARRCNT(manufacturers); i++) {
if (!manufacturers[i].detect_fn)
continue;

if (manufacturers[i].pattern &&
strncmp(manufacturers[i].pattern, chip_manufacturer,
strlen(manufacturers[i].pattern)))
Expand Down Expand Up @@ -115,9 +143,11 @@ static bool hw_detect_system() {
return ret;
}
#ifdef __arm__
#ifdef IPCHW_VENDOR_XM
// xm510
case 0x10030000:
return detect_and_set("Xiongmai", xm_detect_cpu, setup_hal_xm, 0);
#endif
// hi3516cv300
case 0x12100000:
// hi3516ev200
Expand Down