Vikas Gupta | 70bf263 | 2020-08-20 20:41:05 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 Broadcom |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | |
| 9 | #define FW_IMAGE_SIG 0xff123456 |
| 10 | #define CFG_IMAGE_SIG 0xcf54321a |
| 11 | |
| 12 | /* |
| 13 | * structure for bin file |
| 14 | * signature: fw itb file |
| 15 | * size: fw itb file |
| 16 | * signature: NS3 config file |
| 17 | * size: NS3 config file |
| 18 | * Data: fw itb file |
| 19 | * ............................ |
| 20 | * ............................ |
| 21 | * Data: NS3 config file |
| 22 | * ............................ |
| 23 | * ............................ |
| 24 | */ |
| 25 | |
| 26 | static struct img_header { |
| 27 | u32 bin_sig; |
| 28 | u32 bin_size; |
| 29 | u32 cfg1_sig; |
| 30 | u32 cfg1_size; |
| 31 | } *img_header; |
| 32 | |
| 33 | static int env_set_val(const char *varname, ulong val) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | ret = env_set_hex(varname, val); |
| 38 | if (ret) |
| 39 | pr_err("Failed to %s env var\n", varname); |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int do_spi_images_addr(struct cmd_tbl *cmdtp, int flag, int argc, |
| 45 | char *const argv[]) |
| 46 | { |
| 47 | uintptr_t images_load_addr; |
| 48 | uintptr_t spi_load_addr; |
| 49 | u32 len; |
| 50 | u32 spi_data_offset = sizeof(struct img_header); |
| 51 | |
| 52 | if (argc != 3) |
| 53 | return CMD_RET_USAGE; |
| 54 | |
| 55 | /* convert command parameter to fastboot address (base 16), i.e. hex */ |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 56 | images_load_addr = hextoul(argv[1], NULL); |
Vikas Gupta | 70bf263 | 2020-08-20 20:41:05 +0530 | [diff] [blame] | 57 | if (!images_load_addr) { |
| 58 | pr_err("Invalid load address\n"); |
| 59 | return CMD_RET_USAGE; |
| 60 | } |
| 61 | |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 62 | spi_load_addr = hextoul(argv[2], NULL); |
Vikas Gupta | 70bf263 | 2020-08-20 20:41:05 +0530 | [diff] [blame] | 63 | if (!spi_load_addr) { |
| 64 | pr_err("Invalid spi load address\n"); |
| 65 | return CMD_RET_USAGE; |
| 66 | } |
| 67 | |
| 68 | img_header = (struct img_header *)images_load_addr; |
| 69 | |
| 70 | if (img_header->bin_sig != FW_IMAGE_SIG) { |
| 71 | pr_err("Invalid Nitro bin file\n"); |
| 72 | goto error; |
| 73 | } |
| 74 | |
| 75 | if (env_set_val("spi_nitro_fw_itb_start_addr", 0)) |
| 76 | goto error; |
| 77 | |
| 78 | if (env_set_val("spi_nitro_fw_itb_len", 0)) |
| 79 | goto error; |
| 80 | |
| 81 | if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr", 0)) |
| 82 | goto error; |
| 83 | |
| 84 | if (env_set_val("spi_nitro_fw_ns3_cfg_len", 0)) |
| 85 | goto error; |
| 86 | |
| 87 | len = img_header->bin_size; |
| 88 | |
| 89 | if (env_set_val("spi_nitro_fw_itb_start_addr", |
| 90 | (spi_load_addr + spi_data_offset))) |
| 91 | goto error; |
| 92 | |
| 93 | if (env_set_val("spi_nitro_fw_itb_len", img_header->bin_size)) |
| 94 | goto error; |
| 95 | |
| 96 | spi_data_offset += len; |
| 97 | |
| 98 | if (img_header->cfg1_sig == CFG_IMAGE_SIG) { |
| 99 | len = img_header->cfg1_size; |
| 100 | |
| 101 | if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr", |
| 102 | (spi_load_addr + spi_data_offset))) |
| 103 | goto error; |
| 104 | |
| 105 | if (env_set_val("spi_nitro_fw_ns3_cfg_len", len)) |
| 106 | goto error; |
| 107 | |
| 108 | spi_data_offset += len; |
| 109 | } |
| 110 | |
| 111 | /* disable secure boot */ |
| 112 | if (env_set_val("nitro_fastboot_secure", 0)) |
| 113 | goto error; |
| 114 | |
| 115 | return CMD_RET_SUCCESS; |
| 116 | |
| 117 | error: |
| 118 | return CMD_RET_FAILURE; |
| 119 | } |
| 120 | |
| 121 | U_BOOT_CMD |
| 122 | (spi_nitro_images_addr, 3, 1, do_spi_images_addr, |
| 123 | "Load the bnxt bin header and sets envs ", |
| 124 | "spi_nitro_images_addr <load_addr> <spi_base_addr>\n" |
| 125 | ); |