From: Mateusz Moscicki Date: Thu, 4 Jul 2024 12:16:57 +0000 (+0200) Subject: Use hal-rootstrap instead of individual packages X-Git-Tag: accepted/tizen/unified/x/20240708.014828~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b95efad5385b7ca43323dca4f79a357c5f9388b;p=platform%2Fhal%2Fbackend%2Fvisionfive2%2Fdevice-visionfive2.git Use hal-rootstrap instead of individual packages Change-Id: I4df072341584c501f4799664c6a38cef1d3cf30f --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e73b8ca..3898d5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,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-visionfive2_pkgs REQUIRED dlog) +pkg_check_modules(hal-backend-device-visionfive2_pkgs REQUIRED hal-rootstrap) + +FOREACH(flag ${hal-backend-device-visionfive2_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/display) -ADD_SUBDIRECTORY(hw/memory) \ No newline at end of file +ADD_SUBDIRECTORY(hw/memory) diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt index 3cd56ee..1b7d63e 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 dlog) +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}") diff --git a/hw/display/display.c b/hw/display/display.c index 2029e3e..cec6912 100644 --- a/hw/display/display.c +++ b/hw/display/display.c @@ -25,7 +25,7 @@ #include #include -#include "hal-backend-device-visionfive2-common.h" +#include "util.h" static int display_get_max_brightness(int *val) { diff --git a/hw/memory/CMakeLists.txt b/hw/memory/CMakeLists.txt index a35248a..7b39d30 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}") diff --git a/hw/memory/memory.c b/hw/memory/memory.c index 84f4c9b..b42ccea 100644 --- a/hw/memory/memory.c +++ b/hw/memory/memory.c @@ -21,7 +21,7 @@ #include #include -#include "hal-backend-device-visionfive2-common.h" +#include "util.h" static int memory_get_gpu_info(const int pid, hal_device_memory_gpu_info_s *info) { diff --git a/include/hal-backend-device-visionfive2-common.h b/include/hal-backend-device-visionfive2-common.h deleted file mode 100644 index a995677..0000000 --- a/include/hal-backend-device-visionfive2-common.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - - -#ifndef __HAL_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__ -#define __HAL_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__ - -#ifdef FEATURE_DLOG - #define LOG_TAG "HAL_BACKEND_DEVICE_VISIONFIVE2" - #include - #define _D(fmt, args...) SLOGD(fmt, ##args) - #define _I(fmt, args...) SLOGI(fmt, ##args) - #define _W(fmt, args...) SLOGW(fmt, ##args) - #define _E(fmt, args...) SLOGE(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])) -#endif /* __HAL_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__ */ diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..7e89de0 --- /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_VISIONFIVE2" + #include + #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-visionfive2.spec b/packaging/hal-backend-device-visionfive2.spec index 7e5787c..1b3bc77 100644 --- a/packaging/hal-backend-device-visionfive2.spec +++ b/packaging/hal-backend-device-visionfive2.spec @@ -10,9 +10,7 @@ ExclusiveArch: riscv64 Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: cmake -BuildRequires: pkgconfig(hal-api-common) -BuildRequires: pkgconfig(hal-api-device) -BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(hal-rootstrap) %description Device HAL backend drivers for RISC-V VisionFive2 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 +#include +#include +#include +#include + +#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