Add board HAL 07/182907/2
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 28 Jun 2018 12:11:59 +0000 (14:11 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Sat, 7 Jul 2018 03:00:58 +0000 (03:00 +0000)
Change-Id: Ib968cd4c36771efdbed3b6234cd06fc149003a26
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
CMakeLists.txt
hw/board/CMakeLists.txt [new file with mode: 0644]
hw/board/board.c [new file with mode: 0755]

index eec07916a6ef1d71f8920d6e4aab10c7976d9290..b05cd168f2aba24938dc2b124fba5f972c2ce6ab 100644 (file)
@@ -4,6 +4,7 @@ PROJECT(device-manager-exynos5433 C)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 ADD_SUBDIRECTORY(hw/battery)
+ADD_SUBDIRECTORY(hw/board)
 ADD_SUBDIRECTORY(hw/display)
 ADD_SUBDIRECTORY(hw/led)
 ADD_SUBDIRECTORY(hw/touchscreen)
diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5b8b5b4
--- /dev/null
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(board C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon)
+
+FOREACH(flag ${usb_gadget_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+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)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/board/board.c b/hw/board/board.c
new file mode 100755 (executable)
index 0000000..1448e2e
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * libdevice-node
+ *
+ * Copyright (c) 2016 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.
+ */
+
+#define _GNU_SOURCE
+#include <hw/board.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#define MMC_ID_PATH "/sys/class/mmc_host/mmc0/mmc0:0001/cid"
+#define SERIAL_OFFSET 16
+#define SERIAL_LEN 16
+#define LINE_LEN (SERIAL_OFFSET + SERIAL_LEN + 2)
+
+static int get_device_serial(char **out)
+{
+       FILE *fp;
+       char line[LINE_LEN], *p;
+
+       fp = fopen(MMC_ID_PATH, "r");
+       if (!fp)
+               return -1;
+
+       p = fgets(line, LINE_LEN, fp);
+       fclose(fp);
+       if (p == NULL)
+               return -1;
+
+       *out = strndup(line + SERIAL_OFFSET, SERIAL_LEN);
+       return 0;
+}
+
+static int board_open(struct hw_info *info,
+               const char *id, struct hw_common **common)
+{
+       struct hw_board *b;
+
+       if (!info || !common)
+               return -EINVAL;
+
+       b = calloc(1, sizeof(*b));
+       if (!b)
+               return -ENOMEM;
+
+       b->common.info = info;
+       b->get_device_serial = get_device_serial;
+
+       *common = &b->common;
+       return 0;
+}
+
+static int board_close(struct hw_common *common)
+{
+       struct hw_board *b;
+
+       if (!common)
+               return -EINVAL;
+
+       b = container_of(common, struct hw_board, common);
+       free(b);
+
+       return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+       .magic = HARDWARE_INFO_TAG,
+       .hal_version = HARDWARE_INFO_VERSION,
+       .device_version = BOARD_HARDWARE_DEVICE_VERSION,
+       .id = BOARD_HARDWARE_DEVICE_ID,
+       .name = "device",
+       .open = board_open,
+       .close = board_close,
+};