TPM 2.0中的tpm2_nvread命令对应的源文件就是tpm2_nvread.c,该文件位于tpm2-tools/tools/下,一共有444行(版本5.5)。
tpm2_nvread的功能是读取存储在非易失性(NV)索引中的数据。
下边用几篇文章的篇幅对tpm2_nvread.c文件结合tpm2_nvread命令进行深入的、完全的解析。
先来看第一段代码:
// Register this tool with tpm2_tool.c
TPM2_TOOL_REGISTER("nvread", tpm2_tool_onstart, tpm2_tool_onrun,
tpm2_tool_onstop, NULL)
TPM2_TOOL_REGISTER是一个宏定义,在tpm2-tools/tools/tpm2_tool.h中,代码如下:
#define TPM2_TOOL_REGISTER(tool_name,tool_onstart,tool_onrun,tool_onstop,tool_onexit) \
static const tpm2_tool tool = { \
.name = tool_name, \
.onstart = tool_onstart, \
.onrun = tool_onrun, \
.onstop = tool_onstop, \
.onexit = tool_onexit, \
}; \
static void \
__attribute__((__constru