1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2020 Broadcom
9 #define FW_IMAGE_SIG 0xff123456
10 #define CFG_IMAGE_SIG 0xcf54321a
13 * structure for bin file
14 * signature: fw itb file
16 * signature: NS3 config file
17 * size: NS3 config file
19 * ............................
20 * ............................
21 * Data: NS3 config file
22 * ............................
23 * ............................
26 static struct img_header {
33 static int env_set_val(const char *varname, ulong val)
37 ret = env_set_hex(varname, val);
39 pr_err("Failed to %s env var\n", varname);
44 static int do_spi_images_addr(struct cmd_tbl *cmdtp, int flag, int argc,
47 uintptr_t images_load_addr;
48 uintptr_t spi_load_addr;
50 u32 spi_data_offset = sizeof(struct img_header);
55 /* convert command parameter to fastboot address (base 16), i.e. hex */
56 images_load_addr = hextoul(argv[1], NULL);
57 if (!images_load_addr) {
58 pr_err("Invalid load address\n");
62 spi_load_addr = hextoul(argv[2], NULL);
64 pr_err("Invalid spi load address\n");
68 img_header = (struct img_header *)images_load_addr;
70 if (img_header->bin_sig != FW_IMAGE_SIG) {
71 pr_err("Invalid Nitro bin file\n");
75 if (env_set_val("spi_nitro_fw_itb_start_addr", 0))
78 if (env_set_val("spi_nitro_fw_itb_len", 0))
81 if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr", 0))
84 if (env_set_val("spi_nitro_fw_ns3_cfg_len", 0))
87 len = img_header->bin_size;
89 if (env_set_val("spi_nitro_fw_itb_start_addr",
90 (spi_load_addr + spi_data_offset)))
93 if (env_set_val("spi_nitro_fw_itb_len", img_header->bin_size))
96 spi_data_offset += len;
98 if (img_header->cfg1_sig == CFG_IMAGE_SIG) {
99 len = img_header->cfg1_size;
101 if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr",
102 (spi_load_addr + spi_data_offset)))
105 if (env_set_val("spi_nitro_fw_ns3_cfg_len", len))
108 spi_data_offset += len;
111 /* disable secure boot */
112 if (env_set_val("nitro_fastboot_secure", 0))
115 return CMD_RET_SUCCESS;
118 return CMD_RET_FAILURE;
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"