feat(libtl): integrate Transfer List Library as submodule
Replaces in-tree transfer_list implementation with LibTL submodule.
Removes legacy source and headers, updates includes and makefiles
to use the standalone library. Adds architecture-specific inttypes
headers for compatibility.
Change-Id: Iff8272a6417983b9fb8e7f6bde6db44c2a6020f5
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/.gitmodules b/.gitmodules
index 1946491..c753963 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,7 @@
[submodule "ext/mbedtls"]
path = ext/mbedtls
url = https://github.com/Mbed-TLS/mbedtls.git
+[submodule "libtl"]
+ path = contrib/libtl
+ url = https://review.trustedfirmware.org/shared/transfer-list-library
+ shallow = true
diff --git a/Makefile b/Makefile
index 3ebf566..d5a18be 100644
--- a/Makefile
+++ b/Makefile
@@ -98,6 +98,9 @@
DOCS_PATH := docs
+# Path to Transfer List Library (LibTL)
+LIBTL_PATH := contrib/libtl
+
ifeq (${PLAT},)
$(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
endif
diff --git a/contrib/libtl b/contrib/libtl
new file mode 160000
index 0000000..38b309b
--- /dev/null
+++ b/contrib/libtl
@@ -0,0 +1 @@
+Subproject commit 38b309b70f830280af038e03c51082df8f54a149
diff --git a/include/lib/event_log/event_handoff.h b/include/lib/event_log/event_handoff.h
index e969d1f..f8c8716 100644
--- a/include/lib/event_log/event_handoff.h
+++ b/include/lib/event_log/event_handoff.h
@@ -10,7 +10,7 @@
#include <stdint.h>
-#include <lib/transfer_list.h>
+#include <transfer_list.h>
/**
* Initializes or extends the TPM event log in the transfer list.
diff --git a/include/lib/event_log/event_log.h b/include/lib/event_log/event_log.h
index b5adfdc..964f80a 100644
--- a/include/lib/event_log/event_log.h
+++ b/include/lib/event_log/event_log.h
@@ -10,6 +10,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <lib/utils_def.h>
#include <drivers/auth/crypto_mod.h>
#include "event_handoff.h"
#include "tcg.h"
diff --git a/include/lib/libc/aarch32/inttypes_.h b/include/lib/libc/aarch32/inttypes_.h
new file mode 100644
index 0000000..0888bf0
--- /dev/null
+++ b/include/lib/libc/aarch32/inttypes_.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 Broadcom
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+/*
+ * Portions copyright (c) 2020, Arm Limited and Contributors.
+ * All rights reserved.
+ */
+
+#ifndef INTTYPES__H
+#define INTTYPES__H
+
+#define PRId64 "lld" /* int64_t */
+#define PRIi64 "lli" /* int64_t */
+#define PRIo64 "llo" /* int64_t */
+#define PRIu64 "llu" /* uint64_t */
+#define PRIx64 "llx" /* uint64_t */
+#define PRIX64 "llX" /* uint64_t */
+
+#define PRIdPTR "d" /* intptr_t */
+#define PRIiPTR "i" /* intptr_t */
+#define PRIoPTR "o" /* intptr_t */
+#define PRIuPTR "u" /* uintptr_t */
+#define PRIxPTR "x" /* uintptr_t */
+#define PRIXPTR "X" /* uintptr_t */
+
+#endif /* INTTYPES__H */
diff --git a/include/lib/libc/aarch64/inttypes_.h b/include/lib/libc/aarch64/inttypes_.h
new file mode 100644
index 0000000..6109084
--- /dev/null
+++ b/include/lib/libc/aarch64/inttypes_.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 Broadcom
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+/*
+ * Portions copyright (c) 2020, Arm Limited and Contributors.
+ * All rights reserved.
+ */
+
+#ifndef INTTYPES__H
+#define INTTYPES__H
+
+#define PRId64 "ld" /* int64_t */
+#define PRIi64 "li" /* int64_t */
+#define PRIo64 "lo" /* int64_t */
+#define PRIu64 "lu" /* uint64_t */
+#define PRIx64 "lx" /* uint64_t */
+#define PRIX64 "lX" /* uint64_t */
+
+#define PRIdPTR "ld" /* intptr_t */
+#define PRIiPTR "li" /* intptr_t */
+#define PRIoPTR "lo" /* intptr_t */
+#define PRIuPTR "lu" /* uintptr_t */
+#define PRIxPTR "lx" /* uintptr_t */
+#define PRIXPTR "lX" /* uintptr_t */
+
+#endif /* INTTYPES__H */
diff --git a/include/lib/libc/inttypes.h b/include/lib/libc/inttypes.h
new file mode 100644
index 0000000..344b71c
--- /dev/null
+++ b/include/lib/libc/inttypes.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 Broadcom
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+/*
+ * Portions copyright (c) 2020, Arm Limited and Contributors.
+ * All rights reserved.
+ */
+
+#ifndef INTTYPES_H
+#define INTTYPES_H
+
+#include <inttypes_.h>
+#include <stdint.h>
+
+#define PRId8 "d" /* int8_t */
+#define PRId16 "d" /* int16_t */
+#define PRId32 "d" /* int32_t */
+
+#define PRIi8 "i" /* int8_t */
+#define PRIi16 "i" /* int16_t */
+#define PRIi32 "i" /* int32_t */
+
+#define PRIo8 "o" /* int8_t */
+#define PRIo16 "o" /* int16_t */
+#define PRIo32 "o" /* int32_t */
+
+#define PRIu8 "u" /* uint8_t */
+#define PRIu16 "u" /* uint16_t */
+#define PRIu32 "u" /* uint32_t */
+
+#define PRIx8 "x" /* uint8_t */
+#define PRIx16 "x" /* uint16_t */
+#define PRIx32 "x" /* uint32_t */
+
+#define PRIX8 "X" /* uint8_t */
+#define PRIX16 "X" /* uint16_t */
+#define PRIX32 "X" /* uint32_t */
+
+#endif
diff --git a/include/lib/transfer_list.h b/include/lib/transfer_list.h
deleted file mode 100644
index eee2b82..0000000
--- a/include/lib/transfer_list.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2023, Linaro Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __TRANSFER_LIST_H
-#define __TRANSFER_LIST_H
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <lib/utils_def.h>
-
-#define TRANSFER_LIST_SIGNATURE U(0x4a0fb10b)
-#define TRANSFER_LIST_VERSION U(0x0001)
-
-// Init value of maximum alignment required by any TE data in the TL
-// specified as a power of two
-#define TRANSFER_LIST_INIT_MAX_ALIGN U(3)
-
-// alignment required by TE header start address, in bytes
-#define TRANSFER_LIST_GRANULE U(8)
-
-// version of the register convention used.
-// Set to 1 for both AArch64 and AArch32 according to fw handoff spec v0.9
-#define REGISTER_CONVENTION_VERSION_SHIFT_64 UL(32)
-#define REGISTER_CONVENTION_VERSION_SHIFT_32 UL(24)
-#define REGISTER_CONVENTION_VERSION_MASK UL(0xff)
-
-#define TRANSFER_LIST_HANDOFF_X1_VALUE(__version) \
- ((TRANSFER_LIST_SIGNATURE & \
- ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_64) - 1)) | \
- (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
- REGISTER_CONVENTION_VERSION_SHIFT_64))
-
-#define TRANSFER_LIST_HANDOFF_R1_VALUE(__version) \
- ((TRANSFER_LIST_SIGNATURE & \
- ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_32) - 1)) | \
- (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
- REGISTER_CONVENTION_VERSION_SHIFT_32))
-
-#ifndef __ASSEMBLER__
-
-enum transfer_list_tag_id {
- TL_TAG_EMPTY = 0,
- TL_TAG_FDT = 1,
- TL_TAG_HOB_BLOCK = 2,
- TL_TAG_HOB_LIST = 3,
- TL_TAG_ACPI_TABLE_AGGREGATE = 4,
- TL_TAG_TPM_EVLOG = 5,
-};
-
-enum transfer_list_ops {
- TL_OPS_NON, // invalid for any operation
- TL_OPS_ALL, // valid for all operations
-};
-
-struct transfer_list_header {
- uint32_t signature;
- uint8_t checksum;
- uint8_t version;
- uint8_t hdr_size;
- uint8_t alignment; // max alignment of TE data
- uint32_t size; // TL header + all TEs
- uint32_t max_size;
- /*
- * Commented out element used to visualize dynamic part of the
- * data structure.
- *
- * Note that struct transfer_list_entry also is dynamic in size
- * so the elements can't be indexed directly but instead must be
- * traversed in order
- *
- * struct transfer_list_entry entries[];
- */
-};
-
-struct transfer_list_entry {
- uint16_t tag_id;
- uint8_t reserved0; // place holder
- uint8_t hdr_size;
- uint32_t data_size;
- /*
- * Commented out element used to visualize dynamic part of the
- * data structure.
- *
- * Note that padding is added at the end of @data to make to reach
- * a 8-byte boundary.
- *
- * uint8_t data[ROUNDUP(data_size, 8)];
- */
-};
-
-struct transfer_list_entry *
-transfer_list_next(struct transfer_list_header *tl,
- struct transfer_list_entry *last);
-
-bool transfer_list_verify_checksum(const struct transfer_list_header *tl);
-
-void *transfer_list_entry_data(struct transfer_list_entry *entry);
-
-struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
- uint16_t tag_id);
-
-enum transfer_list_ops
-transfer_list_check_header(const struct transfer_list_header *tl);
-
-#endif /*__ASSEMBLER__*/
-#endif /*__TRANSFER_LIST_H*/
diff --git a/lib/libtl/libtl.mk b/lib/libtl/libtl.mk
new file mode 100644
index 0000000..4e685d2
--- /dev/null
+++ b/lib/libtl/libtl.mk
@@ -0,0 +1,15 @@
+#
+# Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+LIBTL_PATH ?= contrib/libtl
+
+INCLUDES += -I$(LIBTL_PATH)/include/ \
+ -I$(LIBTL_PATH)/include/private/
+
+LIBTL_SOURCES += $(addprefix ${LIBTL_PATH}/src/generic/, \
+ transfer_list.c \
+ logging.c \
+ )
diff --git a/lib/transfer_list/transfer_list.c b/lib/transfer_list/transfer_list.c
deleted file mode 100644
index 13ff6ff..0000000
--- a/lib/transfer_list/transfer_list.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <stddef.h>
-
-#include <transfer_list.h>
-
-/*******************************************************************************
- * Search for an existing transfer entry with the specified tag id from a
- * transfer list
- * Return pointer to the found transfer entry or NULL on error
- ******************************************************************************/
-struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
- uint16_t tag_id)
-{
- struct transfer_list_entry *te = NULL;
-
- do {
- te = transfer_list_next(tl, te);
- } while (te && (te->tag_id != tag_id));
-
- return te;
-}
-
-/*******************************************************************************
- * Enumerate the next transfer entry
- * Return pointer to the next transfer entry or NULL on error
- ******************************************************************************/
-struct transfer_list_entry *transfer_list_next(struct transfer_list_header *tl,
- struct transfer_list_entry *last)
-{
- struct transfer_list_entry *te = NULL;
- uintptr_t tl_ev = 0;
- uintptr_t va = 0;
- uintptr_t ev = 0;
- size_t sz = 0;
-
- if (!tl) {
- return NULL;
- }
-
- tl_ev = (uintptr_t)tl + tl->size;
-
- if (last) {
- va = (uintptr_t)last;
- /* check if the total size overflow */
- if (add_overflow(last->hdr_size, last->data_size, &sz)) {
- return NULL;
- }
- /* roundup to the next entry */
- if (add_with_round_up_overflow(va, sz, TRANSFER_LIST_GRANULE,
- &va)) {
- return NULL;
- }
- } else {
- va = (uintptr_t)tl + tl->hdr_size;
- }
-
- te = (struct transfer_list_entry *)va;
-
- if (va + sizeof(*te) > tl_ev || te->hdr_size < sizeof(*te) ||
- add_overflow(te->hdr_size, te->data_size, &sz) ||
- add_overflow(va, sz, &ev) || ev > tl_ev) {
- return NULL;
- }
-
- return te;
-}
-
-void *transfer_list_entry_data(struct transfer_list_entry *entry)
-{
- return (uint8_t *)entry + entry->hdr_size;
-}
-
-/*******************************************************************************
- * Verifying the header of a transfer list
- * Compliant to 2.4.1 of Firmware handoff specification (v0.9)
- * Return transfer list operation status code
- ******************************************************************************/
-enum transfer_list_ops
-transfer_list_check_header(const struct transfer_list_header *tl)
-{
- uint8_t byte_sum = 0U;
- uint8_t *b = (uint8_t *)tl;
-
- if (tl == NULL) {
- return TL_OPS_NON;
- }
-
- if (tl->signature != TRANSFER_LIST_SIGNATURE ||
- tl->size > tl->max_size) {
- return TL_OPS_NON;
- }
-
- for (size_t i = 0; i < tl->size; i++) {
- byte_sum += b[i];
- }
-
- if (byte_sum - tl->checksum == tl->checksum) {
- return TL_OPS_NON;
- }
-
- return TL_OPS_ALL;
-}
diff --git a/tftf/framework/framework.mk b/tftf/framework/framework.mk
index 098f2b8..24742a4 100644
--- a/tftf/framework/framework.mk
+++ b/tftf/framework/framework.mk
@@ -70,7 +70,6 @@
lib/smc/${ARCH}/smc.c \
lib/trng/trng.c \
lib/errata_abi/errata_abi.c \
- lib/transfer_list/transfer_list.c \
lib/trusted_os/trusted_os.c \
lib/utils/mp_printf.c \
lib/utils/uuid.c \
diff --git a/tftf/tests/tests-firmware-handoff.mk b/tftf/tests/tests-firmware-handoff.mk
index 65dfc4b..c7ca2cd 100644
--- a/tftf/tests/tests-firmware-handoff.mk
+++ b/tftf/tests/tests-firmware-handoff.mk
@@ -7,11 +7,12 @@
ifeq (${TRANSFER_LIST}, 1)
include lib/event_log/event_log.mk
+include lib/libtl/libtl.mk
TESTS_SOURCES += $(addprefix tftf/tests/misc_tests/, \
test_firmware_handoff.c \
)
-TESTS_SOURCES += ${EVENT_LOG_SOURCES}
+TESTS_SOURCES += ${EVENT_LOG_SOURCES} ${LIBTL_SOURCES}
endif