Use hal-rootstrap instead of individual packages 62/314062/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 4 Jul 2024 12:16:57 +0000 (14:16 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 4 Jul 2024 12:41:49 +0000 (14:41 +0200)
Change-Id: I4df072341584c501f4799664c6a38cef1d3cf30f

CMakeLists.txt
hw/display/CMakeLists.txt
hw/display/display.c
hw/memory/CMakeLists.txt
hw/memory/memory.c
include/hal-backend-device-visionfive2-common.h [deleted file]
include/util.h [new file with mode: 0644]
packaging/hal-backend-device-visionfive2.spec
src/util.c [new file with mode: 0644]

index e73b8cae91212184800d254b5f63e0c97c373ac6..3898d5a2608c56b07c0865eba72c896f092b9314 100644 (file)
@@ -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)
index 3cd56eef84151264469b2545f038021451e7bf06..1b7d63e2722d06f09adc58242bcb5512854c25b7 100644 (file)
@@ -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}")
index 2029e3eebae1d200889aab275e003e9923961584..cec69122cddc030ae8152efaed9ea3db90ea8712 100644 (file)
@@ -25,7 +25,7 @@
 #include <hal/hal-device-display-interface.h>
 #include <hal/hal-common-interface.h>
 
-#include "hal-backend-device-visionfive2-common.h"
+#include "util.h"
 
 static int display_get_max_brightness(int *val)
 {
index a35248a5828afb5efd9c345ad3a99a4e8b04f34f..7b39d308e0658f3211146c0356bae2b06855e700 100644 (file)
@@ -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}")
index 84f4c9b820451421910b81bb293700ec68fd7e8a..b42cceaac7c67bed719d570ce03a926dac54defa 100644 (file)
@@ -21,7 +21,7 @@
 #include <hal/hal-device-memory-interface.h>
 #include <hal/hal-common-interface.h>
 
-#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 (file)
index a995677..0000000
+++ /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 <dlog.h>
-    #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 (file)
index 0000000..7e89de0
--- /dev/null
@@ -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 <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, ...);
index 7e5787cb548ec302795aa3a1bb9b53c283e30293..1b3bc77975ec0c002f4f40b93d098cce02213ca4 100644 (file)
@@ -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 (file)
index 0000000..e2abf4b
--- /dev/null
@@ -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