| 1 | From: Vagrant Cascadian <[email protected]>
|
| 2 | Date: Fri, 22 Oct 2021 17:34:53 -0700
|
| 3 | Subject: [PATCH] Revert "tools: kwbimage: Do not hide usage of secure header
|
| 4 | under CONFIG_ARMADA_38X"
|
| 5 |
|
| 6 | This reverts commit b4f3cc2c42d97967a3a3c8796c340f6b07ecccac.
|
| 7 |
|
| 8 | Addendum 2022-12-08, Ricardo Wurmus: This patch has been updated to introduce
|
| 9 | CONFIG_FIT_PRELOAD to remove fit_pre_load_data, which depends on openssl.
|
| 10 |
|
| 11 | Addendum 2024-01-18, Herman Rimm: Patch updated to leave out upstreamed
|
| 12 | diffs with CONFIG_FIT_PRELOAD.
|
| 13 | ---
|
| 14 | Fixes build of U-Boot v2021.10 without openssl. See:
|
| 15 | https://lists.denx.de/pipermail/u-boot/2021-October/462728.html
|
| 16 |
|
| 17 | diff --git a/tools/kwbimage.c b/tools/kwbimage.c
|
| 18 | index 4dce495ff0..976174ae77 100644
|
| 19 | |
| 20 | |
| 21 | @@ -19,6 +19,7 @@
|
| 22 | #include <stdint.h>
|
| 23 | #include "kwbimage.h"
|
| 24 |
|
| 25 | +#ifdef CONFIG_KWB_SECURE
|
| 26 | #include <openssl/bn.h>
|
| 27 | #include <openssl/rsa.h>
|
| 28 | #include <openssl/pem.h>
|
| 29 | @@ -44,6 +45,7 @@ void EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
|
| 30 | EVP_MD_CTX_reset(ctx);
|
| 31 | }
|
| 32 | #endif
|
| 33 | +#endif
|
| 34 |
|
| 35 | /* fls - find last (most-significant) bit set in 4-bit integer */
|
| 36 | static inline int fls4(int num)
|
| 37 | @@ -62,7 +64,9 @@ static inline int fls4(int num)
|
| 38 |
|
| 39 | static struct image_cfg_element *image_cfg;
|
| 40 | static int cfgn;
|
| 41 | +#ifdef CONFIG_KWB_SECURE
|
| 42 | static int verbose_mode;
|
| 43 | +#endif
|
| 44 |
|
| 45 | struct boot_mode {
|
| 46 | unsigned int id;
|
| 47 | @@ -281,6 +285,8 @@ image_count_options(unsigned int optiontype)
|
| 48 | return count;
|
| 49 | }
|
| 50 |
|
| 51 | +#if defined(CONFIG_KWB_SECURE)
|
| 52 | +
|
| 53 | static int image_get_csk_index(void)
|
| 54 | {
|
| 55 | struct image_cfg_element *e;
|
| 56 | @@ -291,6 +297,7 @@ static int image_get_csk_index(void)
|
| 57 |
|
| 58 | return e->csk_idx;
|
| 59 | }
|
| 60 | +#endif
|
| 61 |
|
| 62 | static bool image_get_spezialized_img(void)
|
| 63 | {
|
| 64 | @@ -435,6 +442,7 @@ static uint8_t baudrate_to_option(unsigned int baudrate)
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | +#if defined(CONFIG_KWB_SECURE)
|
| 69 | static void kwb_msg(const char *fmt, ...)
|
| 70 | {
|
| 71 | if (verbose_mode) {
|
| 72 | @@ -929,6 +937,7 @@ static int kwb_dump_fuse_cmds(struct secure_hdr_v1 *sec_hdr)
|
| 73 | done:
|
| 74 | return ret;
|
| 75 | }
|
| 76 | +#endif
|
| 77 |
|
| 78 | static int image_fill_xip_header(void *image, struct image_tool_params *params)
|
| 79 | {
|
| 80 | @@ -1149,13 +1158,13 @@ static size_t image_headersz_v1(int *hasext)
|
| 81 | int ret;
|
| 82 |
|
| 83 | headersz = sizeof(struct main_hdr_v1);
|
| 84 | -
|
| 85 | +#if defined(CONFIG_KWB_SECURE)
|
| 86 | if (image_get_csk_index() >= 0) {
|
| 87 | headersz += sizeof(struct secure_hdr_v1);
|
| 88 | if (hasext)
|
| 89 | *hasext = 1;
|
| 90 | }
|
| 91 | -
|
| 92 | +#endif
|
| 93 | cpu_sheeva = image_is_cpu_sheeva();
|
| 94 |
|
| 95 | count = 0;
|
| 96 | @@ -1351,6 +1360,7 @@ err_close:
|
| 97 | return -1;
|
| 98 | }
|
| 99 |
|
| 100 | +#if defined(CONFIG_KWB_SECURE)
|
| 101 | static int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr)
|
| 102 | {
|
| 103 | FILE *hashf;
|
| 104 | @@ -1458,6 +1468,7 @@ static int add_secure_header_v1(struct image_tool_params *params, uint8_t *image
|
| 105 |
|
| 106 | return 0;
|
| 107 | }
|
| 108 | +#endif
|
| 109 |
|
| 110 | static void finish_register_set_header_v1(uint8_t **cur, uint8_t **next_ext,
|
| 111 | struct register_set_hdr_v1 *register_set_hdr,
|
| 112 | @@ -1481,7 +1492,9 @@ static void *image_create_v1(size_t *dataoff, struct image_tool_params *params,
|
| 113 | struct image_cfg_element *e;
|
| 114 | struct main_hdr_v1 *main_hdr;
|
| 115 | struct register_set_hdr_v1 *register_set_hdr;
|
| 116 | +#if defined(CONFIG_KWB_SECURE)
|
| 117 | struct secure_hdr_v1 *secure_hdr = NULL;
|
| 118 | +#endif
|
| 119 | size_t headersz;
|
| 120 | uint8_t *image, *cur;
|
| 121 | int hasext = 0;
|
| 122 | @@ -1562,7 +1575,7 @@ static void *image_create_v1(size_t *dataoff, struct image_tool_params *params,
|
| 123 | }
|
| 124 | *dataoff = le32_to_cpu(main_hdr->srcaddr);
|
| 125 | }
|
| 126 | -
|
| 127 | +#if defined(CONFIG_KWB_SECURE)
|
| 128 | if (image_get_csk_index() >= 0) {
|
| 129 | /*
|
| 130 | * only reserve the space here; we fill the header later since
|
| 131 | @@ -1573,7 +1586,7 @@ static void *image_create_v1(size_t *dataoff, struct image_tool_params *params,
|
| 132 | *next_ext = 1;
|
| 133 | next_ext = &secure_hdr->next;
|
| 134 | }
|
| 135 | -
|
| 136 | +#endif
|
| 137 | datai = 0;
|
| 138 | for (cfgi = 0; cfgi < cfgn; cfgi++) {
|
| 139 | e = &image_cfg[cfgi];
|
| 140 | @@ -1624,9 +1637,11 @@ static void *image_create_v1(size_t *dataoff, struct image_tool_params *params,
|
| 141 | &datai, delay);
|
| 142 | }
|
| 143 |
|
| 144 | +#if defined(CONFIG_KWB_SECURE)
|
| 145 | if (secure_hdr && add_secure_header_v1(params, ptr + *dataoff, payloadsz,
|
| 146 | image, headersz, secure_hdr))
|
| 147 | return NULL;
|
| 148 | +#endif
|
| 149 |
|
| 150 | /* Calculate and set the header checksum */
|
| 151 | main_hdr->checksum = image_checksum8(main_hdr, headersz);
|