Move the logging code to a common directory 95/215495/2 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5 tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.021820 accepted/tizen/5.5/unified/mobile/hotfix/20201027.085855 accepted/tizen/unified/20191015.011903 submit/tizen/20191011.053630 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 tizen_5.5.m2_release
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 9 Oct 2019 14:22:54 +0000 (16:22 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 9 Oct 2019 14:32:02 +0000 (16:32 +0200)
This is to avoid 2-way calls between ta and serialization directories which SAM
complains about.

Change-Id: Ibac9f6e6bbda7ee37c7bc5591cfa2a480c9c0531

CMakeLists.txt
common/include/log.h [new file with mode: 0644]
common/src/log.c [new file with mode: 0644]
serialization/CMakeLists.txt
ta/CMakeLists.txt
ta/include/log.h [deleted file]
ta/src/log.c [deleted file]

index eafbd215749b78e997430ef677b019685a8df94a..46b3b66535c1518e3f41178f54d43fc59eacfa2d 100644 (file)
@@ -25,6 +25,7 @@ PROJECT("key-manager-ta")
 SET(KEY_MANAGER_TA_ROOT_PATH ${PROJECT_SOURCE_DIR})
 SET(KEY_MANAGER_TA_PATH ${KEY_MANAGER_TA_ROOT_PATH}/ta)
 SET(KEY_MANAGER_TA_SERIALIZATION_PATH ${KEY_MANAGER_TA_ROOT_PATH}/serialization)
+SET(KEY_MANAGER_TA_COMMON_PATH ${KEY_MANAGER_TA_ROOT_PATH}/common)
 
 IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
     ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
@@ -34,6 +35,7 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 INCLUDE_DIRECTORIES(
     ${KEY_MANAGER_TA_PATH}/include
     ${KEY_MANAGER_TA_SERIALIZATION_PATH}/include
+    ${KEY_MANAGER_TA_COMMON_PATH}/include
     )
 
 ADD_DEFINITIONS("-D${CMAKE_BUILD_TYPE}")
diff --git a/common/include/log.h b/common/include/log.h
new file mode 100644 (file)
index 0000000..0c519b7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (c) 2017 - 2019 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
+ */
+/*
+ * @file        log.h
+ * @author      Rafał Tyminski (r.tyminski@partner.samsung.com)
+ * @version     1.0
+ * @brief
+ */
+#ifndef __LOG_H__
+#define __LOG_H__
+
+#include <stdio.h>
+#include <string.h>
+
+void log_msg(const char* type, const char* location, int line, const char* func,
+                       const char* format, ...)
+__attribute__((format(printf, 5, 6)));
+
+#define LOG(...) do { \
+       log_msg(" MSG ", __FILE__, __LINE__, __func__, __VA_ARGS__); \
+} while(0)
+
+#ifdef BUILD_TYPE_DEBUG
+#define LOGD(...) do { \
+       log_msg("DEBUG", __FILE__, __LINE__, __func__, __VA_ARGS__); \
+} while(0)
+#else
+#define LOGD(...) do { } while(0)
+#endif
+
+void log_id(const char* prefix, void* id, unsigned int size);
+
+#ifdef BUILD_TYPE_DEBUG
+#define LOGD_ID(prefix, id, size) do {\
+       log_id(prefix, id, size);\
+} while(0)
+#else
+#define LOGD_ID(...) do {} while(0)
+#endif
+
+#endif // __LOG_H__
diff --git a/common/src/log.c b/common/src/log.c
new file mode 100644 (file)
index 0000000..25ba45d
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2017 - 2019 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
+ */
+
+/*
+ * @file        log.c
+ * @author      Lukasz Kostyra (l.kostyra@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#include "log.h"
+#include <malloc.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+void log_msg(const char* type, const char* location, int line, const char* func,
+                       const char* format, ...)
+{
+#ifdef BUILD_TYPE_DEBUG
+       va_list args;
+       const size_t logSize = 512; // increase this limit as needed
+       char logBuffer[logSize];
+
+       va_start(args, format);
+       vsnprintf(logBuffer, logSize, format, args);
+       va_end(args);
+
+       printf("[%s] %s @ %i (%s): %s \n\r", type, location, line, func, logBuffer);
+       fflush(stdout);
+#else
+// TODO actually code below is a mitigation for ARM compilation on OpTEE
+// TODO this entire ifdef should probably be replaced for TEE-OS specific logging
+// TODO but this should be done in separate commit
+       (void) type;
+       (void) location;
+       (void) line;
+       (void) func;
+       (void) format;
+#endif
+}
+
+void log_id(const char* prefix, void* id, unsigned int size) {
+#ifdef BUILD_TYPE_DEBUG
+       char* out = (char*)malloc(sizeof(char) * (size * 2 + 1));
+       for (unsigned int i = 0; i < size; i++)
+               snprintf(out + i*2, 3, "%02x", ((unsigned char*)id)[i]);
+       LOGD("%s%s", prefix, out);
+       free(out);
+#else
+// TODO actually code below is a mitigation for ARM compilation on OpTEE
+// TODO this entire ifdef should probably be replaced for TEE-OS specific logging
+// TODO but this should be done in separate commit
+       (void) prefix;
+       (void) id;
+       (void) size;
+#endif
+}
index 915f4120f0b46c7c2a9b23c3f3cb02199d6d538d..99640cf1aca80efc66c807473953f1e9729a76e3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2017 - 2019 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.
@@ -21,7 +21,7 @@ SET(TARGET_KEY_MANAGER_TA_SERIALIZATION km_serialization)
 
 SET(KEY_MANAGER_TA_SERIALIZATION_SOURCES
     ${KEY_MANAGER_TA_SERIALIZATION_PATH}/src/km_serialization.c
-    ${KEY_MANAGER_TA_PATH}/src/log.c
+    ${KEY_MANAGER_TA_COMMON_PATH}/src/log.c
     )
 
 SET(KEY_MANAGER_TA_SERIALIZATION_HEADERS
index 850215b1b9fe06e49ce3c67d9fb14b79ca9adcae..b473bc33c8fa8ee726058b5ce947f58eabb6a01f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2017 - 2019 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.
@@ -32,9 +32,9 @@ SET(KEY_MANAGER_TA_SOURCES
     ${KEY_MANAGER_TA_PATH}/src/crypto_padding.c
     ${KEY_MANAGER_TA_PATH}/src/crypto_symmetric.c
     ${KEY_MANAGER_TA_PATH}/src/internal.c
-    ${KEY_MANAGER_TA_PATH}/src/log.c
     ${KEY_MANAGER_TA_PATH}/src/km_ta.c
     ${KEY_MANAGER_TA_PATH}/src/base64.c
+    ${KEY_MANAGER_TA_COMMON_PATH}/src/log.c
     ${KEY_MANAGER_TA_SERIALIZATION_PATH}/src/km_serialization.c
     )
 
diff --git a/ta/include/log.h b/ta/include/log.h
deleted file mode 100644 (file)
index 0c519b7..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *  Copyright (c) 2017 - 2019 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
- */
-/*
- * @file        log.h
- * @author      Rafał Tyminski (r.tyminski@partner.samsung.com)
- * @version     1.0
- * @brief
- */
-#ifndef __LOG_H__
-#define __LOG_H__
-
-#include <stdio.h>
-#include <string.h>
-
-void log_msg(const char* type, const char* location, int line, const char* func,
-                       const char* format, ...)
-__attribute__((format(printf, 5, 6)));
-
-#define LOG(...) do { \
-       log_msg(" MSG ", __FILE__, __LINE__, __func__, __VA_ARGS__); \
-} while(0)
-
-#ifdef BUILD_TYPE_DEBUG
-#define LOGD(...) do { \
-       log_msg("DEBUG", __FILE__, __LINE__, __func__, __VA_ARGS__); \
-} while(0)
-#else
-#define LOGD(...) do { } while(0)
-#endif
-
-void log_id(const char* prefix, void* id, unsigned int size);
-
-#ifdef BUILD_TYPE_DEBUG
-#define LOGD_ID(prefix, id, size) do {\
-       log_id(prefix, id, size);\
-} while(0)
-#else
-#define LOGD_ID(...) do {} while(0)
-#endif
-
-#endif // __LOG_H__
diff --git a/ta/src/log.c b/ta/src/log.c
deleted file mode 100644 (file)
index 25ba45d..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  Copyright (c) 2017 - 2019 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
- */
-
-/*
- * @file        log.c
- * @author      Lukasz Kostyra (l.kostyra@samsung.com)
- * @version     1.0
- * @brief
- */
-
-#include "log.h"
-#include <malloc.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-void log_msg(const char* type, const char* location, int line, const char* func,
-                       const char* format, ...)
-{
-#ifdef BUILD_TYPE_DEBUG
-       va_list args;
-       const size_t logSize = 512; // increase this limit as needed
-       char logBuffer[logSize];
-
-       va_start(args, format);
-       vsnprintf(logBuffer, logSize, format, args);
-       va_end(args);
-
-       printf("[%s] %s @ %i (%s): %s \n\r", type, location, line, func, logBuffer);
-       fflush(stdout);
-#else
-// TODO actually code below is a mitigation for ARM compilation on OpTEE
-// TODO this entire ifdef should probably be replaced for TEE-OS specific logging
-// TODO but this should be done in separate commit
-       (void) type;
-       (void) location;
-       (void) line;
-       (void) func;
-       (void) format;
-#endif
-}
-
-void log_id(const char* prefix, void* id, unsigned int size) {
-#ifdef BUILD_TYPE_DEBUG
-       char* out = (char*)malloc(sizeof(char) * (size * 2 + 1));
-       for (unsigned int i = 0; i < size; i++)
-               snprintf(out + i*2, 3, "%02x", ((unsigned char*)id)[i]);
-       LOGD("%s%s", prefix, out);
-       free(out);
-#else
-// TODO actually code below is a mitigation for ARM compilation on OpTEE
-// TODO this entire ifdef should probably be replaced for TEE-OS specific logging
-// TODO but this should be done in separate commit
-       (void) prefix;
-       (void) id;
-       (void) size;
-#endif
-}