From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de> To: barebox@lists.infradead.org Cc: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>, rcz@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de> Subject: [PATCH v2 2/3] imx-usb-loader: Drop nearly unused struct usb_id Date: Fri, 13 Aug 2021 17:22:44 +0200 [thread overview] Message-ID: <20210813152245.15841-3-u.kleine-koenig@pengutronix.de> (raw) In-Reply-To: <20210813152245.15841-1-u.kleine-koenig@pengutronix.de> Only one of the two members of struct usb_id is actually used. So replace struct usb_id by a struct mach_id. Signed-off-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> --- scripts/imx/imx-usb-loader.c | 51 ++++++++++++------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c index cff77f27f264..3e96c86f2f29 100644 --- a/scripts/imx/imx-usb-loader.c +++ b/scripts/imx/imx-usb-loader.c @@ -52,7 +52,7 @@ int verbose; static struct libusb_device_handle *usb_dev_handle; -static struct usb_id *usb_id; +static const struct mach_id *mach_id; struct mach_id { struct mach_id * next; @@ -79,11 +79,6 @@ struct usb_work { unsigned char plug; }; -struct usb_id { - const struct mach_id *mach_id; - struct usb_work *work; -}; - static const struct mach_id imx_ids[] = { { .vid = 0x066f, @@ -507,8 +502,8 @@ static int read_file(const char *name, unsigned char **buffer, unsigned *size) static int transfer(int report, unsigned char *p, unsigned cnt, int *last_trans) { int err; - if (cnt > usb_id->mach_id->max_transfer) - cnt = usb_id->mach_id->max_transfer; + if (cnt > mach_id->max_transfer) + cnt = mach_id->max_transfer; if (verbose > 4) { printf("report=%i\n", report); @@ -516,7 +511,7 @@ static int transfer(int report, unsigned char *p, unsigned cnt, int *last_trans) dump_bytes(p, cnt, 0); } - if (usb_id->mach_id->mode == MODE_BULK) { + if (mach_id->mode == MODE_BULK) { *last_trans = 0; err = libusb_bulk_transfer(usb_dev_handle, (report < 3) ? 1 : 2 + EP_IN, p, cnt, last_trans, 1000); @@ -602,7 +597,7 @@ static int do_status(void) break; } - if (usb_id->mach_id->mode == MODE_HID) { + if (mach_id->mode == MODE_HID) { err = transfer(4, tmp, sizeof(tmp), &last_trans); if (err) printf("4 in err=%i, last_trans=%i %02x %02x %02x %02x\n", @@ -810,7 +805,7 @@ static int load_file(void *buf, unsigned len, unsigned dladdr, retry = 0; - if (usb_id->mach_id->mode == MODE_BULK) { + if (mach_id->mode == MODE_BULK) { err = transfer(3, tmp, sizeof(tmp), &last_trans); if (err) printf("in err=%i, last_trans=%i %02x %02x %02x %02x\n", @@ -821,7 +816,7 @@ static int load_file(void *buf, unsigned len, unsigned dladdr, cnt = len; while (1) { - int now = get_min(cnt, usb_id->mach_id->max_transfer); + int now = get_min(cnt, mach_id->max_transfer); if (!now) break; @@ -839,7 +834,7 @@ static int load_file(void *buf, unsigned len, unsigned dladdr, if (mode_barebox) return transfer_size; - if (usb_id->mach_id->mode == MODE_HID) { + if (mach_id->mode == MODE_HID) { err = transfer(3, tmp, sizeof(tmp), &last_trans); if (err) printf("3 in err=%i, last_trans=%i %02x %02x %02x %02x\n", @@ -1233,7 +1228,7 @@ static int is_header(const unsigned char *p) const struct imx_flash_header_v2 *hdr = (const struct imx_flash_header_v2 *)p; - switch (usb_id->mach_id->header_type) { + switch (mach_id->header_type) { case HDR_MX51: if (ohdr->app_code_barker == 0xb1) return 1; @@ -1253,7 +1248,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start, struct imx_flash_header_v2 *hdr = (struct imx_flash_header_v2 *)p; int ret = 0; - switch (usb_id->mach_id->header_type) { + switch (mach_id->header_type) { case HDR_MX51: ret = write_dcd_table_old(ohdr, file_start, cnt); ohdr->dcd_block_len = 0; @@ -1274,7 +1269,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start, unsigned *header_addr) { const unsigned char *file_end = file_start + cnt; - switch (usb_id->mach_id->header_type) { + switch (mach_id->header_type) { case HDR_MX51: { struct imx_flash_header *ohdr = (struct imx_flash_header *)p; @@ -1315,7 +1310,7 @@ 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) { + switch (mach_id->header_type) { case HDR_MX51: return -EINVAL; @@ -1430,7 +1425,7 @@ static int do_irom_download(struct usb_work *curr, int verify) memcpy(verify_buffer, image, 64); - if ((type == FT_APP) && (usb_id->mach_id->mode != MODE_HID)) { + if ((type == FT_APP) && (mach_id->mode != MODE_HID)) { type = FT_LOAD_ONLY; verify = 2; } @@ -1469,7 +1464,7 @@ static int do_irom_download(struct usb_work *curr, int verify) } } - if (usb_id->mach_id->mode == MODE_HID && type == FT_APP) { + if (mach_id->mode == MODE_HID && type == FT_APP) { printf("jumping to 0x%08x\n", header_addr); ret = sdp_jump_address(header_addr); @@ -1532,7 +1527,7 @@ static int mxs_load_file(libusb_device_handle *dev, uint8_t *data, int size) cnt = size; while (1) { - int now = get_min(cnt, usb_id->mach_id->max_transfer); + int now = get_min(cnt, mach_id->max_transfer); if (!now) break; @@ -1591,7 +1586,6 @@ static void usage(const char *prgname) int main(int argc, char *argv[]) { - const struct mach_id *mach; libusb_device **devs; libusb_device *dev; int r; @@ -1663,7 +1657,7 @@ int main(int argc, char *argv[]) goto out; } - dev = find_imx_dev(devs, &mach, devpath, devtype); + dev = find_imx_dev(devs, &mach_id, devpath, devtype); if (!dev) { fprintf(stderr, "no supported device found\n"); goto out; @@ -1682,15 +1676,7 @@ int main(int argc, char *argv[]) goto out; } - usb_id = malloc(sizeof(*usb_id)); - if (!usb_id) { - perror("malloc"); - exit(1); - } - - usb_id->mach_id = mach; - - if (mach->dev_type == DEV_MXS) { + if (mach_id->dev_type == DEV_MXS) { ret = mxs_work(&w); goto out; } @@ -1715,9 +1701,6 @@ int main(int argc, char *argv[]) ret = 0; out: - if (usb_id) - free(usb_id); - if (usb_dev_handle) libusb_close(usb_dev_handle); -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-08-13 15:34 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 ` Uwe Kleine-König [this message] 2021-10-27 6:05 ` [PATCH v2 2/3] imx-usb-loader: Drop nearly unused struct usb_id 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 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=20210813152245.15841-3-u.kleine-koenig@pengutronix.de \ --to=u.kleine-koenig@pengutronix.de \ --cc=a.fatoum@pengutronix.de \ --cc=barebox@lists.infradead.org \ --cc=rcz@pengutronix.de \ --subject='Re: [PATCH v2 2/3] imx-usb-loader: Drop nearly unused struct usb_id' \ /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