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)
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}")
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)
#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"
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)
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;
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;
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;
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)
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;
}
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;
return -ferror;
}
- return sys_set_str(UPGRADE_STATE_PATH, state);
+ return sysfs_write_str(UPGRADE_STATE_PATH, state);
}
static void trim_str(char *str)
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;
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}")
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)
#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"
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;
}
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;
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;
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}")
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)
#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
{
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;
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) {
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;
_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) {
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}")
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)
#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)
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}")
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)
#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"
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}")
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)
#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"
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}")
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)
#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"
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;
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);
--- /dev/null
+/*
+ * 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, ...);
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
--- /dev/null
+/*
+ * 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