summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunhee Seo <yuni.seo@samsung.com>2024-07-02 14:25:20 +0900
committerYunhee Seo <yuni.seo@samsung.com>2024-07-03 11:23:33 +0900
commit298639364991a70e0247202f436f86d7f0bbf58f (patch)
treeaaeb2ffc677a3050d11fb176549b9521e878405c
parent7e5138a23dcf6a087a8d78e86c8f3906fde66eee (diff)
downloaddevice-rpi-298639364991a70e0247202f436f86d7f0bbf58f.tar.gz
device-rpi-298639364991a70e0247202f436f86d7f0bbf58f.tar.bz2
device-rpi-298639364991a70e0247202f436f86d7f0bbf58f.zip
As support hal-abi-versioning, the hal-backend package should be built using only the hal-rootstrap. Other packages not included in the hal-roostrap have been deleted to remove dependencies. util is added to replace functions of dlog and libsyscommon package. Change-Id: I828813ef12dc695ddf66885269df5aabf2cd8717 Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
-rw-r--r--CMakeLists.txt9
-rw-r--r--hw/board/CMakeLists.txt9
-rw-r--r--hw/board/board.c29
-rw-r--r--hw/display/CMakeLists.txt8
-rw-r--r--hw/display/display.c9
-rw-r--r--hw/haptic/CMakeLists.txt10
-rw-r--r--hw/haptic/gpio.c15
-rw-r--r--hw/led/CMakeLists.txt6
-rw-r--r--hw/led/led.c4
-rw-r--r--hw/memory/CMakeLists.txt6
-rw-r--r--hw/memory/memory.c2
-rw-r--r--hw/thermal/CMakeLists.txt6
-rw-r--r--hw/thermal/thermal.c2
-rw-r--r--hw/touchscreen/CMakeLists.txt6
-rw-r--r--hw/touchscreen/touchscreen.c7
-rw-r--r--include/util.h50
-rw-r--r--packaging/hal-backend-device-rpi.spec7
-rw-r--r--src/util.c159
18 files changed, 280 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f8bf84e..391daa1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,10 +5,19 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror")
+INCLUDE(FindPkgConfig)
+pkg_check_modules(hal-backend-device-rpi_pkgs REQUIRED hal-rootstrap)
+
+FOREACH(flag ${hal-backend-device-rpi_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
IF(ENABLE_DLOG STREQUAL on)
ADD_DEFINITIONS("-DFEATURE_DLOG")
ENDIF()
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.Apache-2.0 DESTINATION ${HAL_LICENSE_DIR}/${PROJECT_NAME})
ADD_SUBDIRECTORY(hw/board)
diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt
index 5234091..358723c 100644
--- a/hw/board/CMakeLists.txt
+++ b/hw/board/CMakeLists.txt
@@ -3,11 +3,10 @@ PROJECT(hal-backend-device-board C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-board_pkgs REQUIRED
- hal-backend-device-common
- libsyscommon
- )
+pkg_check_modules(hal-backend-device-board_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-board_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -16,6 +15,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE board.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE board.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-board_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/board/board.c b/hw/board/board.c
index caa213e..3e9233a 100644
--- a/hw/board/board.c
+++ b/hw/board/board.c
@@ -26,8 +26,7 @@
#include <unistd.h>
#include <ctype.h>
-#include </hal/include/device/hal-backend-common.h>
-#include <libsyscommon/file.h>
+#include "util.h"
#define INFORM_MNT_PATH "/mnt/inform"
#define PARTITION_AB_PATH INFORM_MNT_PATH"/partition-ab.info"
@@ -73,7 +72,7 @@ static int clear_boot_mode(void)
return -ferror;
}
- return sys_set_str(REBOOT_PARAM_PATH, BOOT_MODE_NORMAL);
+ return sysfs_write_str(REBOOT_PARAM_PATH, BOOT_MODE_NORMAL);
}
static int get_boot_mode(char *buffer, const int max_len)
@@ -83,7 +82,7 @@ static int get_boot_mode(char *buffer, const int max_len)
snprintf(scan_format, sizeof(scan_format), "bootmode=%%%ds", max_len - 1);
- ret = syscommon_parse_cmdline_scanf(scan_format, buffer);
+ ret = parse_cmdline_scanf(scan_format, buffer);
if (ret <= 0) {
return -ENOENT;
@@ -99,7 +98,7 @@ static int get_boot_mode(char *buffer, const int max_len)
static int get_current_partition(char *partition_ab)
{
- int ret_parse = syscommon_parse_cmdline_scanf("partition_ab=%c", partition_ab);
+ int ret_parse = parse_cmdline_scanf("partition_ab=%c", partition_ab);
if (ret_parse <= 0) {
return -ENOENT;
@@ -136,22 +135,22 @@ static int switch_partition(char partition_ab)
return -EINVAL;
}
- return sys_write_buf(PARTITION_AB_PATH, next_partition_ab);
+ return sysfs_write_buf(PARTITION_AB_PATH, next_partition_ab);
}
static int set_partition_ab_cloned(void)
{
- return sys_write_buf(PARTITION_AB_CLONED_PATH, "1");
+ return sysfs_write_buf(PARTITION_AB_CLONED_PATH, "1");
}
static int clear_partition_ab_cloned(void)
{
- return sys_write_buf(PARTITION_AB_CLONED_PATH, "0");
+ return sysfs_write_buf(PARTITION_AB_CLONED_PATH, "0");
}
static int get_partition_ab_cloned(int *cloned)
{
- int ret_get_int = sys_get_int(PARTITION_AB_CLONED_PATH, cloned);
+ int ret_get_int = sysfs_read_int(PARTITION_AB_CLONED_PATH, cloned);
if (ret_get_int < 0) {
return ret_get_int;
@@ -198,7 +197,7 @@ static int set_partition_status(char partition_ab, const char *status)
return -ferror;
}
- return sys_set_str(path, (char *)status);
+ return sysfs_write_str(path, (char *)status);
}
static int get_partition_status(char partition_ab, char *buffer, const int max_len)
@@ -227,7 +226,7 @@ static int get_partition_status(char partition_ab, char *buffer, const int max_l
return -EINVAL;
}
- int res_get_str = sys_get_str(path, buffer, max_len);
+ int res_get_str = sysfs_read_str(path, buffer, max_len);
if (res_get_str < 0) {
return res_get_str;
}
@@ -258,12 +257,12 @@ static int set_upgrade_progress_status(int status)
return -ferror;
}
- return sys_set_int(UPGRADE_PROGRESS_STATUS_PATH, status);
+ return sysfs_write_int(UPGRADE_PROGRESS_STATUS_PATH, status);
}
static int get_upgrade_progress_status(int *status)
{
- int ret_get_int = sys_get_int(UPGRADE_PROGRESS_STATUS_PATH, status);
+ int ret_get_int = sysfs_read_int(UPGRADE_PROGRESS_STATUS_PATH, status);
if (ret_get_int < 0) {
return ret_get_int;
@@ -289,7 +288,7 @@ static int set_upgrade_state(char *state)
return -ferror;
}
- return sys_set_str(UPGRADE_STATE_PATH, state);
+ return sysfs_write_str(UPGRADE_STATE_PATH, state);
}
static void trim_str(char *str)
@@ -330,7 +329,7 @@ static int get_upgrade_state(char *buffer, const int max_len)
if (max_len < 1)
return -EINVAL;
- ret = sys_get_str(UPGRADE_STATE_PATH, buffer, max_len - 1);
+ ret = sysfs_read_str(UPGRADE_STATE_PATH, buffer, max_len - 1);
if (ret < 0)
return ret;
diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt
index 5fa6a8e..ef0b4c7 100644
--- a/hw/display/CMakeLists.txt
+++ b/hw/display/CMakeLists.txt
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-display C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-display_pkgs REQUIRED hal-backend-device-common libsyscommon)
+pkg_check_modules(hal-backend-device-display_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-display_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -14,13 +16,13 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
SET(HAL_BACKEND_DEVICE_DISPLAY_RPI3 ${PROJECT_NAME}.rpi3)
-ADD_LIBRARY(${HAL_BACKEND_DEVICE_DISPLAY_RPI3} MODULE display.c)
+ADD_LIBRARY(${HAL_BACKEND_DEVICE_DISPLAY_RPI3} MODULE display.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_COMPILE_DEFINITIONS(${HAL_BACKEND_DEVICE_DISPLAY_RPI3} PUBLIC RPI3)
TARGET_LINK_LIBRARIES(${HAL_BACKEND_DEVICE_DISPLAY_RPI3} ${hal-backend-device-display_pkgs_LDFLAGS})
INSTALL(TARGETS ${HAL_BACKEND_DEVICE_DISPLAY_RPI3} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
SET(HAL_BACKEND_DEVICE_DISPLAY_RPI4 ${PROJECT_NAME}.rpi4)
-ADD_LIBRARY(${HAL_BACKEND_DEVICE_DISPLAY_RPI4} MODULE display.c)
+ADD_LIBRARY(${HAL_BACKEND_DEVICE_DISPLAY_RPI4} MODULE display.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_COMPILE_DEFINITIONS(${HAL_BACKEND_DEVICE_DISPLAY_RPI4} PUBLIC RPI4)
TARGET_LINK_LIBRARIES(${HAL_BACKEND_DEVICE_DISPLAY_RPI4} ${hal-backend-device-display_pkgs_LDFLAGS})
INSTALL(TARGETS ${HAL_BACKEND_DEVICE_DISPLAY_RPI4} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/display/display.c b/hw/display/display.c
index 059f433..e4c9fe0 100644
--- a/hw/display/display.c
+++ b/hw/display/display.c
@@ -25,9 +25,8 @@
#include <hal/hal-device-display-interface.h>
#include <hal/hal-common-interface.h>
-#include <libsyscommon/file.h>
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
#if defined(RPI3)
#define BACKLIGHT_PATH "/sys/class/backlight/rpi_backlight"
@@ -46,7 +45,7 @@ static int display_get_max_brightness(int *val)
return -EINVAL;
if (max < 0) {
- r = sys_get_int(BACKLIGHT_PATH"/max_brightness", &max);
+ r = sysfs_read_int(BACKLIGHT_PATH"/max_brightness", &max);
if (r < 0)
return -ENOTSUP;
}
@@ -64,7 +63,7 @@ static int display_get_brightness(int *brightness)
return -EINVAL;
}
- r = sys_get_int(BACKLIGHT_PATH"/brightness", &v);
+ r = sysfs_read_int(BACKLIGHT_PATH"/brightness", &v);
if (r < 0) {
_E("fail to get brightness (errno:%d)", r);
return -ENOTSUP;
@@ -89,7 +88,7 @@ static int display_set_brightness(int brightness)
return -EINVAL;
}
- r = sys_set_int(BACKLIGHT_PATH"/brightness", brightness);
+ r = sysfs_write_int(BACKLIGHT_PATH"/brightness", brightness);
if (r < 0) {
_E("fail to set brightness (errno:%d)", r);
return r;
diff --git a/hw/haptic/CMakeLists.txt b/hw/haptic/CMakeLists.txt
index d3b5d3c..c04a362 100644
--- a/hw/haptic/CMakeLists.txt
+++ b/hw/haptic/CMakeLists.txt
@@ -3,12 +3,10 @@ PROJECT(hal-backend-device-haptic C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(haptic_pkgs REQUIRED
- hal-backend-device-common
- glib-2.0
- libsyscommon
- capi-system-peripheral-io)
+pkg_check_modules(haptic_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${haptic_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -17,7 +15,7 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE gpio.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE gpio.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${haptic_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/haptic/gpio.c b/hw/haptic/gpio.c
index ecd82a5..81f9bdb 100644
--- a/hw/haptic/gpio.c
+++ b/hw/haptic/gpio.c
@@ -19,10 +19,9 @@
#include <stdlib.h>
#include <glib.h>
#include <peripheral_io.h>
-#include <libsyscommon/list.h>
#include <hal/hal-device-haptic-interface.h>
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
#define GPIO_I2C_BUS_INDEX 1
#define MAX_HAPIC 1
@@ -85,7 +84,7 @@ static bool find_from_list(int handle)
{
GList *elem;
- elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)handle);
+ elem = g_list_find(handle_list, (gpointer)(long)handle);
if (elem)
return true;
@@ -140,7 +139,7 @@ static int gpio_haptic_open_device(int *handle)
return -EINVAL;
/* if it is the first element */
- n = SYS_G_LIST_LENGTH(handle_list);
+ n = g_list_length(handle_list);
if (n == 0) {
_I("Peripheral Device Open.");
if (device_handle == NULL) {
@@ -156,13 +155,13 @@ static int gpio_haptic_open_device(int *handle)
while (found != true) {
++unique_number;
- elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number);
+ elem = g_list_find(handle_list, (gpointer)(long)unique_number);
if (!elem)
found = true;
}
/* add info to local list */
- SYS_G_LIST_APPEND(handle_list, (gpointer)(long)unique_number);
+ handle_list = g_list_append(handle_list, (gpointer)(long)unique_number);
*handle = unique_number;
return 0;
@@ -190,10 +189,10 @@ static int gpio_haptic_close_device(int handle)
_I("Already stopped or failed to stop effect: %d", r);
_D("Handle(%d) is closed and timer deleted.", handle);
- SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)handle);
+ handle_list = g_list_remove(handle_list, (gpointer)(long)handle);
/* if it is the last element */
- n = SYS_G_LIST_LENGTH(handle_list);
+ n = g_list_length(handle_list);
if (n == 0) {
_I("Peripheral Device Close.");
if (device_handle != NULL) {
diff --git a/hw/led/CMakeLists.txt b/hw/led/CMakeLists.txt
index c0e1583..5571f02 100644
--- a/hw/led/CMakeLists.txt
+++ b/hw/led/CMakeLists.txt
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-led C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-led_pkgs REQUIRED hal-backend-device-common glib-2.0 capi-system-peripheral-io)
+pkg_check_modules(hal-backend-device-led_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-led_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE led.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE led.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-led_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/led/led.c b/hw/led/led.c
index 92bb67b..e07ab7d 100644
--- a/hw/led/led.c
+++ b/hw/led/led.c
@@ -23,10 +23,10 @@
#include <hal/hal-device-led-interface.h>
#include <hal/hal-common-interface.h>
-#include </hal/include/device/hal-backend-common.h>
-
#include <peripheral_io.h>
+#include "util.h"
+
#define GET_BRIGHTNESS(val) (((val) >> 24) & 0xFF)
#define GET_TYPE(a) (((a) >> 24) & 0xFF)
diff --git a/hw/memory/CMakeLists.txt b/hw/memory/CMakeLists.txt
index a35248a..77b4f9c 100644
--- a/hw/memory/CMakeLists.txt
+++ b/hw/memory/CMakeLists.txt
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-memory C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED dlog)
+pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-memory_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE memory.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE memory.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-memory_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/memory/memory.c b/hw/memory/memory.c
index 3347d23..28f99c2 100644
--- a/hw/memory/memory.c
+++ b/hw/memory/memory.c
@@ -21,7 +21,7 @@
#include <hal/hal-device-memory-interface.h>
#include <hal/hal-common-interface.h>
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
#define GEM_INFO_PATH "/sys/kernel/debug/dri/0/gem_info"
#define GEM_INFO_PATH1 "/sys/kernel/debug/dri/1/gem_info"
diff --git a/hw/thermal/CMakeLists.txt b/hw/thermal/CMakeLists.txt
index 197833c..ee95e00 100644
--- a/hw/thermal/CMakeLists.txt
+++ b/hw/thermal/CMakeLists.txt
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-thermal C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-thermal_pkgs REQUIRED hal-backend-device-common glib-2.0)
+pkg_check_modules(hal-backend-device-thermal_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-thermal_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE thermal.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE thermal.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-thermal_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/thermal/thermal.c b/hw/thermal/thermal.c
index fb59d28..91c36c0 100644
--- a/hw/thermal/thermal.c
+++ b/hw/thermal/thermal.c
@@ -26,7 +26,7 @@
#include <hal/hal-device-thermal-interface.h>
#include <hal/hal-common-interface.h>
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
#define AP_PATH "/sys/class/thermal/thermal_zone0/temp"
diff --git a/hw/touchscreen/CMakeLists.txt b/hw/touchscreen/CMakeLists.txt
index 207d23f..d9b00fa 100644
--- a/hw/touchscreen/CMakeLists.txt
+++ b/hw/touchscreen/CMakeLists.txt
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-touchscreen C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-touchscreen_pkgs REQUIRED hal-backend-device-common libsyscommon)
+pkg_check_modules(hal-backend-device-touchscreen_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-touchscreen_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE touchscreen.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE touchscreen.c ${CMAKE_SOURCE_DIR}/src/util.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-touchscreen_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c
index cf73293..32bd1ea 100644
--- a/hw/touchscreen/touchscreen.c
+++ b/hw/touchscreen/touchscreen.c
@@ -27,9 +27,8 @@
#include <hal/hal-device-touchscreen-interface.h>
#include <hal/hal-common-interface.h>
-#include <libsyscommon/file.h>
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
#define TOUCHSCREEN_CON_FILE "/sys/devices/platform/rpi_ft5406/enable"
@@ -48,7 +47,7 @@ static int touchscreen_get_state(hal_device_touchscreen_state_e *state)
if (access(TOUCHSCREEN_CON_FILE, F_OK) != 0)
return -ENODEV;
- ret = sys_get_int(TOUCHSCREEN_CON_FILE, &val);
+ ret = sysfs_read_int(TOUCHSCREEN_CON_FILE, &val);
if (ret < 0) {
_E("Failed to get touchscreen state (%d)", ret);
return ret;
@@ -90,7 +89,7 @@ static int touchscreen_set_state(hal_device_touchscreen_state_e state)
return -EINVAL;
}
- ret = sys_set_int(TOUCHSCREEN_CON_FILE, val);
+ ret = sysfs_write_int(TOUCHSCREEN_CON_FILE, val);
if (ret < 0)
_E("Failed to change touchscreen state (%d)", ret);
diff --git a/include/util.h b/include/util.h
new file mode 100644
index 0000000..abec175
--- /dev/null
+++ b/include/util.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+#ifdef FEATURE_DLOG
+ #define LOG_TAG "HAL_BACKEND_DEVICE_RPI"
+ #include <dlog.h>
+ #define _D(fmt, args...) dlog_print(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+ #define _I(fmt, args...) dlog_print(DLOG_INFO, LOG_TAG, fmt, ##args)
+ #define _W(fmt, args...) dlog_print(DLOG_WARN, LOG_TAG, fmt, ##args)
+ #define _E(fmt, args...) dlog_print(DLOG_ERROR, LOG_TAG, fmt, ##args)
+#else
+ #define _D(x, ...)
+ #define _I(x, ...)
+ #define _W(x, ...)
+ #define _E(x, ...)
+#endif
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+#define MAX_BUF_SIZE 255
+
+int sysfs_read_int(char *path, int *val);
+int sysfs_read_str(char *path, char *str, int len);
+int sysfs_write_buf(char *path, char *buf);
+int sysfs_write_int(char *path, int val);
+int sysfs_write_str(char *path, char *str);
+
+/**
+ * @brief Parse format from /proc/cmdline
+ *
+ * @param[in] format Format string
+ * @param[out] ... Variable argument
+ *
+ * @return zero if cannot read else the number of matched and assigned items
+ */
+int parse_cmdline_scanf(const char *format, ...);
diff --git a/packaging/hal-backend-device-rpi.spec b/packaging/hal-backend-device-rpi.spec
index 67bb5c3..1e108d9 100644
--- a/packaging/hal-backend-device-rpi.spec
+++ b/packaging/hal-backend-device-rpi.spec
@@ -10,12 +10,7 @@ ExclusiveArch: %{arm} aarch64
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: cmake
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(capi-system-peripheral-io)
-BuildRequires: pkgconfig(hal-api-common)
-BuildRequires: pkgconfig(hal-api-device)
-BuildRequires: pkgconfig(libsyscommon)
-BuildRequires: pkgconfig(hal-backend-device-common)
+BuildRequires: pkgconfig(hal-rootstrap)
%description
Device HAL backend drivers for Raspberry Pi targets
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..e2abf4b
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2024 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 <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "util.h"
+
+static int sysfs_read_buf(char *path, char *buf, int len)
+{
+ int r, fd;
+
+ if ((!path) || (!buf) || (len < 0))
+ return -EINVAL;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -ENOENT;
+
+ r = read(fd, buf, len);
+ close(fd);
+
+ if ((r < 0) || (r > len))
+ return -EIO;
+
+ /* Replace '\n' with space (ascii code is 32) */
+ buf[strcspn(buf, "\n")] = (char)32;
+ buf[r] = '\0';
+
+ return 0;
+}
+
+int sysfs_write_buf(char *path, char *buf)
+{
+ int w, fd;
+
+ if ((!path) || (!buf))
+ return -EINVAL;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1)
+ return -ENOENT;
+
+ w = write(fd, buf, strlen(buf));
+ close(fd);
+
+ if (w < 0)
+ return -EIO;
+
+ return 0;
+}
+
+int sysfs_read_int(char *path, int *val)
+{
+ char buf[MAX_BUF_SIZE + 1];
+ int r;
+
+ if ((!path) || (!val))
+ return -EINVAL;
+
+ r = sysfs_read_buf(path, buf, MAX_BUF_SIZE);
+ if (r < 0)
+ return r;
+
+ *val = atoi(buf);
+ return 0;
+}
+
+int sysfs_read_str(char *path, char *str, int len)
+{
+ int r;
+
+ if ((!path) || (!str) || (len <= 0))
+ return -EINVAL;
+
+ r = sysfs_read_buf(path, str, len);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int sysfs_write_int(char *path, int val)
+{
+ char buf[MAX_BUF_SIZE + 1];
+ int w;
+
+ if (!path)
+ return -EINVAL;
+
+ snprintf(buf, MAX_BUF_SIZE, "%d", val);
+ w = sysfs_write_buf(path, buf);
+ if (w < 0)
+ return w;
+
+ return 0;
+}
+
+int sysfs_write_str(char *path, char *str)
+{
+ int w;
+
+ if ((!path) || (!str))
+ return -EINVAL;
+
+ w = sysfs_write_buf(path, str);
+ if (w < 0)
+ return w;
+
+ return 0;
+}
+
+int parse_cmdline_scanf(const char *format, ...)
+{
+ FILE *fp = NULL;
+ char *token = NULL;
+ size_t len = 0;
+ va_list ap;
+ int ret = 0;
+ char buffer[MAX_BUF_SIZE + 1];
+
+ fp = fopen("/proc/cmdline", "r");
+ if (!fp)
+ return 0;
+
+ va_start(ap, format);
+
+ while (getdelim(&token, &len, ' ', fp) != EOF) {
+ if (len > MAX_BUF_SIZE)
+ len = MAX_BUF_SIZE;
+ strncpy(buffer, token, len);
+ buffer[MAX_BUF_SIZE] = '\0';
+ ret = vsscanf(buffer, format, ap);
+ memset(buffer, 0, sizeof(buffer));
+ if (ret > 0)
+ break;
+ }
+
+ free(token);
+ va_end(ap);
+ fclose(fp);
+
+ return ret;
+} \ No newline at end of file