Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2013 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/hab.h> |
| 10 | |
| 11 | /* -------- start of HAB API updates ------------*/ |
| 12 | #define hab_rvt_report_event ((hab_rvt_report_event_t *)HAB_RVT_REPORT_EVENT) |
| 13 | #define hab_rvt_report_status ((hab_rvt_report_status_t *)HAB_RVT_REPORT_STATUS) |
| 14 | #define hab_rvt_authenticate_image \ |
| 15 | ((hab_rvt_authenticate_image_t *)HAB_RVT_AUTHENTICATE_IMAGE) |
| 16 | #define hab_rvt_entry ((hab_rvt_entry_t *)HAB_RVT_ENTRY) |
| 17 | #define hab_rvt_exit ((hab_rvt_exit_t *)HAB_RVT_EXIT) |
| 18 | #define hab_rvt_clock_init HAB_RVT_CLOCK_INIT |
| 19 | |
| 20 | bool is_hab_enabled(void) |
| 21 | { |
| 22 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 23 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 24 | struct fuse_bank0_regs *fuse = |
| 25 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 26 | uint32_t reg = readl(&fuse->cfg5); |
| 27 | |
| 28 | return (reg & 0x2) == 0x2; |
| 29 | } |
| 30 | |
| 31 | void display_event(uint8_t *event_data, size_t bytes) |
| 32 | { |
| 33 | uint32_t i; |
| 34 | |
| 35 | if (!(event_data && bytes > 0)) |
| 36 | return; |
| 37 | |
| 38 | for (i = 0; i < bytes; i++) { |
| 39 | if (i == 0) |
| 40 | printf("\t0x%02x", event_data[i]); |
| 41 | else if ((i % 8) == 0) |
| 42 | printf("\n\t0x%02x", event_data[i]); |
| 43 | else |
| 44 | printf(" 0x%02x", event_data[i]); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | int get_hab_status(void) |
| 49 | { |
| 50 | uint32_t index = 0; /* Loop index */ |
| 51 | uint8_t event_data[128]; /* Event data buffer */ |
| 52 | size_t bytes = sizeof(event_data); /* Event size in bytes */ |
| 53 | enum hab_config config = 0; |
| 54 | enum hab_state state = 0; |
| 55 | |
| 56 | if (is_hab_enabled()) |
| 57 | puts("\nSecure boot enabled\n"); |
| 58 | else |
| 59 | puts("\nSecure boot disabled\n"); |
| 60 | |
| 61 | /* Check HAB status */ |
| 62 | if (hab_rvt_report_status(&config, &state) != HAB_SUCCESS) { |
| 63 | printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n", |
| 64 | config, state); |
| 65 | |
| 66 | /* Display HAB Error events */ |
| 67 | while (hab_rvt_report_event(HAB_FAILURE, index, event_data, |
| 68 | &bytes) == HAB_SUCCESS) { |
| 69 | puts("\n"); |
| 70 | printf("--------- HAB Event %d -----------------\n", |
| 71 | index + 1); |
| 72 | puts("event data:\n"); |
| 73 | display_event(event_data, bytes); |
| 74 | puts("\n"); |
| 75 | bytes = sizeof(event_data); |
| 76 | index++; |
| 77 | } |
| 78 | } |
| 79 | /* Display message if no HAB events are found */ |
| 80 | else { |
| 81 | printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n", |
| 82 | config, state); |
| 83 | puts("No HAB Events Found!\n\n"); |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | int do_hab_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 89 | { |
| 90 | if ((argc != 1)) { |
| 91 | cmd_usage(cmdtp); |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | get_hab_status(); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | U_BOOT_CMD( |
| 101 | hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status, |
| 102 | "display HAB status", |
| 103 | "" |
| 104 | ); |