Skip to contentSkip to conversation

board: zynqmp: add cmd for getting boot auth state

PATCH Superseded Neal Frager 2 participants 2 messages Jan 6 Arm/Zynq architecture

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board: zynqmp: add cmd for getting boot auth state

Add command for checking if boot was authenticated.

---
 board/xilinx/zynqmp/zynqmp.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
board/xilinx/zynqmp/zynqmp.c +38 -0
index 3b28ba62374..92351aca36c 100644
@@ -149,6 +149,44 @@ static void print_secure_boot(void)
 	       status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
 }
 
+static bool is_boot_authenticated(void)
+{
+	u32 status = 0;
+	int ret;
+
+	ret = zynqmp_mmio_read((ulong)&csu_base->status, &status);
+	if (ret) {
+		printf("Can't obtain boot auth state");
+		return false;
+	}
+
+	return (status & BIT(0));
+}
+
+static int do_is_boot_authenticated(struct cmd_tbl *cmdtp, int flag,
+				    int argc, char * const argv[])
+{
+	int ret;
+
+	if (is_boot_authenticated()) {
+		printf("Board is in closed state\n");
+
+		ret = env_set("board_is_closed", "1");
+		if (ret)
+			return CMD_RET_FAILURE;
+	} else {
+		printf("Board is in open state\n");
+	}
+
+	return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+	is_boot_authenticated, CONFIG_SYS_MAXARGS, 1,
+	do_is_boot_authenticated,
+	"Check if the board is authenticated", ""
+);
+
 int board_init(void)
 {
 #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 29 lines · Neal Frager

Add command for checking if boot was authenticated.

---
  board/xilinx/zynqmp/zynqmp.c | 38 ++++++++++++++++++++++++++++++++++++
  1 file changed, 38 insertions(+)
board/xilinx/zynqmp/zynqmp.c +13 -0
index 3b28ba62374..92351aca36c 100644
@@ -149,6 +149,44 @@ static void print_secure_boot(void)
  	       status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
  }
 
+static bool is_boot_authenticated(void)
+{
+	u32 status = 0;
+	int ret;
+
+	ret = zynqmp_mmio_read((ulong)&csu_base->status, &status);
+	if (ret) {
+		printf("Can't obtain boot auth state");
+		return false;
+	}
+
+	return (status & BIT(0));
+}

board/xilinx/zynqmp/zynqmp.c static void print_secure_boot(void) · line 174

Quoted 10 lines
board/xilinx/zynqmp/zynqmp.c +10 -0
+
+static int do_is_boot_authenticated(struct cmd_tbl *cmdtp, int flag,
+				    int argc, char * const argv[])
+{
+	int ret;
+
+	if (is_boot_authenticated()) {
+		printf("Board is in closed state\n");
+
+		ret = env_set("board_is_closed", "1");

I don't think we should create variable in this form.

Quoted 4 lines
board/xilinx/zynqmp/zynqmp.c +4 -0
+		if (ret)
+			return CMD_RET_FAILURE;
+	} else {
+		printf("Board is in open state\n");

board/xilinx/zynqmp/zynqmp.c static void print_secure_boot(void) · line 188

Quoted 10 lines
board/xilinx/zynqmp/zynqmp.c +10 -0
+	}
+
+	return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+	is_boot_authenticated, CONFIG_SYS_MAXARGS, 1,
+	do_is_boot_authenticated,
+	"Check if the board is authenticated", ""
+);

Also having this high level command doesn't look good.

You should extend
arch/arm/mach-zynqmp/zynqmp.c

and create new command there and return 0 or 1 based on status. Then you can use it in scripts without creating variable. Or obviously you can create variable when command pass/failed.

zynqmp is_boot_authenticated || setenv whatever

M