From: Chanwoo Choi Date: Mon, 13 Mar 2023 21:17:42 +0000 (+0900) Subject: tools: Add lshal tool to get hal backends X-Git-Tag: accepted/tizen/unified/20230424.185339~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F291600%2F2;p=platform%2Fhal%2Fapi%2Fcommon.git tools: Add lshal tool to get hal backends Provide lshal to get the detailed informaiton of hal backends on device. [Description of each attribute of lshal tool] - HAL Module Name : HAL Module Name (fixed, not be changed) - ID : HAL Module Unique ID (fixed, not be changed) - Backend Library Name : HAL Backend Library Name (fixed, not be changed) - Backend Open Count : HAL Backend Open Count (it's changed according to user count) - Backend Verification : If there is HAL backend, print "YES". : If HAL backend is verified (get/put_backen), print "VERIFIED". - Backend Symbol Name : HAL Backend Symbol Name (fixed, not be changed) - Backend ABI Version : HAL Backend ABI Version (Written by Backend Developer) - Backend Name : HAL Backend Name (Written by Backend Developer) - Vendor Name : HAL Backend Vendor Name (Written by Backend Developer) - TOTAL : The number of HAL modules and backends [Example on rpi4 armv7l environment] root:~> lshal --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | Backend | Backend | Backend | Backend ABI Version | Backend Name | Vendor Name | HAL Module Name | ID | Backend Library Name | Open Count | Verification | Symbol Name | (Written by Developer) | (Written by Developer) | (Written by Developer) | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- HAL_MODULE_TBM | 1 | /hal/lib/libhal-backend-tbm.so | 4 | YES | VERIFIED | hal_backend_tbm_data | HAL_ABI_VERSION_TIZEN_6_5 | vc4 | Samsung | HAL_MODULE_TDM | 2 | /hal/lib/libhal-backend-tdm.so | 2 | YES | VERIFIED | hal_backend_tdm_data | HAL_ABI_VERSION_TIZEN_6_5 | vc4 | Samsung | HAL_MODULE_COREGL | 3 | | | | | | | | | HAL_MODULE_INPUT | 4 | | | | | | | | | HAL_MODULE_AUDIO | 5 | /hal/lib/libhal-backend-audio.so | 1 | YES | VERIFIED | hal_backend_audio_data | HAL_ABI_VERSION_TIZEN_6_5 | audio-rpi | Broadcom | HAL_MODULE_CAMERA | 6 | /hal/lib/libhal-backend-camera.so | 1 | YES | VERIFIED | hal_backend_camera_data | HAL_ABI_VERSION_TIZEN_6_5 | camera-v4l2 | TIZEN | HAL_MODULE_RADIO | 7 | /hal/lib/libhal-backend-radio.so | 0 | NO | | hal_backend_radio_data | | | | HAL_MODULE_CODEC | 8 | | | | | | | | | HAL_MODULE_USB_AUDIO | 9 | | | | | | | | | HAL_MODULE_ALSAUCM | 10 | | | | | | | | | HAL_MODULE_BLUETOOTH | 11 | /hal/lib/libhal-backend-bluetooth.so | 1 | YES | VERIFIED | hal_backend_bluetooth_data | HAL_ABI_VERSION_TIZEN_6_5 | bluetooth | broadcom | HAL_MODULE_WIFI | 12 | /hal/lib/libhal-backend-wifi.so | 0 | NO | | hal_backend_wifi_data | | | | HAL_MODULE_NAN | 13 | | | | | | | | | HAL_MODULE_NFC | 14 | /hal/lib/libhal-backend-nfc.so | 0 | NO | | hal_backend_nfc_data | | | | HAL_MODULE_ZIGBEE | 15 | /hal/lib/libhal-backend-zigbee.so | 0 | NO | | hal_backend_zigbee_data | | | | HAL_MODULE_UWB | 16 | /hal/lib/libhal-backend-uwb.so | 0 | NO | | hal_backend_uwb_data | | | | HAL_MODULE_MTP | 17 | | | | | | | | | HAL_MODULE_TELEPHONY | 18 | | | | | | | | | HAL_MODULE_LOCATION | 19 | /hal/lib/libhal-backend-location.so | 3 | YES | VERIFIED | hal_backend_location_data | HAL_ABI_VERSION_TIZEN_6_5 | location-backend | replay | HAL_MODULE_COMMON | 20 | | | | | | | | | HAL_MODULE_POWER | 21 | /hal/lib/libhal-backend-power.so | 1 | YES | VERIFIED | hal_backend_power_data | HAL_ABI_VERSION_TIZEN_6_5 | power-rpi4 | Rasberry Pi | HAL_MODULE_SENSOR | 22 | /hal/lib/libhal-backend-sensor.so | 0 | NO | | hal_backend_sensor_data | | | | HAL_MODULE_PERIPHERAL | 23 | | | | | | | | | HAL_MODULE_DEVICE_BATTERY | 24 | /hal/lib/libhal-backend-device-battery.so | 0 | NO | | hal_backend_device_battery_data | | | | HAL_MODULE_DEVICE_BEZEL | 25 | /hal/lib/libhal-backend-device-bezel.so | 0 | NO | | hal_backend_device_bezel_data | | | | HAL_MODULE_DEVICE_DISPLAY | 26 | /hal/lib/libhal-backend-device-display.so | 2 | YES | VERIFIED | hal_backend_device_display_data | HAL_ABI_VERSION_TIZEN_7_0 | display | RPI | HAL_MODULE_DEVICE_IR | 27 | /hal/lib/libhal-backend-device-ir.so | 0 | NO | | hal_backend_device_ir_data | | | | HAL_MODULE_DEVICE_TOUCHSCREEN | 28 | /hal/lib/libhal-backend-device-touchscreen.so | 1 | YES | VERIFIED | hal_backend_device_touchscreen_data | HAL_ABI_VERSION_TIZEN_7_0 | touchscreen | RPI | HAL_MODULE_DEVICE_LED | 29 | /hal/lib/libhal-backend-device-led.so | 1 | YES | VERIFIED | hal_backend_device_led_data | HAL_ABI_VERSION_TIZEN_7_0 | led | RPI | HAL_MODULE_DEVICE_BOARD | 30 | /hal/lib/libhal-backend-device-board.so | 1 | YES | VERIFIED | hal_backend_device_board_data | HAL_ABI_VERSION_TIZEN_7_0 | board | RPI | HAL_MODULE_DEVICE_EXTERNAL_CONNECTION | 31 | /hal/lib/libhal-backend-device-external-connection.so | 0 | NO | | hal_backend_device_external_connection_data | | | | HAL_MODULE_DEVICE_THERMAL | 32 | /hal/lib/libhal-backend-device-thermal.so | 1 | YES | VERIFIED | hal_backend_device_thermal_data | HAL_ABI_VERSION_TIZEN_7_0 | thermal | RPI | HAL_MODULE_DEVICE_USB_GADGET | 33 | /hal/lib/libhal-backend-device-usb-gadget.so | 0 | NO | | hal_backend_device_usb_gadget_data | | | | HAL_MODULE_DEVICE_HAPTIC | 34 | /hal/lib/libhal-backend-device-haptic.so | 1 | YES | VERIFIED | hal_backend_device_haptic_data | HAL_ABI_VERSION_TIZEN_7_0 | haptic | RPI | HAL_MODULE_DEVICE_MEMORY | 35 | /hal/lib/libhal-backend-device-memory.so | 1 | YES | VERIFIED | hal_backend_device_memory_data | HAL_ABI_VERSION_TIZEN_7_0 | memory | RPI | HAL_MODULE_DEVICE_INPUT | 36 | /hal/lib/libhal-backend-device-input.so | 0 | NO | | hal_backend_device_input_data | | | | HAL_MODULE_DEVICE_POWER | 37 | /hal/lib/libhal-backend-device-power.so | 0 | NO | | hal_backend_device_power_data | | | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TOTAL | 37 | | | 14 | | | | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Change-Id: Id8246ff25d6cabf785b3fd1c6f24b1a1749daf0f Signed-off-by: Chanwoo Choi --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5979e5a..5fcd8e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,3 +61,5 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/hal-rpmdb-checker.conf DESTINATION /usr/lib/tmpfiles.d) ADD_SUBDIRECTORY(tests) + +ADD_SUBDIRECTORY(tools/lshal) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 0163bc4..058f19c 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -105,6 +105,7 @@ systemd-tmpfiles /usr/lib/tmpfiles.d/hal-rpmdb-checker.conf --create %defattr(-,root,root,-) %dir /hal %{_libdir}/hal/*.so* +%{_bindir}/lshal %{_sysconfdir}/ld.so.conf.d/libhal-api.conf %{_systemdgeneratordir}/systemd-hal-firmware-generator diff --git a/tools/lshal/CMakeLists.txt b/tools/lshal/CMakeLists.txt new file mode 100644 index 0000000..d5efa00 --- /dev/null +++ b/tools/lshal/CMakeLists.txt @@ -0,0 +1,33 @@ +PROJECT(lshal C CXX) + +SET(SRCS + ${CMAKE_SOURCE_DIR}/src/hal-api-common.c + ${CMAKE_SOURCE_DIR}/src/hal-api-conf.c +) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(gtest_pkgs REQUIRED + gio-2.0 + glib-2.0 + dlog +) + +FOREACH(flag ${gtest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +SET(src ${CMAKE_SOURCE_DIR}/tools/lshal/lshal.c) +GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) +MESSAGE("${src_name}") +ADD_EXECUTABLE(${src_name} ${SRCS} ${src}) +TARGET_LINK_LIBRARIES(${src_name} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl) +INSTALL(TARGETS ${src_name} DESTINATION /usr/bin/) diff --git a/tools/lshal/lshal.c b/tools/lshal/lshal.c new file mode 100644 index 0000000..fa4491b --- /dev/null +++ b/tools/lshal/lshal.c @@ -0,0 +1,224 @@ +/* + * lshal Tool + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "hal-common.h" +#include "hal-common-interface.h" + +#include "hal-api-conf.h" + +#define BIT(x) (1ULL << x) +#define BUFF_MAX 256 + +#define LSHAL_FLAG_BACKEND_VERIFICATION BIT(0) +#define LSHAL_FLAG_BACKEND_MODULE_NAME BIT(1) +#define LSHAL_FLAG_BACKEND_LIB_NAME BIT(2) +#define LSHAL_FLAG_BACKEND_SYMBOL_NAME BIT(3) +#define LSHAL_FLAG_BACKEND_NAME BIT(4) +#define LSHAL_FLAG_BACKEND_VENDOR_NAME BIT(5) +#define LSHAL_FLAG_BACKEND_USAGE_COUNT BIT(6) +#define LSHAL_FLAG_BACKEND_ABI_VERSION BIT(7) + +struct _hal_backend_module_data { + /** + * Each HAL module defines the different backend_module_data. + * In order to test the all HAL backends, just use the large buffer. + */ + void *unused_buffer[10000]; +} *backend_module_data; + +static int lshal_verify_hal_backend(enum hal_module module) +{ + int ret; + + ret = hal_common_get_backend(module, (void **)&backend_module_data); + if (ret < 0) + return ret; + + ret = hal_common_put_backend(module, backend_module_data); + if (ret < 0) + return ret; + + return 0; +} + +static void lshal_print_border(void) { + for (int i = 0; i < 267; i++) + printf("-"); + printf("\n"); +} + +static void lshal_print_hal_backend_info(u_int32_t flags) { + int ret; + enum hal_module module; + char str[BUFF_MAX]; + int backend_verification_count = 0; + + lshal_print_border(); + printf(" %-38s | | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n", + "", + "", + "Backend", + "Backend", + "Backend", + "Backend ABI Version", + "Backend Name", + "Vendor Name"); + + printf(" %-38s | ID | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n", + "HAL Module Name", + "Backend Library Name", + "Open Count", + "Verification", + "Symbol Name", + "(Written by Developer)", + "(Written by Developer)", + "(Written by Developer)"); + lshal_print_border(); + + for (module = HAL_MODULE_UNKNOWN + 1; module < HAL_MODULE_END; module++) { + if (LSHAL_FLAG_BACKEND_MODULE_NAME | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_module_name(module, str, BUFF_MAX - 1); + if (ret < 0) + printf(" %-38s | %-2d |", "", module); + else + printf(" %-38s | %-2d |", str, module); + } + + if (LSHAL_FLAG_BACKEND_LIB_NAME | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_library_name(module, str, BUFF_MAX - 1); + if (ret < 0) + printf(" %-55s |", ""); + else + printf(" %-55s |", str); + } + + if (LSHAL_FLAG_BACKEND_USAGE_COUNT | flags) { + int count = hal_common_get_backend_count(module); + if (count < 0) + printf(" %-10s |", ""); + else + printf(" %-10d |", count); + } + + if (LSHAL_FLAG_BACKEND_VERIFICATION | flags) { + ret = lshal_verify_hal_backend(module); + + if (ret == -ENOENT) { + printf(" %-15s |", "NO |"); + } else if (ret < 0) { + printf(" %-15s |", " |"); + } else { + printf(" %-15s |", "YES | VERIFIED"); + backend_verification_count++; + } + } + + if (LSHAL_FLAG_BACKEND_SYMBOL_NAME | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_symbol_name(module, str, BUFF_MAX - 1); + if (ret < 0) + printf(" %-45s |", ""); + else + printf(" %-45s |", str); + } + + if (LSHAL_FLAG_BACKEND_ABI_VERSION | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_abi_version(module); + if (ret == HAL_ABI_VERSION_UNKNOWN) + printf(" %-25s |", ""); + else + printf(" %-25s |", hal_abi_version_str[ret]); + } + + if (LSHAL_FLAG_BACKEND_NAME | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_name(module, str, BUFF_MAX - 1); + if (ret < 0) + printf(" %-25s |", ""); + else + printf(" %-25s |", str); + } + + if (LSHAL_FLAG_BACKEND_VENDOR_NAME | flags) { + strncpy(str, "", BUFF_MAX - 1); + + ret = hal_common_get_backend_vendor(module, str, BUFF_MAX - 1); + if (ret < 0) + printf(" %-25s |", ""); + else + printf(" %-25s |", str); + } + + printf("\n"); + } + + lshal_print_border(); + printf(" %-38s | %-2d | %-55s | %-10s | %15d | %-45s | %-25s | %-25s | %-25s |\n", + "TOTAL", + HAL_MODULE_END - 1, + "", + "", + backend_verification_count, + "", + "", + "", + ""); + lshal_print_border(); +} + +static void lshal_handle_signal(int signal) {} + +static void lshal(void) +{ + u_int32_t flags = (LSHAL_FLAG_BACKEND_VERIFICATION + | LSHAL_FLAG_BACKEND_LIB_NAME + | LSHAL_FLAG_BACKEND_SYMBOL_NAME + | LSHAL_FLAG_BACKEND_NAME + | LSHAL_FLAG_BACKEND_VENDOR_NAME + | LSHAL_FLAG_BACKEND_USAGE_COUNT); + + lshal_print_hal_backend_info(flags); +} + +int main(int argc, char *argv[]) +{ + /* Register signal handler for freeing resources */ + signal(SIGINT, lshal_handle_signal); + + lshal(); + + return 0; +}