From: Ahmad Fatoum <a.fatoum@pengutronix.de> To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>, barebox@lists.infradead.org Cc: rcz@pengutronix.de Subject: Re: [PATCH v2 3/3] imx-usb-loader: Add support for i.MX8MP Date: Wed, 27 Oct 2021 08:06:31 +0200 [thread overview] Message-ID: <d4c03100-bf4a-c691-26f7-6d325c0cb729@pengutronix.de> (raw) In-Reply-To: <20210813152245.15841-4-u.kleine-koenig@pengutronix.de> On 13.08.21 17:22, Uwe Kleine-König wrote: > The i.MX8MP uses a protocol similar to the MXS. The relevant differences > are: > > - Maximal transfer size is 1020 > - HID reports must be sent to EP1 instead of using a control transfer > - The FW_DOWNLOAD command must not be send. > - The image to upload must start with the IVT header (usually at offset > 0x8000), so the barebox header isn't transferred. > > Signed-off-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> With correct VID/PID added, this works on the i.MX8MN as well: Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > scripts/imx/imx-usb-loader.c | 80 +++++++++++++++++++++++++----------- > 1 file changed, 55 insertions(+), 25 deletions(-) > > diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c > index 3e96c86f2f29..cf87e0f91d65 100644 > --- a/scripts/imx/imx-usb-loader.c > +++ b/scripts/imx/imx-usb-loader.c > @@ -71,6 +71,7 @@ struct mach_id { > #define DEV_IMX 0 > #define DEV_MXS 1 > unsigned char dev_type; > + unsigned char hid_endpoint; > }; > > struct usb_work { > @@ -177,6 +178,14 @@ static const struct mach_id imx_ids[] = { > .header_type = HDR_MX53, > .mode = MODE_HID, > .max_transfer = 1024, > + }, { > + .vid = 0x1fc9, > + .pid = 0x0146, > + .name = "i.MX8MP", > + .header_type = HDR_MX53, > + .max_transfer = 1020, > + .dev_type = DEV_MXS, > + .hid_endpoint = 1, > }, { > .vid = 0x1fc9, > .pid = 0x012b, > @@ -522,15 +531,22 @@ static int transfer(int report, unsigned char *p, unsigned cnt, int *last_trans) > > if (report < 3) { > memcpy(&tmp[1], p, cnt); > - err = libusb_control_transfer(usb_dev_handle, > - CTRL_OUT, > - HID_SET_REPORT, > - (HID_REPORT_TYPE_OUTPUT << 8) | report, > - 0, > - tmp, cnt + 1, 1000); > - *last_trans = (err > 0) ? err - 1 : 0; > - if (err > 0) > - err = 0; > + if (mach_id->hid_endpoint) { > + int trans; > + err = libusb_interrupt_transfer(usb_dev_handle, > + mach_id->hid_endpoint, tmp, cnt + 1, &trans, 1000); > + *last_trans = trans - 1; > + } else { > + err = libusb_control_transfer(usb_dev_handle, > + CTRL_OUT, > + HID_SET_REPORT, > + (HID_REPORT_TYPE_OUTPUT << 8) | report, > + 0, > + tmp, cnt + 1, 1000); > + *last_trans = (err > 0) ? err - 1 : 0; > + if (err > 0) > + err = 0; > + } > } else { > *last_trans = 0; > memset(&tmp[1], 0, cnt); > @@ -1500,32 +1516,46 @@ static int write_mem(const struct config_data *data, uint32_t addr, > } > > /* MXS section */ > -static int mxs_load_file(libusb_device_handle *dev, uint8_t *data, int size) > +static int mxs_load_file(struct usb_work *curr, libusb_device_handle *dev, uint8_t *data, int size) > { > static struct mxs_command dl_command; > int last_trans, err; > void *p; > int cnt; > > - dl_command.sign = htonl(0x424c5443); /* Signature: BLTC */ > - dl_command.tag = htonl(0x1); > - dl_command.size = htonl(size); > - dl_command.flags = 0; > - dl_command.rsvd[0] = 0; > - dl_command.rsvd[1] = 0; > - dl_command.cmd = MXS_CMD_FW_DOWNLOAD; > - dl_command.dw_size = htonl(size); > - > - err = transfer(1, (unsigned char *) &dl_command, 20, &last_trans); > - if (err) { > - printf("transfer error at init step: err=%i, last_trans=%i\n", > - err, last_trans); > - return err; > + if (!mach_id->hid_endpoint) { > + dl_command.sign = htonl(0x424c5443); /* Signature: BLTC */ > + dl_command.tag = htonl(0x1); > + dl_command.size = htonl(size); > + dl_command.flags = 0; > + dl_command.rsvd[0] = 0; > + dl_command.rsvd[1] = 0; > + dl_command.cmd = MXS_CMD_FW_DOWNLOAD; > + dl_command.dw_size = htonl(size); > + > + err = transfer(1, (unsigned char *) &dl_command, 20, &last_trans); > + if (err) { > + printf("transfer error at init step: err=%i, last_trans=%i\n", > + err, last_trans); > + return err; > + } > } > > p = data; > cnt = size; > > + if (mach_id->header_type != HDR_NONE) { > + unsigned int dummy; > + err = process_header(curr, p, cnt, &dummy, &dummy, &dummy); > + if (err < 0) { > + printf("Failed to find IVT header\n"); > + return err; > + } > + > + p += err; > + cnt -= err; > + } > + > while (1) { > int now = get_min(cnt, mach_id->max_transfer); > > @@ -1555,7 +1585,7 @@ static int mxs_work(struct usb_work *curr) > if (ret < 0) > return ret; > > - return mxs_load_file(usb_dev_handle, buf, fsize); > + return mxs_load_file(curr, usb_dev_handle, buf, fsize); > } > /* end of mxs section */ > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-10-27 6:46 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-13 15:22 [PATCH v2 0/3] Support usb booting on i.MX8MP Uwe Kleine-König 2021-08-13 15:22 ` [PATCH v2 1/3] imx8mp-evk: Add support for booting via USB Uwe Kleine-König 2021-08-13 19:26 ` Ahmad Fatoum 2021-08-13 20:20 ` Lucas Stach 2021-08-13 20:48 ` Ahmad Fatoum 2021-10-26 16:30 ` Ahmad Fatoum 2021-08-13 15:22 ` [PATCH v2 2/3] imx-usb-loader: Drop nearly unused struct usb_id Uwe Kleine-König 2021-10-27 6:05 ` Ahmad Fatoum 2021-08-13 15:22 ` [PATCH v2 3/3] imx-usb-loader: Add support for i.MX8MP Uwe Kleine-König 2021-10-27 6:06 ` Ahmad Fatoum [this message] 2021-08-13 20:32 ` [PATCH v2 0/3] Support usb booting on i.MX8MP Lucas Stach 2021-10-13 19:33 ` Ahmad Fatoum
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d4c03100-bf4a-c691-26f7-6d325c0cb729@pengutronix.de \ --to=a.fatoum@pengutronix.de \ --cc=barebox@lists.infradead.org \ --cc=rcz@pengutronix.de \ --cc=u.kleine-koenig@pengutronix.de \ --subject='Re: [PATCH v2 3/3] imx-usb-loader: Add support for i.MX8MP' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox