From 456f76db005fed6a0beba8b53d0f6cf598697a8b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 22 Mar 2021 16:54:53 +0900 Subject: [PATCH 01/16] halapi: Fix svace warning issue Change-Id: I29f2405f1412a99066ae248c1a98f14cf6b30af9 Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 9914c08..e66446d 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -132,8 +132,8 @@ static int __get_backend(enum hal_module module, void **data, const char *librar struct __hal_module_info *info = NULL; void *handle = NULL; hal_backend *backend; - const char *symbol_name; - const char *backend_library_name; + const char *symbol_name = NULL; + const char *backend_library_name = NULL; int ret = 0; /* Check parameter whether is valid or not */ -- 2.7.4 From 0bd8f286c05544f4646b41b14bb118f9c8634ba3 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 23 Mar 2021 17:25:16 +0900 Subject: [PATCH 02/16] haltest: Add haltest.target to support HAL TEST mode In order to support HAL TEST Mode, add haltest.target which requires the least running processes for only haltest such as sdbd service. So that haltest.target is based on getty.target to support the console and then add deviced.service/ac.service for supporting sdbd service. And reboot-haltest/reboot-normal scripts are for switching between normal mode and HALTEST mode. [Essential service list in haltest.target] - dbus.service for /usr/bin/dbus-daemon - serial-getty@.service for console - dlog_logger.service for /usr/bin/dlog_logger - systemd-udevd.service for /usr/lib/sytemd/sytemd-udevd - systemd-journald.service for /usr/bin/systemd/systemd-journald - ac.service for /usr/bin/amd is requied for deviced.service - deviced.service for /usr/bin/deviced is required for sdbd.service - sdbd.service for /usr/sbin/sdbd [Script commands to switch between Normal and HALTEST mode] - reboot-haltest switches from Normal to HALTEST mode. - reboot-normal switches from HALTEST to Normal mode. Change-Id: If8fdd240003cf3509cec5f83bf8aacb3bc1a5ec6 Signed-off-by: Chanwoo Choi --- packaging/hal-api-common.spec | 9 +++++++++ packaging/haltest.target | 6 ++++++ packaging/reboot-haltest | 41 +++++++++++++++++++++++++++++++++++++++++ packaging/reboot-normal | 26 ++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 packaging/haltest.target create mode 100644 packaging/reboot-haltest create mode 100644 packaging/reboot-normal diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 223887f..1844696 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -14,6 +14,9 @@ Source1: %{name}.manifest Source2: libhal-api.conf Source3: systemd-hal-firmware-generator Source4: macros.hal-api +Source5: haltest.target +Source6: reboot-haltest +Source7: reboot-normal Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -67,6 +70,9 @@ mkdir -p %{buildroot}/hal install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf install -D -m 0755 %{SOURCE3} %{buildroot}%{_systemdgeneratordir}/systemd-hal-firmware-generator install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/rpm/macros.hal-api +install -D -m 0644 %{SOURCE5} %{buildroot}%{_unitdir}/haltest.target +install -D -m 0755 %{SOURCE6} %{buildroot}%{_bindir}/reboot-haltest +install -D -m 0755 %{SOURCE7} %{buildroot}%{_bindir}/reboot-normal %clean rm -rf %{buildroot} @@ -101,3 +107,6 @@ fi %files -n %{test_name} %{_bindir}/hal/common-haltests +%{_unitdir}/haltest.target +%{_bindir}/reboot-haltest +%{_bindir}/reboot-normal diff --git a/packaging/haltest.target b/packaging/haltest.target new file mode 100644 index 0000000..0b35a53 --- /dev/null +++ b/packaging/haltest.target @@ -0,0 +1,6 @@ +[Unit] +Description=HALTEST Mode +Requires=basic.target ac.service deviced.service getty.target +Conflicts=rescue.service rescue.target +After=basic.target rescue.service rescue.target ac.service deviced.service getty.target +AllowIsolate=yes diff --git a/packaging/reboot-haltest b/packaging/reboot-haltest new file mode 100644 index 0000000..622939c --- /dev/null +++ b/packaging/reboot-haltest @@ -0,0 +1,41 @@ +#!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +user=`whoami` +default=`systemctl get-default` +dmverity_path="/usr/bin/verityctl" +dmverity_cmd=`verityctl get-mode root` +dmverity_log="dm-verity is disabled (Normal boot)" + +if ! [ "$user" = "root" ] +then + echo "HALTEST: Need 'root' permission for switching mode" + exit +fi + +if [ -f $dmverity_path ] +then + if ! [ "$dmverity_cmd" = "$dmverity_log" ] + then + echo "HALTEST: Need to disable DM-VERITY to use HALTEST Mode " + echo "HALTEST: Disable DM-VERITY and reboot target " + echo "HALTEST: After rebooting, need to execure reboot-haltest again " + verityctl disable + echo "HALTEST: Rebooting ..." + reboot -f + fi +fi + +if ! [ "$default" = "haltest.target" ] +then + echo "HALTEST: Switch to HALTEST Mode from Normal Mode" + echo "HALTEST: Change default.target from $default to haltest.target" + mount -o remount,rw / + systemctl set-default haltest.target + sync + echo "HALTEST: Rebooting ..." + reboot -f +else + echo "HALTEST: HALTEST Mode is already enabled (default: $default)" +fi + diff --git a/packaging/reboot-normal b/packaging/reboot-normal new file mode 100644 index 0000000..09fafa9 --- /dev/null +++ b/packaging/reboot-normal @@ -0,0 +1,26 @@ +#!/bin/bash + +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +user=`whoami` +default=`systemctl get-default` + +if ! [ "$user" = "root" ] +then + echo "HALTEST: Need 'root' permission for switching mode" + exit +fi + +if ! [ "$default" = "graphical.target" ] +then + echo "HALTEST: Switch to Normal Mode from HALTEST Mode" + echo "HALTEST: Change default.target from $default to graphical.target" + mount -o remount,rw / + systemctl set-default graphical.target + sync + echo "HALTEST: Rebooting ..." + reboot -f +else + echo "HALTEST: Normal Mode is already enabled (default: $default)" +fi + -- 2.7.4 From bb5b8f7b9af9d50888eb80e03fdf8587af855a81 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 14:19:35 +0900 Subject: [PATCH 03/16] halapi: Replace fPIE gcc option with fPIC The fPIE option is for the executable binary. It is not proper for shared library files. So that correct the wrong use-case by using fPIC. Change-Id: Id27d4a31080477415d9bc2bbaa0210039ff27233 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df8d137..062835b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -- 2.7.4 From a82677839e8a5b6ada81eea39c9a3710d1af283c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 21 Apr 2021 20:48:59 +0900 Subject: [PATCH 04/16] halapi: Get backend library name always regardless of usage_count The backend_library_name value is necessary to show the backend library name always. So that get backend library name always regardless of usage_count and then print 'close' message when close the fd of backend library. Change-Id: I338bf22ac678bc80ceab020c7fd0c1ca1662254b Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index e66446d..769da13 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -160,19 +160,19 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err; } + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { + _E("%s: Failed to get backend library name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + if (info->usage_count == 0) { /* * Load HAL backend library at first loading time * when usage_count is 0. */ - backend_library_name = get_backend_library_name(info); - if (!backend_library_name) { - _E("%s: Failed to get backend library name\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - ret = access(backend_library_name, F_OK); if (ret < 0) { _E("%s: Failed to find backend library (%s)\n", @@ -205,6 +205,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err_dlclose; } + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + backend_library_name, info->usage_count); + info->library_backend = backend; info->library_handle = handle; } else { @@ -288,12 +292,6 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - info->usage_count--; - if (info->usage_count > 0) { - ret = TIZEN_ERROR_NONE; - goto out; - } - if (backend->exit) { ret = backend->exit(data); if (ret < 0) { @@ -304,10 +302,21 @@ static int __put_backend(enum hal_module module, void *data, const char *library } } + info->usage_count--; + _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", info->module_name, backend->name, backend->vendor, get_backend_library_name(info), info->usage_count); + if (info->usage_count > 0) { + ret = TIZEN_ERROR_NONE; + goto out; + } + + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + get_backend_library_name(info), info->usage_count); + if (handle) dlclose(handle); -- 2.7.4 From 337405b7eddade611c70a9d4afcb4b255e42159f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 21 Apr 2021 21:02:43 +0900 Subject: [PATCH 05/16] halapi: Encapsulate unused variables by external user The following variables are only used in hal-api-common without exposing for external user. So that move them into internal header files for encapsulation. - enum hal_license - enum hal_group - char *const hal_group_string[] - char *const hal_module_string[] Change-Id: I18643fdbbabcabee7b6aefadff1ba36c8dc3a0fa Signed-off-by: Chanwoo Choi --- include/hal-common.h | 29 ----------------------------- src/common.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 45c4a10..67dc4b1 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -25,35 +25,6 @@ extern "C" { #endif -enum hal_license { - HAL_LICENSE_UNKNOWN = 0, - HAL_LICENSE_APACHE_2_0, - HAL_LICENSE_FLORA, - HAL_LICENSE_MIT, - HAL_LICENSE_END, -}; - -enum hal_group { - HAL_GROUP_UNKNOWN = 0, - HAL_GROUP_GRAPHICS, - HAL_GROUP_MULTIMEDIA, - HAL_GROUP_CONNECTIVITY, - HAL_GROUP_TELEPHONY, - HAL_GROUP_LOCATION, - HAL_GROUP_SYSTEM, - HAL_GROUP_END, -}; - -static const char *const hal_group_string[] = { - [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN", - [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS", - [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA", - [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY", - [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY", - [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION", - [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM", -}; - enum hal_module { HAL_MODULE_UNKNOWN = 0, diff --git a/src/common.h b/src/common.h index e3463e2..c641610 100644 --- a/src/common.h +++ b/src/common.h @@ -33,6 +33,35 @@ extern "C" { #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +enum hal_license { + HAL_LICENSE_UNKNOWN = 0, + HAL_LICENSE_APACHE_2_0, + HAL_LICENSE_FLORA, + HAL_LICENSE_MIT, + HAL_LICENSE_END, +}; + +enum hal_group { + HAL_GROUP_UNKNOWN = 0, + HAL_GROUP_GRAPHICS, + HAL_GROUP_MULTIMEDIA, + HAL_GROUP_CONNECTIVITY, + HAL_GROUP_TELEPHONY, + HAL_GROUP_LOCATION, + HAL_GROUP_SYSTEM, + HAL_GROUP_END, +}; + +static const char *const hal_group_string[] = { + [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN", + [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS", + [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA", + [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY", + [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY", + [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION", + [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM", +}; + /** * hal-api-common (/platform/hal/api/common) provides the HAL ABI * (Application Binary Interface) version check feature which is used to check -- 2.7.4 From 0bde68b13a4809ae6772ce46677bfd1867b5f174 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 18:33:36 +0900 Subject: [PATCH 06/16] halapi: conf: Remove unused local variables Change-Id: Iab9597b3bd4d2bbfc258d62ca1302f8ba64169a4 Signed-off-by: Chanwoo Choi --- src/hal-api-conf.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 4465fe6..65e67f4 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -283,13 +283,6 @@ __attribute__ ((visibility("default"))) struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, const char *library_name) { - struct __hal_module_info *info = NULL; - json_object *module_array_object = NULL; - const char *group_name = NULL; - const char *module_name = NULL; - const char *key = NULL; - int i; - #ifdef HAL_API_CONF_JSON if (!_json_file_object) return NULL; -- 2.7.4 From 9c3b2bc76bb5cbfd35322fa2a1c37735ad6b585c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 23 Apr 2021 16:02:45 +0900 Subject: [PATCH 07/16] halapi: Show process name when using hal-api library The hal-api library are used by the various process. In order to support the easy debugging, show the process name who get/put the hal-api library. Example log with process name, HAL_MODULE_TBM: Get HAL backend: name(vc4)/vendor(Samsung)/library(/hal/lib64/libhal-backend-tbm.so)/count(1) by /usr/bin/enlightenment HAL_MODULE_TBM: Get HAL backend: name(vc4)/vendor(Samsung)/library(/hal/lib64/libhal-backend-tbm.so)/count(1) by /usr/bin/boot-animation Change-Id: I7befe874d17585cfffc79e05e32f90f1edcb284d Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 769da13..530d18c 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -22,11 +22,16 @@ #include #include +#define _GNU_SOURCE +#include + #include #include "common.h" #include "hal-api-conf.h" +extern char *program_invocation_name; + #ifndef EXPORT #define EXPORT __attribute__ ((visibility("default"))) #endif @@ -205,9 +210,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err_dlclose; } - _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); info->library_backend = backend; info->library_handle = handle; @@ -246,9 +252,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar info->usage_count++; - _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count); + backend_library_name, info->usage_count, + program_invocation_name); G_UNLOCK(hal_common_lock); return TIZEN_ERROR_NONE; @@ -304,18 +311,20 @@ static int __put_backend(enum hal_module module, void *data, const char *library info->usage_count--; - _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); if (info->usage_count > 0) { ret = TIZEN_ERROR_NONE; goto out; } - _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); if (handle) dlclose(handle); -- 2.7.4 From cffb4836e9887964dc595b6e63a271e0ce216c0d Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 19:12:04 +0900 Subject: [PATCH 08/16] halapi: Split the internal functions finely to get flexibility New functions will use only __open_backend() without __close_backend() in order to get the data of hal_backend structure. But this code have been tightly coupled implemented in __get_backend and __put_backend. In order to make the code more flexibility, split __get_backend/__put_backend finley to two steps such as open/close and init/exit. [Simple description for functions] - __open_backend() : Open backend library and get backend symbol - __close_backend() : Close backend library - __init_backend() : After getting backend, initialize HAL backend driver - __exit_backend() : After getting backend, exit HAL backend driver - __get_backend() __open_backend() __init_backend() Increase usage_count - __put_backend() __exit_backen() __close_backend() Decrease usage_count [Change variable name in struct __hal_module_info] - library_backend -> backend - library_handle -> handle Change-Id: I358e3f4db1991d26c8cf0498b3f37ec543da3e38 Signed-off-by: Chanwoo Choi --- src/common.h | 4 +- src/hal-api-common.c | 279 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 169 insertions(+), 114 deletions(-) diff --git a/src/common.h b/src/common.h index c641610..69d7c13 100644 --- a/src/common.h +++ b/src/common.h @@ -93,8 +93,8 @@ struct __hal_module_info { char *library_name; char *library_name_64bit; - void *library_handle; - hal_backend *library_backend; + void *handle; + hal_backend *backend; char *symbol_name; unsigned int num_abi_versions; diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 530d18c..18eab76 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -132,23 +132,157 @@ out: return ret; } -static int __get_backend(enum hal_module module, void **data, const char *library_name) +static int __open_backend(struct __hal_module_info *info) { - struct __hal_module_info *info = NULL; - void *handle = NULL; - hal_backend *backend; - const char *symbol_name = NULL; const char *backend_library_name = NULL; - int ret = 0; + int ret; + + if (info->backend && info->handle) + return 0; + + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { + _E("%s: Failed to get backend library name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + if (!info->symbol_name) { + _E("%s: Failed to get backend symbol name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + ret = access(backend_library_name, F_OK); + if (ret < 0) { + _E("%s: Failed to find backend library (%s)\n", + info->module_name, backend_library_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + info->handle = dlopen(backend_library_name, RTLD_LAZY); + if (!info->handle) { + _E("%s: Failed to load backend library (%s)\n", + info->module_name, dlerror()); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + info->backend = dlsym(info->handle, info->symbol_name); + if (!info->backend) { + _E("%s: Failed to find backend data (%s)\n", + info->module_name, dlerror()); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_dlclose; + } + + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + backend_library_name, info->usage_count, + program_invocation_name); + + return 0; + +err_dlclose: + dlclose(info->handle); +err: + info->backend = NULL; + info->handle = NULL; + + return ret; +} + +static void __close_backend(struct __hal_module_info *info) +{ + if (!info->backend || !info->handle) + return; + + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, + program_invocation_name); + + if (info->handle) + dlclose(info->handle); + + info->backend = NULL; + info->handle = NULL; +} + +static int __init_backend(struct __hal_module_info *info, void **data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return TIZEN_ERROR_NONE; + } + + if (!info->backend->init) { + _E("%s: hal_backend->init() is NULL\n", info->module_name); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + /* Check HAL ABI Version */ + ret = hal_common_check_backend_abi_version(info->module, + info->backend->abi_version); + if (ret < 0) { + _E("%s: Failed to check ABI version\n", info->module_name); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + /* Initialize backend */ + ret = info->backend->init(data); + if (ret < 0) { + _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + return TIZEN_ERROR_NONE; +} + +static int __exit_backend(struct __hal_module_info *info, void *data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return TIZEN_ERROR_NONE; + } + + /* Exit backend */ + if (info->backend->exit) { + ret = info->backend->exit(data); + if (ret < 0) { + _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return TIZEN_ERROR_INVALID_PARAMETER; + } + } + + return 0; +} + +static int __get_backend(enum hal_module module, void **data, + const char *library_name) +{ + struct __hal_module_info *info = NULL; + int ret; - /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { _E("Invalid parameter of HAL module (%d)\n", module); return TIZEN_ERROR_INVALID_PARAMETER; } G_LOCK(hal_common_lock); - if (_hal_api_conf_init()) { ret = TIZEN_ERROR_UNKNOWN; goto err; @@ -165,96 +299,27 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err; } - backend_library_name = get_backend_library_name(info); - if (!backend_library_name) { - _E("%s: Failed to get backend library name\n", + ret = __open_backend(info); + if (ret < 0) { + _E("%s: Failed to get the backend library by dlopen\n", info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } - if (info->usage_count == 0) { - /* - * Load HAL backend library at first loading time - * when usage_count is 0. - */ - ret = access(backend_library_name, F_OK); - if (ret < 0) { - _E("%s: Failed to find backend library (%s)\n", - info->module_name, backend_library_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - - handle = dlopen(backend_library_name, RTLD_LAZY); - if (!handle) { - _E("%s: Failed to load backend library (%s)\n", - info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - - symbol_name = info->symbol_name; - if (!symbol_name) { - _E("%s: Failed to get backend symbol name\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - backend = dlsym(handle, symbol_name); - if (!backend) { - _E("%s: Failed to find backend data (%s)\n", - info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count, - program_invocation_name); - - info->library_backend = backend; - info->library_handle = handle; - } else { - /* - * Re-use the already loaded HAL backend instance - * when usage_count is larger than 0. - */ - backend = info->library_backend; - } - - /* Check HAL ABI Version */ - ret = hal_common_check_backend_abi_version(module, backend->abi_version); + ret = __init_backend(info, data, NULL); if (ret < 0) { - _E("%s: Failed to check ABI version\n", + _E("%s: Failed to initialize the backend library\n", info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err_dlclose; } - /* Get the backend module data */ - if (!backend->init) { - _E("%s: hal_backend->init() is NULL\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - ret = backend->init(data); - if (ret < 0) { - _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - info->usage_count++; _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count, + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, program_invocation_name); G_UNLOCK(hal_common_lock); @@ -262,17 +327,16 @@ static int __get_backend(enum hal_module module, void **data, const char *librar err_dlclose: _hal_api_conf_exit(); - dlclose(handle); + __close_backend(info); err: G_UNLOCK(hal_common_lock); return ret; } -static int __put_backend(enum hal_module module, void *data, const char *library_name) +static int __put_backend(enum hal_module module, void *data, + const char *library_name) { struct __hal_module_info *info = NULL; - hal_backend *backend = NULL; - void *handle = NULL; int ret; /* Check parameter whether is valid or not */ @@ -290,29 +354,30 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - backend = info->library_backend; - handle = info->library_handle; + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + ret = TIZEN_ERROR_NONE; + goto out; + } - if (!backend || info->usage_count == 0) { + if (!info->usage_count) { _I("%s: Already fully put for HAL module\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = TIZEN_ERROR_NONE; goto out; } - if (backend->exit) { - ret = backend->exit(data); - if (ret < 0) { - _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto out; - } + ret = __exit_backend(info, data, NULL); + if (ret < 0) { + _E("%s: Failed to exit the backend library\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto out; } info->usage_count--; _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, + info->module_name, info->backend->name, info->backend->vendor, get_backend_library_name(info), info->usage_count, program_invocation_name); @@ -321,17 +386,7 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count, - program_invocation_name); - - if (handle) - dlclose(handle); - - info->library_backend = NULL; - info->library_handle = NULL; - + __close_backend(info); _hal_api_conf_exit(); ret = TIZEN_ERROR_NONE; -- 2.7.4 From bc5a305b030bd67f8bbd1fbd49bc9eeb1c67985b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 26 Apr 2021 19:06:56 +0900 Subject: [PATCH 09/16] halapi: Add new functions to get information of hal_backend structure The hal-api-common defines the common hal_backend structure for all hal backend driver. Add new functions to provide the information of hal_backend structure because of user request. Add the detailed function roles as following: [Newly added functions] - hal_common_get_backend_abi_version(enum hal_module module); : Get the backend HAL ABI version according to the type of HAL module - hal_common_get_backend_name(enum hal_module module, char *name, int size); : Get the backend name according to the type of HAL module - hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); : Get the backend vendor description according to the type of HAL module Change-Id: I2060e9047b60c029e161dc18f3981185a0f724a1 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 25 +++++++++++++ src/hal-api-common.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/include/hal-common.h b/include/hal-common.h index 67dc4b1..7ec6c1f 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -203,6 +203,31 @@ int hal_common_put_backend_with_library_name(enum hal_module module, int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version); +/** + * @brief Get the backend HAL ABI version according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @return @c positive integer value on success, otherwise a zero error value + */ +unsigned int hal_common_get_backend_abi_version(enum hal_module module); + +/** + * @brief Get the backend name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend name of HAL module + * @param[in] Arrary size of name[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_name(enum hal_module module, char *name, int size); + +/** + * @brief Get the backend vendor description according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend vendor description of HAL module + * @param[in] Arrary size of vendor[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 18eab76..7a98878 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -396,6 +396,82 @@ out: return ret; } +static int __get_backend_data(enum hal_module module, unsigned int *abi_version, + char *name, int name_size, char *vendor, int vendor_size) +{ + struct __hal_module_info *info = NULL; + int ret, len; + + if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { + _E("Invalid parameter of HAL module (%d)\n", module); + return 0; + } + + G_LOCK(hal_common_lock); + + if (_hal_api_conf_init()) { + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_unlock; + } + + info = _hal_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_conf_exit; + } + + ret = __open_backend(info); + if (ret < 0) { + _E("%s: Failed to get the backend library by dlopen\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + /* Return abi_verion of hal_backend structure */ + if (!name_size && !vendor_size) { + *abi_version = info->backend->abi_version; + + /* Return name of hal_backend structure */ + } else if (info->backend->name && name_size && !vendor_size) { + len = strlen(info->backend->name); + + if (!info->backend->name || (len + 1 > name_size)) { + _E("%s: Invalid size of name[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(name, info->backend->name, len); + name[len] = '\0'; + + /* Return vendor of hal_backend structure */ + } else if (info->backend->vendor && !name_size && vendor_size) { + len = strlen(info->backend->vendor); + + if (!info->backend->vendor || (len + 1 > vendor_size)) { + _E("%s: Invalid size of vendor[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(vendor, info->backend->vendor, len); + vendor[len] = '\0'; + } else { + _E("%s: Failed to get backend data\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + ret = TIZEN_ERROR_NONE; + +err_conf_exit: + _hal_api_conf_exit(); +err_unlock: + G_UNLOCK(hal_common_lock); + return ret; +} + EXPORT int hal_common_get_backend(enum hal_module module, void **data) { @@ -505,3 +581,28 @@ out: _hal_api_conf_exit(); return ret; } + +EXPORT +unsigned int hal_common_get_backend_abi_version(enum hal_module module) +{ + unsigned int abi_version; + int ret; + + ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); + if (ret < 0) + return HAL_ABI_VERSION_UNKNOWN; + + return abi_version; +} + +EXPORT +int hal_common_get_backend_name(enum hal_module module, char *name, int size) +{ + return __get_backend_data(module, NULL, name, size, NULL, 0); +} + +EXPORT +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size) +{ + return __get_backend_data(module, NULL, NULL, 0, vendor, size); +} -- 2.7.4 From 4ced43fa876d0c0c6f3d72cba55bffeb9e7bc131 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 2 Jun 2021 17:01:13 +0900 Subject: [PATCH 10/16] haltest: Change dmverity command according to the change of dmverity guide Change-Id: Ibcd023abdddea80bee7323ac841da1fc9809c570 Reported-by: INSUN PYO Signed-off-by: Chanwoo Choi --- packaging/reboot-haltest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/reboot-haltest b/packaging/reboot-haltest index 622939c..892e331 100644 --- a/packaging/reboot-haltest +++ b/packaging/reboot-haltest @@ -4,7 +4,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin user=`whoami` default=`systemctl get-default` dmverity_path="/usr/bin/verityctl" -dmverity_cmd=`verityctl get-mode root` +dmverity_cmd=`verityctl get-mode rootfs` dmverity_log="dm-verity is disabled (Normal boot)" if ! [ "$user" = "root" ] -- 2.7.4 From dbeef1465f25513301690eb3b2ee9c326ded62d7 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 17 Jun 2021 11:13:13 +0900 Subject: [PATCH 11/16] halapi: Fix svace issue when accessing hal-backend file Fix savce TOCTOU[1] issue [1] https://wiki.sei.cmu.edu/confluence/display/c/FIO45-C.+Avoid+TOCTOU+race+conditions+while+accessing+files Change-Id: I20e8724afd5d27eb466223315fab11ebc9faf77c Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 7a98878..8f17557 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -155,14 +155,6 @@ static int __open_backend(struct __hal_module_info *info) goto err; } - ret = access(backend_library_name, F_OK); - if (ret < 0) { - _E("%s: Failed to find backend library (%s)\n", - info->module_name, backend_library_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - info->handle = dlopen(backend_library_name, RTLD_LAZY); if (!info->handle) { _E("%s: Failed to load backend library (%s)\n", -- 2.7.4 From b4593a4cf5265f2cdd34171f7196d9032f6a046f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 29 Apr 2021 12:14:16 +0900 Subject: [PATCH 12/16] halimg: Add hal-rpmdb-checker.service to check rpm version compatibility For removing the h/w dependency from Tizen core image, decide to create Tizen core image (core.img) and hal.img separately. It means that each image is able to be built on different build time. So that in order to guarnatee the compatibility between images, must need to check the version compatiblity of rpm packages of hal backend packages in hal.img. hal-rpmdb-checker.service will check the the version compatiblity between core.img and hal.img on booting time. If there are no problem between images, hal-rpmdb-checker script will create /opt/etc/hal/.hal-img-version.ini with hal.img build information. Also, after writing the core.img, hal-rpmdb-checker script will create /opt/etc/hal/.first-booting file to distinguish whether booting is first or not. Exmaple of /opt/etc/hal/.hal-img-version.ini $cat /opt/etc/hal/.hal-img-version.ini tizen-6.5-unified-gbm_20210525.030006; Change-Id: I06c740d48478eae6671cec555e627e58e06ea119 Signed-off-by: Chanwoo Choi --- packaging/hal-api-common.spec | 15 +++ packaging/hal-rpmdb-checker | 186 ++++++++++++++++++++++++++++++++++++ packaging/hal-rpmdb-checker.service | 18 ++++ 3 files changed, 219 insertions(+) create mode 100755 packaging/hal-rpmdb-checker create mode 100644 packaging/hal-rpmdb-checker.service diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 1844696..206d858 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -17,6 +17,8 @@ Source4: macros.hal-api Source5: haltest.target Source6: reboot-haltest Source7: reboot-normal +Source8: hal-rpmdb-checker.service +Source9: hal-rpmdb-checker Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -53,6 +55,8 @@ Haltests for hal-api-common %prep %setup -q +%define hal_rpmdb_checker_path /opt/etc/hal + cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} %build @@ -67,18 +71,24 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}/hal +mkdir -p %{buildroot}%{hal_rpmdb_checker_path} install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf install -D -m 0755 %{SOURCE3} %{buildroot}%{_systemdgeneratordir}/systemd-hal-firmware-generator install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/rpm/macros.hal-api install -D -m 0644 %{SOURCE5} %{buildroot}%{_unitdir}/haltest.target install -D -m 0755 %{SOURCE6} %{buildroot}%{_bindir}/reboot-haltest install -D -m 0755 %{SOURCE7} %{buildroot}%{_bindir}/reboot-normal +install -D -m 0644 %{SOURCE8} %{buildroot}%{_unitdir}/hal-rpmdb-checker.service +install -D -m 0755 %{SOURCE9} %{buildroot}%{_bindir}/hal-rpmdb-checker + +%install_service sysinit.target.wants hal-rpmdb-checker.service %clean rm -rf %{buildroot} %post /sbin/ldconfig +chsmack -a "System" -t %{hal_rpmdb_checker_path} if [ ! -d %{TZ_SYS_RO_ETC} ] then @@ -106,7 +116,12 @@ fi %{_sysconfdir}/rpm/macros.hal-api %files -n %{test_name} +%dir %{hal_rpmdb_checker_path} +%attr(0755,system_fw,system_fw) %{hal_rpmdb_checker_path} %{_bindir}/hal/common-haltests %{_unitdir}/haltest.target %{_bindir}/reboot-haltest %{_bindir}/reboot-normal +%{_unitdir}/sysinit.target.wants/hal-rpmdb-checker.service +%{_unitdir}/hal-rpmdb-checker.service +%{_bindir}/hal-rpmdb-checker diff --git a/packaging/hal-rpmdb-checker b/packaging/hal-rpmdb-checker new file mode 100755 index 0000000..ed11f83 --- /dev/null +++ b/packaging/hal-rpmdb-checker @@ -0,0 +1,186 @@ +#!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +### Define constant variables +UNKNOWN="UNKNOWN" +ROOT_OWNER="root" + +HAL_RPMDB_DIR_PATH='/hal/lib/rpm' +HAL_RPMDB_ETC_DIR_PATH='/hal/etc/rpm' +HAL_RPMDB_FILE_PATH='/hal/etc/hal-rpmdb.ini' +HAL_IMG_INFO_FILE_PATH='/hal/etc/hal-info.ini' + +FIRST_BOOTING_FILE_PATH="/opt/etc/hal/.first-booting" +HAL_IMG_VERSION_FILE_PATH="/opt/etc/hal/.hal-img-version.ini" + +### Define variables +first_booting=0 +hal_img=0 +hal_rpmdb_match=1 +hal_img_version=$UNKNOWN +cur_hal_img_version=$UNKNOWN +owner=$UNKNOWN + +### Define functions + +backup_core_rpmdb() { + if [ "$hal_img" -eq 0 ]; then + return + elif [ "$owner" != "$ROOT_OWNER" ]; then + return + elif [ "$first_booting" -eq 0 ]; then + return + fi + + if ! [ -e /opt/etc/hal/Packages.origin ] ; then + cp /var/lib/rpm/Packages /opt/etc/hal/Packages.origin + echo "HAL_RPMDB: Backup Core RPMDB" + fi +} + +import_hal_rpmdb_to_core_rpmdb() { + if [ "$hal_img" -eq 0 ]; then + return + elif [ "$hal_rpmdb_match" -eq 0 ]; then + return + elif [ "$owner" != "$ROOT_OWNER" ]; then + return + fi + + # Restore core-rpmdb from core-rpmdb backup + if [ -e /opt/etc/hal/Packages.origin ] ; then + rm -rf /var/lib/rpm/Packages + cp /opt/etc/hal/Packages.origin /var/lib/rpm/Packages + echo "HAL_RPMDB: Restore Core RPMDB" + fi + + # Import hal-rpmdb into core-rpmdb + if [ -e "$HAL_RPMDB_FILE_PATH" ] ; then + /usr/bin/rpmdb --importdb < $HAL_RPMDB_FILE_PATH + echo "HAL_RPMDB: Import hal-rpdmb into core-rpmdb" + else + echo "HAL_RPMDB: Failed to find $HAL_RPMDB_FILE_PATH" + fi +} + +init() { + first_booting=0 + hal_img=0 + owner=`whoami` + local_hal_part=`/usr/bin/lsblk | grep hal` + + if [ "$local_hal_part" == "" ]; then + echo "HAL_RPMDB: It doesnt' contain both /hal partition and hal.img" + exit 0 + elif ! [ -e "$HAL_RPMDB_DIR_PATH" ] ; then + echo "HAL_RPMDB: Failed to find $HAL_RPMDB_DIR_PATH path" + exit 0 + elif ! [ -e "$HAL_RPMDB_ETC_DIR_PATH" ] ; then + echo "HAL_RPMDB: Failed to find $HAL_RPMDB_ETC_DIR_PATH path" + exit 0 + elif ! [ -e "$HAL_IMG_INFO_FILE_PATH" ] ; then + echo "HAL_RPMDB: Failed to find $HAL_IMG_INFO_FILE_PATH" + exit 0 + else + if ! [ -e /opt/etc/hal/.first-booting ] ; then + /usr/bin/echo "0" > $FIRST_BOOTING_FILE_PATH + first_booting=1 + fi + + hal_img=1 + + backup_core_rpmdb + fi +} + +get_hal_img_version() { + if [ "$hal_img" -eq 0 ]; then + return + fi + + # Get hal_img_version from /hal/etc/info.ini + tmp=`cat $HAL_IMG_INFO_FILE_PATH | grep Build=` + hal_img_version=`echo ${tmp:6}` + + # Get current hal_img_version from $HAL_IMG_VERSION_FILE_PATH + + if ! [ -e "$HAL_IMG_VERSION_FILE_PATH" ] ; then + cur_hal_img_version="$HAL_IMG_VERSION_UNKNOWN" + else + cur_hal_img_version=`cat $HAL_IMG_VERSION_FILE_PATH` + fi + + echo "HAL_RPMDB: hal.img version ($hal_img_version) of /hal/etc/hal-info.ini" + echo "HAL_RPMDB: hal.img version ($cur_hal_img_version) of $HAL_IMG_VERSION_FILE_PATH" +} + +check_hal_rpmdb() { + if [ "$hal_img" -eq 0 ]; then + return + fi + + echo "HAL_RPMDB: Start hal-rpmdb dependency check ... " + + hal_rpmdb_match=1 + HAL_BACKEND_PKGS=`/usr/bin/ls $HAL_RPMDB_ETC_DIR_PATH` + for hal_backend_pkg in ${HAL_BACKEND_PKGS}; do + while read line; do + IS_INSTALLED_IN_RPM=`/usr/bin/rpm -q $line` + + if [[ $IS_INSTALLED_IN_RPM != $line ]]; then + IS_INSTALLED_IN_HAL_RPM=`/usr/bin/rpm --dbpath=$HAL_RPMDB_DIR_PATH -q $line` + + if [[ $IS_INSTALLED_IN_HAL_RPM != $line ]]; then + echo "HAL_RPMDB: WARNING!!! $line is not installed for $hal_backend_pkg" + hal_rpmdb_match=0 + fi + fi + done < $HAL_RPMDB_ETC_DIR_PATH/$hal_backend_pkg + done + + if [ "$hal_rpmdb_match" -eq 1 ]; then + # Update hal.img version when version matched + /usr/bin/echo "$hal_img_version" > $HAL_IMG_VERSION_FILE_PATH + + echo "HAL_RPMDB: Finish hal-rpmdb dependency check (Version Matched) " + else + # Remove hal.img version file when version mismatched + if [ -e "$HAL_IMG_VERSION_FILE_PATH" ] ; then + rm -rf $HAL_IMG_VERSION_FILE_PATH + fi + + echo "HAL_RPMDB: Finish hal-rpmdb dependency check (Version Mismatched) " + exit 0 + fi +} + +main() { + # Check whether h/w device is using hal.img or not + init + # Get hal.img version info + get_hal_img_version + + if [ "$cur_hal_img_version" == "$hal_img_version" ] ; then + # Have finished the version check of hal rpmdb + # and imported hal rpmdb into core rpmdb. + echo "HAL_RPMDB: Already Version Matched!" + return + elif [ "$cur_hal_img_version" == "$HAL_IMG_VERSION_UNKNOWN" ] ; then + # In case of among, + # - first booting or + # - core.img is only updated or + # - hal.img was only updated but, version mismatched + check_hal_rpmdb + else + # In case of hal.img is only updated, must need to restore + # the core rpmdb and then execute check_hal_rpmdb + echo "HAL_RPMDB: hal.img is only updated!" + check_hal_rpmdb + + # Import hal-rpmdb (/hal/lib/rpm) into core-rpmdb (/var/lib/rpm) + import_hal_rpmdb_to_core_rpmdb + fi +} + +### Execute main function +main diff --git a/packaging/hal-rpmdb-checker.service b/packaging/hal-rpmdb-checker.service new file mode 100644 index 0000000..4780d46 --- /dev/null +++ b/packaging/hal-rpmdb-checker.service @@ -0,0 +1,18 @@ +[Unit] +Description=HAL RPMDB Checker +RefuseManualStart=yes +RefuseManualStop=yes +DefaultDependencies=no +After=local-fs.target systemd-tmpfiles-setup.service +Before=shutdown.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/hal-rpmdb-checker +SmackProcessLabel=System +User=system_fw +Group=system_fw + +[Install] +WantedBy=sysinit.target -- 2.7.4 From 8517bf45865e2147c1ed57b0991a77a5c5f9fcfb Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 21 Jun 2021 18:18:46 +0900 Subject: [PATCH 13/16] hal-rpmdb-checker: Remove systemd-tmpfiles-setup.service dependency When checking hal rpmdb dependency, systemd-tmpfiles.setup.service is not necessary. Also, if add the dependency of systemd-tmpfiles.setup.service to hal-rpmdb-checker.service, affect the booting time. So that remove systemd-tmpfiles-setup.service dependency from systemd-tmpfiles-setup.service Change-Id: I25bc49c42b6edc81cf072ec133f8123f54b0adf9 Signed-off-by: Chanwoo Choi --- packaging/hal-rpmdb-checker.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/hal-rpmdb-checker.service b/packaging/hal-rpmdb-checker.service index 4780d46..e7453f4 100644 --- a/packaging/hal-rpmdb-checker.service +++ b/packaging/hal-rpmdb-checker.service @@ -3,7 +3,7 @@ Description=HAL RPMDB Checker RefuseManualStart=yes RefuseManualStop=yes DefaultDependencies=no -After=local-fs.target systemd-tmpfiles-setup.service +After=local-fs.target Before=shutdown.target [Service] -- 2.7.4 From 37b2aa44af9d54b7fdfe5237144a14a1bff9d238 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 21 Jun 2021 18:23:14 +0900 Subject: [PATCH 14/16] halapi: Don't install hal-api.json hal-api.json is not used because of package dependcency issue. Until fixing the issue, don't install hal-api.json. Change-Id: Iaafaef11db0ae3a3d5a58812e679b3b1f4716f08 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 1 - packaging/hal-api-common.spec | 1 - 2 files changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 062835b..f8be43a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,5 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/hal-api.json DESTINATION /etc/hal) ADD_SUBDIRECTORY(tests) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 206d858..42e5d49 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -107,7 +107,6 @@ fi %{_libdir}/hal/*.so* %{_sysconfdir}/ld.so.conf.d/libhal-api.conf %{_systemdgeneratordir}/systemd-hal-firmware-generator -%attr(644,root,root) %{TZ_SYS_RO_ETC}/hal/hal-api.json %files -n %{devel_name} %defattr(-,root,root,-) -- 2.7.4 From 5e83eaad9cdf2748dab8afea23b642ba85c9d68d Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 6 Jul 2021 20:02:12 +0900 Subject: [PATCH 15/16] halapi: Add new backend_module_name information Change-Id: I186359becfb908d3bd8bb78efc741da3daa87001 Signed-off-by: Chanwoo Choi --- packaging/hal-api.json | 35 +++++++++++++++++++++++++++++++++++ src/common.h | 1 + src/hal-api-conf.c | 45 ++++++++++++++++++++++++++++++++++----------- src/hal-api-list.h | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 11 deletions(-) diff --git a/packaging/hal-api.json b/packaging/hal-api.json index a2b172f..fe30ac6 100644 --- a/packaging/hal-api.json +++ b/packaging/hal-api.json @@ -5,6 +5,7 @@ { "group" :"HAL_GROUP_GRAPHICS", "module" :"HAL_MODULE_TBM", + "backend_module" :"tbm", "license" :"MIT", "library_name" :"/hal/lib/libhal-backend-tbm.so", "library_name_64bit" :"/hal/lib64/libhal-backend-tbm.so", @@ -19,6 +20,7 @@ { "group" :"HAL_GROUP_GRAPHICS", "module" :"HAL_MODULE_TDM", + "backend_module" :"tdm", "license" :"MIT", "library_name" :"/hal/lib/libhal-backend-tdm.so", "library_name_64bit" :"/hal/lib64/libhal-backend-tdm.so", @@ -33,6 +35,7 @@ { "group" :"HAL_GROUP_GRAPHICS", "module" :"HAL_MODULE_COREGL", + "backend_module" :null, "license" :"UNKNOWN", "library_name" :null, "library_name_64bit" :null, @@ -42,6 +45,7 @@ { "group" :"HAL_GROUP_GRAPHICS", "module" :"HAL_MODULE_INPUT", + "backend_module" :null, "license" :"MIT", "library_name" :null, "library_name_64bit" :null, @@ -52,6 +56,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_AUDIO", + "backend_module" :"audio", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-audio.so", "library_name_64bit" :"/hal/lib64/libhal-backend-audio.so", @@ -66,6 +71,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_CAMERA", + "backend_module" :"camera", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-camera.so", "library_name_64bit" :"/hal/lib64/libhal-backend-camera.so", @@ -80,6 +86,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_RADIO", + "backend_module" :"radio", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-radio.so", "library_name_64bit" :"/hal/lib64/libhal-backend-radio.so", @@ -94,6 +101,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_CODEC", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -103,6 +111,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_USB_AUDIO", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -112,6 +121,7 @@ { "group" :"HAL_GROUP_MULTIMEDIA", "module" :"HAL_MODULE_ALSAUCM", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -121,6 +131,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_BLUETOOTH", + "backend_module" :"bluetooth", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-bluetooth.so", "library_name_64bit" :"/hal/lib64/libhal-backend-bluetooth.so", @@ -135,6 +146,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_WIFI", + "backend_module" :"wifi", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-wifi.so", "library_name_64bit" :"/hal/lib64/libhal-backend-wifi.so", @@ -149,6 +161,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_NAN", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -158,6 +171,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_NFC", + "backend_module" :"nfc", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-nfc.so", "library_name_64bit" :"/hal/lib64/libhal-backend-nfc.so", @@ -172,6 +186,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_ZIGBEE", + "backend_module" :"zigbee", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-zigbee.so", "library_name_64bit" :"/hal/lib64/libhal-backend-zigbee.so", @@ -187,6 +202,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_UWB", + "backend_module" :"uwb", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-uwb.so", "library_name_64bit" :"/hal/lib64/libhal-backend-uwb.so", @@ -201,6 +217,7 @@ { "group" :"HAL_GROUP_CONNECTIVITY", "module" :"HAL_MODULE_MTP", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -211,6 +228,7 @@ { "group" :"HAL_GROUP_TELEPHONY", "module" :"HAL_MODULE_TELEPHONY", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -220,6 +238,7 @@ { "group" :"HAL_GROUP_LOCATION", "module" :"HAL_MODULE_LOCATION", + "backend_module" :"location", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-location.so", "library_name_64bit" :"/hal/lib64/libhal-backend-location.so", @@ -234,6 +253,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_COMMON", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -243,6 +263,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_POWER", + "backend_module" :"power", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-power.so", "library_name_64bit" :"/hal/lib64/libhal-backend-power.so", @@ -257,6 +278,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_SENSOR", + "backend_module" :"sensor", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-sensor.so", "library_name_64bit" :"/hal/lib64/libhal-backend-sensor.so", @@ -271,6 +293,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_PERIPHERAL", + "backend_module" :null, "license" :"APACHE_2_0", "library_name" :null, "library_name_64bit" :null, @@ -280,6 +303,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_BATTERY", + "backend_module" :"device-battery", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-battery.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-battery.so", @@ -294,6 +318,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_BEZEL", + "backend_module" :"device-bezel", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-bezel.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-bezel.so", @@ -308,6 +333,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_DISPLAY", + "backend_module" :"device-display", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-display.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-display.so", @@ -322,6 +348,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_IR", + "backend_module" :"device-ir", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-ir.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-ir.so", @@ -336,6 +363,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_TOUCHSCREEN", + "backend_module" :"device-touchscreen", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-touchscreen.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-touchscreen.so", @@ -350,6 +378,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_LED", + "backend_module" :"device-led", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-led.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-led.so", @@ -364,6 +393,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_BOARD", + "backend_module" :"device-board", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-board.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-board.so", @@ -378,6 +408,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", + "backend_module" :"device-external-connection", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-external-connection.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-external-connection.so", @@ -392,6 +423,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_THERMAL", + "backend_module" :"device-thermal", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-thermal.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-thermal.so", @@ -406,6 +438,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_USB_GADGET", + "backend_module" :"device-usb-gadget", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-usb-gadget.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-usb-gadget.so", @@ -420,6 +453,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_HAPTIC", + "backend_module" :"device-haptic", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-haptic.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-haptic.so", @@ -434,6 +468,7 @@ { "group" :"HAL_GROUP_SYSTEM", "module" :"HAL_MODULE_DEVICE_MEMORY", + "backend_module" :"device-memory", "license" :"APACHE_2_0", "library_name" :"/hal/lib/libhal-backend-device-memory.so", "library_name_64bit" :"/hal/lib64/libhal-backend-device-memory.so", diff --git a/src/common.h b/src/common.h index 69d7c13..b567f8b 100644 --- a/src/common.h +++ b/src/common.h @@ -90,6 +90,7 @@ struct __hal_module_info { enum hal_module module; enum hal_license license; char *module_name; + char *backend_module_name; char *library_name; char *library_name_64bit; diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 65e67f4..d511354 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -54,6 +54,7 @@ do { \ if (info) { SAFE_FREE_AND_NULL(info->module_name); + SAFE_FREE_AND_NULL(info->backend_module_name); SAFE_FREE_AND_NULL(info->library_name); SAFE_FREE_AND_NULL(info->library_name_64bit); SAFE_FREE_AND_NULL(info->symbol_name); @@ -130,6 +131,7 @@ static struct __hal_module_info *__create_hal_module_info(enum hal_module module info->module = module; info->module_name = g_strdup(__convert_module_to_string(module)); + info->backend_module_name = g_strdup(__convert_module_to_string(backend_module)); tmp = __get_json_object_string(object, "group"); info->group = __convert_group_str_to_enum(tmp); @@ -218,10 +220,11 @@ static struct __hal_module_info* _get_module_info(enum hal_module module) static struct __hal_module_info* _get_module_info_with_library_name(enum hal_module module, const char *library_name) { - struct __hal_module_info *info = NULL, *new_info = NULL; + struct __hal_module_info *info = NULL, *new_info = NULL, *tmp_info = NULL; json_object *module_array_object = NULL; const char *group_name = NULL; const char *module_name = NULL; + char *library_name_prefix = NULL; int ret; #ifdef HAL_API_CONF_JSON @@ -232,30 +235,47 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod if (!_module_hash | !library_name) return NULL; - if (!g_str_has_prefix(library_name, "libhal-backend-")) { - _E("Invalid library name(%s) of HAL module(%d)\n", - library_name, module); + tmp_info = _get_module_info(module); + if (tmp_info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + return NULL; + } + + if (tmp_info->backend_module_name == NULL) { + _E("Don't support HAL backend of HAL module(%s)\n", + tmp_info->module_name); return NULL; } + library_name_prefix = g_strdup_printf("libhal-backend-%s", + tmp_info->backend_module_name); + if (!library_name_prefix) { + _E("Failed to allocate library_name_prefix of HAL module(%s)\n", + tmp_info->module_name); + return NULL; + } + + if (!g_str_has_prefix(library_name, library_name_prefix)) { + _E("Invalid library name(%s) of HAL module(%s)\n", + library_name, tmp_info->module_name); + goto out; + } /* Find module info with the passed library name */ info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, (gpointer)library_name); - if (info) + if (info) { + g_free(library_name_prefix); return info; + } /* Create new module info with the passed library name */ - info = _get_module_info(module); - if (info == NULL) { - _E("Failed to get HAL module(%d) information\n", module); - return NULL; - } + info = tmp_info; new_info = (struct __hal_module_info *)calloc(1, sizeof(struct __hal_module_info)); if (new_info == NULL) { _E("Failed to allocate the memory\n"); - return NULL; + goto out; } new_info->usage_count = 0; @@ -276,6 +296,9 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod g_hash_table_insert(_module_hash, (gpointer)library_name, new_info); +out: + g_free(library_name_prefix); + return new_info; } diff --git a/src/hal-api-list.h b/src/hal-api-list.h index a7e0ece..f86b50f 100644 --- a/src/hal-api-list.h +++ b/src/hal-api-list.h @@ -276,6 +276,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_TBM, .license = HAL_LICENSE_MIT, .module_name = "HAL_MODULE_TBM", + .backend_module_name = "tbm", .library_name = "/hal/lib/libhal-backend-tbm.so", .library_name_64bit = "/hal/lib64/libhal-backend-tbm.so", .symbol_name = "hal_backend_tbm_data", @@ -288,6 +289,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_TDM, .license = HAL_LICENSE_MIT, .module_name = "HAL_MODULE_TDM", + .backend_module_name = "tdm", .library_name = "/hal/lib/libhal-backend-tdm.so", .library_name_64bit = "/hal/lib64/libhal-backend-tdm.so", .symbol_name = "hal_backend_tdm_data", @@ -300,6 +302,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_COREGL, .license = HAL_LICENSE_UNKNOWN, .module_name = "HAL_MODULE_COREGL", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -312,6 +315,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_INPUT, .license = HAL_LICENSE_MIT, .module_name = "HAL_MODULE_INPUT", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -326,6 +330,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_AUDIO, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_AUDIO", + .backend_module_name = "audio", .library_name = "/hal/lib/libhal-backend-audio.so", .library_name_64bit = "/hal/lib64/libhal-backend-audio.so", .symbol_name = "hal_backend_audio_data", @@ -338,6 +343,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_CAMERA, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_CAMERA", + .backend_module_name = "camera", .library_name = "/hal/lib/libhal-backend-camera.so", .library_name_64bit = "/hal/lib64/libhal-backend-camera.so", .symbol_name = "hal_backend_camera_data", @@ -350,6 +356,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_RADIO, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_RADIO", + .backend_module_name = "radio", .library_name = "/hal/lib/libhal-backend-radio.so", .library_name_64bit = "/hal/lib64/libhal-backend-radio.so", .symbol_name = "hal_backend_radio_data", @@ -362,6 +369,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_CODEC, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_CODEC", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -374,6 +382,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_USB_AUDIO, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_USB_AUDIO", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -386,6 +395,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_ALSAUCM, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_ALSAUCM", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -400,6 +410,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_BLUETOOTH, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_BLUETOOTH", + .backend_module_name = "bluetooth", .library_name = "/hal/lib/libhal-backend-bluetooth.so", .library_name_64bit = "/hal/lib64/libhal-backend-bluetooth.so", .symbol_name = "hal_backend_bluetooth_data", @@ -412,6 +423,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_WIFI, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_WIFI", + .backend_module_name = "wifi", .library_name = "/hal/lib/libhal-backend-wifi.so", .library_name_64bit = "/hal/lib64/libhal-backend-wifi.so", .symbol_name = "hal_backend_wifi_data", @@ -424,6 +436,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_NAN, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_NAN", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -436,6 +449,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_NFC, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_NFC", + .backend_module_name = "nfc", .library_name = "/hal/lib/libhal-backend-nfc.so", .library_name_64bit = "/hal/lib64/libhal-backend-nfc.so", .symbol_name = "hal_backend_nfc_data", @@ -448,6 +462,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_ZIGBEE, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_ZIGBEE", + .backend_module_name = "zigbee", .library_name = "/hal/lib/libhal-backend-zigbee.so", .library_name_64bit = "/hal/lib64/libhal-backend-zigbee.so", .symbol_name = "hal_backend_zigbee_data", @@ -460,6 +475,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_UWB, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_UWB", + .backend_module_name = "uwb", .library_name = "/hal/lib/libhal-backend-uwb.so", .library_name_64bit = "/hal/lib64/libhal-backend-uwb.so", .symbol_name = "hal_backend_uwb_data", @@ -472,6 +488,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_MTP, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_MTP", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -486,6 +503,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_TELEPHONY, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_TELEPHONY", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -500,6 +518,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_LOCATION, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_LOCATION", + .backend_module_name = "location", .library_name = "/hal/lib/libhal-backend-location.so", .library_name_64bit = "/hal/lib64/libhal-backend-location.so", .symbol_name = "hal_backend_location_data", @@ -514,6 +533,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_COMMON, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_COMMON", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -526,6 +546,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_POWER, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_POWER", + .backend_module_name = "power", .library_name = "/hal/lib/libhal-backend-power.so", .library_name_64bit = "/hal/lib64/libhal-backend-power.so", .symbol_name = "hal_backend_power_data", @@ -538,6 +559,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_SENSOR, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_SENSOR", + .backend_module_name = "sensor", .library_name = "/hal/lib/libhal-backend-sensor.so", .library_name_64bit = "/hal/lib64/libhal-backend-sensor.so", .symbol_name = "hal_backend_sensor_data", @@ -550,6 +572,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_PERIPHERAL, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_PERIPHERAL", + .backend_module_name = NULL, .library_name = NULL, .library_name_64bit = NULL, .symbol_name = NULL, @@ -562,6 +585,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_BATTERY, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_BATTERY", + .backend_module_name = "device-battery", .library_name = "/hal/lib/libhal-backend-device-battery.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-battery.so", .symbol_name = "hal_backend_device_battery_data", @@ -574,6 +598,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_BEZEL, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_BEZEL", + .backend_module_name = "device-bezel", .library_name = "/hal/lib/libhal-backend-device-bezel.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-bezel.so", .symbol_name = "hal_backend_device_bezel_data", @@ -586,6 +611,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_DISPLAY, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_DISPLAY", + .backend_module_name = "device-display", .library_name = "/hal/lib/libhal-backend-device-display.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-display.so", .symbol_name = "hal_backend_device_display_data", @@ -598,6 +624,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_IR, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_IR", + .backend_module_name = "device-ir", .library_name = "/hal/lib/libhal-backend-device-ir.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-ir.so", .symbol_name = "hal_backend_device_ir_data", @@ -610,6 +637,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_TOUCHSCREEN, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_TOUCHSCREEN", + .backend_module_name = "device-touchscreen", .library_name = "/hal/lib/libhal-backend-device-touchscreen.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-touchscreen.so", .symbol_name = "hal_backend_device_touchscreen_data", @@ -622,6 +650,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_LED, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_LED", + .backend_module_name = "device-led", .library_name = "/hal/lib/libhal-backend-device-led.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-led.so", .symbol_name = "hal_backend_device_led_data", @@ -634,6 +663,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_BOARD, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_BOARD", + .backend_module_name = "device-board", .library_name = "/hal/lib/libhal-backend-device-board.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-board.so", .symbol_name = "hal_backend_device_board_data", @@ -646,6 +676,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", + .backend_module_name = "device-external-connection", .library_name = "/hal/lib/libhal-backend-device-external-connection.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-external-connection.so", .symbol_name = "hal_backend_device_external_connection_data", @@ -658,6 +689,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_THERMAL, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_THERMAL", + .backend_module_name = "device-thermal", .library_name = "/hal/lib/libhal-backend-device-thermal.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-thermal.so", .symbol_name = "hal_backend_device_thermal_data", @@ -670,6 +702,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_USB_GADGET, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_USB_GADGET", + .backend_module_name = "device-usb-gadget", .library_name = "/hal/lib/libhal-backend-device-usb-gadget.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-usb-gadget.so", .symbol_name = "hal_backend_device_usb_gadget_data", @@ -682,6 +715,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_HAPTIC, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_HAPTIC", + .backend_module_name = "device-haptic", .library_name = "/hal/lib/libhal-backend-device-haptic.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-haptic.so", .symbol_name = "hal_backend_device_haptic_data", @@ -694,6 +728,7 @@ static struct __hal_module_info g_hal_module_info[] = { .module = HAL_MODULE_DEVICE_MEMORY, .license = HAL_LICENSE_APACHE_2_0, .module_name = "HAL_MODULE_DEVICE_MEMORY", + .backend_module_name = "device-memory", .library_name = "/hal/lib/libhal-backend-device-memory.so", .library_name_64bit = "/hal/lib64/libhal-backend-device-memory.so", .symbol_name = "hal_backend_device_memory_data", -- 2.7.4 From 6f8de361cb40d57e8d3076177ba928f92f041981 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 6 Jul 2021 18:21:49 +0900 Subject: [PATCH 16/16] halapi: Add new helper functions to get multiple library names In order to get the multiple library namse on device, add new helper function as following. Firstly, get the number of HAL backend libraries hal_common_get_backend_count() and the get the library names by hal_common_get_backend_library_names(). - Get the number of the backend libraries according to the type of HAL module int hal_common_get_backend_count(enum hal_module module); - Get the backend library names according to the type of HAL module int hal_common_get_backend_library_names(enum hal_module module, char **library_names, int library_count, int library_name_size); Change-Id: If6ecc2f550693768e6e63a572dd99c791984e596 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 20 +++++++++ src/hal-api-common.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/include/hal-common.h b/include/hal-common.h index 7ec6c1f..1b0e328 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -228,6 +228,26 @@ int hal_common_get_backend_name(enum hal_module module, char *name, int size); */ int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); +/** + * @brief Get the number of the backend libraries according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @return @c 0 on success, otherwise a negative error value + */ +int hal_common_get_backend_count(enum hal_module module); + +/** + * @brief Get the backend library names according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Data pointer should be filled by backend library names + * @param[in] Number of backend library of specific HAL module + * @param[in] Maximum length of the library name + * @return @c 0 on success, otherwise a negative error value + */ +int hal_common_get_backend_library_names(enum hal_module module, + char **library_names, + int library_count, + int library_name_size); + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 8f17557..5dbdf58 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -21,6 +21,7 @@ #include #include #include +#include #define _GNU_SOURCE #include @@ -598,3 +599,117 @@ int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size { return __get_backend_data(module, NULL, NULL, 0, vendor, size); } + + +static int __get_backend_library_data(enum hal_module module, + char **lib_names, + int lib_count, + int lib_name_size) +{ + struct __hal_module_info *info = NULL; + struct dirent *de; + DIR *dir; + const char *backend_module_name = NULL; + int count, i, ret, len; +#if defined(__aarch64__) + const char hal_backend_path[] = "/hal/lib64"; +#else + const char hal_backend_path[] = "/hal/lib"; +#endif + + /* Check parameter whether is valid or not */ + if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { + _E("Invalid parameter of HAL module (%d)\n", module); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + if (_hal_api_conf_init()) + return TIZEN_ERROR_UNKNOWN; + + info = _hal_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + if (info->backend_module_name == NULL) { + _E("Don't support HAL backend of HAL module(%s)\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + backend_module_name = g_strdup_printf("libhal-backend-%s", + info->backend_module_name); + if (!backend_module_name) { + _E("Failed to allocate the backend_module_name of HAL module(%s)\n", + info->module_name); + ret = TIZEN_ERROR_UNKNOWN; + goto err; + } + + /* Find HAL backend libraries */ + dir = opendir(hal_backend_path); + if (!dir) { + _E("Failed to find HAL backend path(%s) for HAL module(%s)\n", + hal_backend_path, info->module_name); + ret = TIZEN_ERROR_UNKNOWN; + goto err_free_backend_module_name; + } + + count = 0; + while ((de = readdir(dir)) != NULL) { + if (!g_str_has_prefix(de->d_name, backend_module_name)) + continue; + + if (lib_count == 0) + count++; + else if (lib_count > 0) { + len = strlen(de->d_name) + 1; + + if (len > lib_name_size) + len = lib_name_size; + + strncpy(lib_names[count++], de->d_name, len); + } + } + + if (lib_count > 0 && count != lib_count) { + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_mismatch_count; + } + + closedir(dir); + _hal_api_conf_exit(); + g_free(backend_module_name); + + return count; + +err_mismatch_count: + for (i = count - 1; i >= 0; i--) + memset(lib_names[i], 0, strlen(lib_names[i])); + + closedir(dir); +err_free_backend_module_name: + g_free(backend_module_name); +err: + _hal_api_conf_exit(); + return ret; +} + +EXPORT +int hal_common_get_backend_count(enum hal_module module) +{ + return __get_backend_library_data(module, NULL, 0, 0); +} + +EXPORT +int hal_common_get_backend_library_names(enum hal_module module, + char **library_names, + int library_count, + int library_name_size) +{ + int ret = __get_backend_library_data(module, library_names, + library_count, library_name_size); + return (ret < 0) ? ret : 0; +} -- 2.7.4