U-Boot:尝试包含 TPM 头文件时出现编译错误
U-Boot: Compilation Error When Trying to include TPM Header Files
我正在尝试在 FIT 图像签名验证流程中使用几个 TPM V2 API。同样,我尝试以下列方式包含 TPM 头文件:
我在 Master Branch 工作。
diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index 63e5423c92..529da516cc 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -18,6 +18,9 @@ DECLARE_GLOBAL_DATA_PTR;
#include <u-boot/rsa.h>
#include <u-boot/hash-checksum.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+
#define IMAGE_MAX_HASHED_NODES 100
/**
但是,在编译时出现以下错误:
$ make -j$(nproc) CROSS_COMPILE=aarch64-linux-gnu- all
UPD include/generated/timestamp_autogenerated.h
CFGCHK u-boot.cfg
HOSTCC tools/aisimage.o
HOSTCC tools/atmelimage.o
HOSTCC tools/fit_image.o
HOSTCC tools/fit_common.o
HOSTCC tools/image-host.o
HOSTCC tools/common/image-fit.o
HOSTCC tools/image-sig-host.o
HOSTCC tools/common/image-fit-sig.o
HOSTCC tools/common/image-cipher.o
In file included from ./tools/../common/image-fit-sig.c:21,
from tools/common/image-fit-sig.c:1:
include/tpm-common.h:66:2: error: unknown type name ‘u8’
66 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
| ^~
include/tpm-common.h:66:34: error: ‘u8’ undeclared here (not in a function)
66 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
| ^~
include/tpm-common.h:131:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
131 | int (*send)(struct udevice *dev, const u8 *sendbuf, size_t send_size);
| ^
include/tpm-common.h:144:35: error: expected declaration specifiers or ‘...’ before ‘u8’
144 | int (*recv)(struct udevice *dev, u8 *recvbuf, size_t max_size);
| ^~
include/tpm-common.h:173:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
173 | int (*xfer)(struct udevice *dev, const u8 *sendbuf, size_t send_size,
| ^
include/tpm-common.h:259:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
259 | int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
| ^
In file included from ./tools/../common/image-fit-sig.c:22,
from tools/common/image-fit-sig.c:1:
include/tpm-v2.h:117:2: error: unknown type name ‘u16’
117 | u16 hash;
| ^~~
include/tpm-v2.h:118:2: error: expected specifier-qualifier-list before ‘u8’
118 | u8 size_of_select;
| ^~
include/tpm-v2.h:120:3: error: conflicting types for ‘__packed’
120 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:126:3: error: conflicting types for ‘__packed’
126 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:132:3: error: conflicting types for ‘__packed’
132 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:142:3: error: conflicting types for ‘__packed’
142 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:148:3: error: conflicting types for ‘__packed’
148 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:162:2: error: expected specifier-qualifier-list before ‘u8’
162 | u8 digest[TPM2_SHA1_DIGEST_SIZE];
| ^~
include/tpm-v2.h:165:3: error: conflicting types for ‘__packed’
165 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:171:2: error: expected specifier-qualifier-list before ‘u8’
171 | u8 sha1[TPM2_SHA1_DIGEST_SIZE];
| ^~
include/tpm-v2.h:176:3: error: conflicting types for ‘__packed’
176 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:185:2: error: unknown type name ‘u16’
185 | u16 hash_alg;
| ^~~
include/tpm-v2.h:187:3: error: conflicting types for ‘__packed’
187 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:198:3: error: conflicting types for ‘__packed’
198 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:214:2: error: expected specifier-qualifier-list before ‘u8’
214 | u8 event[];
| ^~
include/tpm-v2.h:215:3: error: conflicting types for ‘__packed’
215 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:469:14: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
469 | const u8 *nv_policy, size_t nv_policy_size);
| ^
include/tpm-v2.h:483:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
483 | const u8 *digest, u32 digest_len);
| ^
make[1]: *** [scripts/Makefile.host:112: tools/common/image-fit-sig.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1804: tools] Error 2
似乎可以通过添加 typedef 来规避 'u8' 和 'u16',但是我不确定 lib/tpm-v2.c 和 lib/tpm_api 这样的文件是如何规避的。 c 包含这些头文件而不会出现编译错误。
如果我在上述内容中遗漏了一些微不足道的东西,或者我该如何包含 tpm-v2 头文件,请告诉我?
common/image-fit-sig.c
等一些文件在 U-Boot 本身和我们的 runs-on-host 工具之间共享。在这些情况下,添加新代码/headers 时需要格外小心。您需要在文件顶部的非 USE_HOSTCC
情况下添加那些 headers,您的代码也需要放在后面和 #ifdef。
我正在尝试在 FIT 图像签名验证流程中使用几个 TPM V2 API。同样,我尝试以下列方式包含 TPM 头文件: 我在 Master Branch 工作。
diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index 63e5423c92..529da516cc 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -18,6 +18,9 @@ DECLARE_GLOBAL_DATA_PTR;
#include <u-boot/rsa.h>
#include <u-boot/hash-checksum.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+
#define IMAGE_MAX_HASHED_NODES 100
/**
但是,在编译时出现以下错误:
$ make -j$(nproc) CROSS_COMPILE=aarch64-linux-gnu- all
UPD include/generated/timestamp_autogenerated.h
CFGCHK u-boot.cfg
HOSTCC tools/aisimage.o
HOSTCC tools/atmelimage.o
HOSTCC tools/fit_image.o
HOSTCC tools/fit_common.o
HOSTCC tools/image-host.o
HOSTCC tools/common/image-fit.o
HOSTCC tools/image-sig-host.o
HOSTCC tools/common/image-fit-sig.o
HOSTCC tools/common/image-cipher.o
In file included from ./tools/../common/image-fit-sig.c:21,
from tools/common/image-fit-sig.c:1:
include/tpm-common.h:66:2: error: unknown type name ‘u8’
66 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
| ^~
include/tpm-common.h:66:34: error: ‘u8’ undeclared here (not in a function)
66 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
| ^~
include/tpm-common.h:131:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
131 | int (*send)(struct udevice *dev, const u8 *sendbuf, size_t send_size);
| ^
include/tpm-common.h:144:35: error: expected declaration specifiers or ‘...’ before ‘u8’
144 | int (*recv)(struct udevice *dev, u8 *recvbuf, size_t max_size);
| ^~
include/tpm-common.h:173:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
173 | int (*xfer)(struct udevice *dev, const u8 *sendbuf, size_t send_size,
| ^
include/tpm-common.h:259:44: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
259 | int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
| ^
In file included from ./tools/../common/image-fit-sig.c:22,
from tools/common/image-fit-sig.c:1:
include/tpm-v2.h:117:2: error: unknown type name ‘u16’
117 | u16 hash;
| ^~~
include/tpm-v2.h:118:2: error: expected specifier-qualifier-list before ‘u8’
118 | u8 size_of_select;
| ^~
include/tpm-v2.h:120:3: error: conflicting types for ‘__packed’
120 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:126:3: error: conflicting types for ‘__packed’
126 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:132:3: error: conflicting types for ‘__packed’
132 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:142:3: error: conflicting types for ‘__packed’
142 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:148:3: error: conflicting types for ‘__packed’
148 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:162:2: error: expected specifier-qualifier-list before ‘u8’
162 | u8 digest[TPM2_SHA1_DIGEST_SIZE];
| ^~
include/tpm-v2.h:165:3: error: conflicting types for ‘__packed’
165 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:171:2: error: expected specifier-qualifier-list before ‘u8’
171 | u8 sha1[TPM2_SHA1_DIGEST_SIZE];
| ^~
include/tpm-v2.h:176:3: error: conflicting types for ‘__packed’
176 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:185:2: error: unknown type name ‘u16’
185 | u16 hash_alg;
| ^~~
include/tpm-v2.h:187:3: error: conflicting types for ‘__packed’
187 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:198:3: error: conflicting types for ‘__packed’
198 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:214:2: error: expected specifier-qualifier-list before ‘u8’
214 | u8 event[];
| ^~
include/tpm-v2.h:215:3: error: conflicting types for ‘__packed’
215 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:113:3: note: previous declaration of ‘__packed’ was here
113 | } __packed;
| ^~~~~~~~
include/tpm-v2.h:469:14: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
469 | const u8 *nv_policy, size_t nv_policy_size);
| ^
include/tpm-v2.h:483:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
483 | const u8 *digest, u32 digest_len);
| ^
make[1]: *** [scripts/Makefile.host:112: tools/common/image-fit-sig.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1804: tools] Error 2
似乎可以通过添加 typedef 来规避 'u8' 和 'u16',但是我不确定 lib/tpm-v2.c 和 lib/tpm_api 这样的文件是如何规避的。 c 包含这些头文件而不会出现编译错误。
如果我在上述内容中遗漏了一些微不足道的东西,或者我该如何包含 tpm-v2 头文件,请告诉我?
common/image-fit-sig.c
等一些文件在 U-Boot 本身和我们的 runs-on-host 工具之间共享。在这些情况下,添加新代码/headers 时需要格外小心。您需要在文件顶部的非 USE_HOSTCC
情况下添加那些 headers,您的代码也需要放在后面和 #ifdef。