diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-18 08:48:16 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-18 08:48:16 +0100 |
commit | fcad6e3394943e32bc9e08d971f2c6511a99a151 (patch) | |
tree | f8f4ad6996ef81492d49c36273ef78aac75bd781 /scripts | |
parent | 394b88e6872c607e5317cf57c61c641288555311 (diff) | |
parent | e6e12e9368f730d5e50c9495c2332abe2ad6abf0 (diff) | |
download | barebox-fcad6e3394943e32bc9e08d971f2c6511a99a151.tar.gz barebox-fcad6e3394943e32bc9e08d971f2c6511a99a151.tar.xz |
Merge branch 'for-next/imx'
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/imx/imx-image.c | 11 | ||||
-rw-r--r-- | scripts/imx/imx-usb-loader.c | 56 | ||||
-rw-r--r-- | scripts/imx/imx.c | 4 | ||||
-rw-r--r-- | scripts/imx/imx.h | 6 |
4 files changed, 64 insertions, 13 deletions
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c index a9323f8ba3..c39ceda839 100644 --- a/scripts/imx/imx-image.c +++ b/scripts/imx/imx-image.c @@ -28,7 +28,6 @@ #include <fcntl.h> #include <linux/kernel.h> #include <sys/file.h> -#include <mach/imx_cpu_types.h> #include "../compiler.h" #include "imx.h" @@ -701,9 +700,9 @@ static int hab_sign(struct config_data *data) } /* - * For i.MX8, write into the reserved CSF section + * For i.MX8M, write into the reserved CSF section */ - if (data->cpu_type == IMX_CPU_IMX8MQ) + if (cpu_is_mx8m(data)) outfd = open(data->outfile, O_WRONLY); else outfd = open(data->outfile, O_WRONLY | O_APPEND); @@ -714,7 +713,7 @@ static int hab_sign(struct config_data *data) exit(1); } - if (data->cpu_type == IMX_CPU_IMX8MQ) { + if (cpu_is_mx8m(data)) { /* * For i.MX8 insert the CSF data into the reserved CSF area * right behind the PBL @@ -779,7 +778,7 @@ static void *xread_file(const char *filename, size_t *size) static bool cpu_is_aarch64(const struct config_data *data) { - return data->cpu_type == IMX_CPU_IMX8MQ; + return cpu_is_mx8m(data); } int main(int argc, char *argv[]) @@ -886,7 +885,7 @@ int main(int argc, char *argv[]) exit(1); if (data.max_load_size && (data.encrypt_image || data.csf) - && data.cpu_type != IMX_CPU_IMX8MQ) { + && !cpu_is_mx8m(&data)) { fprintf(stderr, "Specifying max_load_size is incompatible with HAB signing/encrypting\n"); exit(1); } diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c index 08affe72c7..8447ca2a8f 100644 --- a/scripts/imx/imx-usb-loader.c +++ b/scripts/imx/imx-usb-loader.c @@ -187,7 +187,14 @@ static const struct mach_id imx_ids[] = { }, { .vid = 0x1fc9, .pid = 0x012b, - .name = "i.MX8M", + .name = "i.MX8MQ", + .header_type = HDR_MX53, + .mode = MODE_HID, + .max_transfer = 1024, + }, { + .vid = 0x1fc9, + .pid = 0x0134, + .name = "i.MX8MM", .header_type = HDR_MX53, .mode = MODE_HID, .max_transfer = 1024, @@ -763,7 +770,8 @@ static int modify_memory(unsigned addr, unsigned val, int width, int set_bits, i return write_memory(addr, val, 4); } -static int load_file(void *buf, unsigned len, unsigned dladdr, unsigned char type) +static int load_file(void *buf, unsigned len, unsigned dladdr, + unsigned char type, bool mode_barebox) { static struct sdp_command dl_command = { .cmd = SDP_WRITE_FILE, @@ -828,6 +836,9 @@ static int load_file(void *buf, unsigned len, unsigned dladdr, unsigned char typ cnt -= now; } + if (mode_barebox) + return transfer_size; + if (usb_id->mach_id->mode == MODE_HID) { err = transfer(3, tmp, sizeof(tmp), &last_trans); if (err) @@ -1300,12 +1311,28 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start, return 0; } +static int get_payload_start(const unsigned char *p, uint32_t *ofs) +{ + struct imx_flash_header_v2 *hdr = (struct imx_flash_header_v2 *)p; + + switch (usb_id->mach_id->header_type) { + case HDR_MX51: + return -EINVAL; + + case HDR_MX53: + *ofs = hdr->entry - hdr->self; + return 0; + } + + return -EINVAL; +} + static int process_header(struct usb_work *curr, unsigned char *buf, int cnt, unsigned *p_max_length, unsigned *p_plugin, unsigned *p_header_addr) { int ret; - unsigned header_max = 0x800; + unsigned header_max = 0x10000; unsigned header_inc = 0x400; unsigned header_offset = 0; int header_cnt = 0; @@ -1362,6 +1389,7 @@ static int do_irom_download(struct usb_work *curr, int verify) unsigned max_length; unsigned plugin = 0; unsigned header_addr = 0; + unsigned total_size = 0; ret = read_file(curr->filename, &buf, &fsize); if (ret < 0) @@ -1384,6 +1412,11 @@ static int do_irom_download(struct usb_work *curr, int verify) image = buf + header_offset; fsize -= header_offset; + if (fsize > max_length) { + total_size = fsize; + fsize = max_length; + } + type = FT_APP; if (verify) { @@ -1406,7 +1439,7 @@ static int do_irom_download(struct usb_work *curr, int verify) printf("loading binary file(%s) to 0x%08x, fsize=%u type=%d...\n", curr->filename, header_addr, fsize, type); - ret = load_file(image, fsize, header_addr, type); + ret = load_file(image, fsize, header_addr, type, false); if (ret < 0) goto cleanup; @@ -1429,7 +1462,7 @@ static int do_irom_download(struct usb_work *curr, int verify) * so we load part of the image again with type FT_APP * this time. */ - ret = load_file(verify_buffer, 64, header_addr, FT_APP); + ret = load_file(verify_buffer, 64, header_addr, FT_APP, false); if (ret < 0) goto cleanup; @@ -1444,6 +1477,19 @@ static int do_irom_download(struct usb_work *curr, int verify) return ret; } + if (total_size) { + uint32_t ofs; + + ret = get_payload_start(image, &ofs); + if (ret) { + printf("Cannot get offset of payload\n"); + goto cleanup; + } + printf("Loading full image\n"); + printf("Note: This needs board support on the other end\n"); + load_file(image + ofs, total_size - ofs, 0, 0, true); + } + ret = 0; cleanup: free(verify_buffer); diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c index 980173950f..c820c9a0c8 100644 --- a/scripts/imx/imx.c +++ b/scripts/imx/imx.c @@ -24,7 +24,6 @@ #include <errno.h> #include <sys/stat.h> #include <linux/kernel.h> -#include <mach/imx_cpu_types.h> #include "imx.h" @@ -243,6 +242,7 @@ static struct soc_type socs[] = { { .name = "imx53", .header_version = 2, .cpu_type = IMX_CPU_IMX53, .header_gap = 0, .first_opcode = 0xea0003fe /* b 0x1000 */}, { .name = "imx6", .header_version = 2, .cpu_type = IMX_CPU_IMX6, .header_gap = 0, .first_opcode = 0xea0003fe /* b 0x1000 */}, { .name = "imx7", .header_version = 2, .cpu_type = IMX_CPU_IMX7, .header_gap = 0, .first_opcode = 0xea0003fe /* b 0x1000 */}, + { .name = "imx8mm", .header_version = 2, .cpu_type = IMX_CPU_IMX8MM, .header_gap = SZ_32K, .first_opcode = 0x14000000 /* b 0x0000 (offset computed) */}, { .name = "imx8mq", .header_version = 2, .cpu_type = IMX_CPU_IMX8MQ, .header_gap = SZ_32K, .first_opcode = 0x14000000 /* b 0x0000 (offset computed) */}, { .name = "vf610", .header_version = 2, .cpu_type = IMX_CPU_VF610, .header_gap = 0, .first_opcode = 0xea0003fe /* b 0x1000 */}, }; @@ -352,7 +352,7 @@ static int do_hab_blocks(struct config_data *data, int argc, char *argv[]) /* * Ensure we only sign the PBL for i.MX8MQ */ - if (data->pbl_code_size && data->cpu_type == IMX_CPU_IMX8MQ) { + if (data->pbl_code_size && cpu_is_mx8m(data)) { offset += data->header_gap; signed_size = roundup(data->pbl_code_size + HEADER_LEN, 0x1000); if (data->signed_hdmi_firmware_file) diff --git a/scripts/imx/imx.h b/scripts/imx/imx.h index 20fb1e876e..d466e5dad0 100644 --- a/scripts/imx/imx.h +++ b/scripts/imx/imx.h @@ -1,4 +1,10 @@ #include <mach/imx-header.h> +#include <mach/imx_cpu_types.h> + +static inline int cpu_is_mx8m(const struct config_data *data) +{ + return data->cpu_type == IMX_CPU_IMX8MQ || data->cpu_type == IMX_CPU_IMX8MM; +} int parse_config(struct config_data *data, const char *filename); |