From c1266616fe1d219f564126561792c783e6eb3367 Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Mon, 30 May 2022 19:50:51 +0200 Subject: ARM: nxp-imx8mq-evk: install Barebox into eMMC boot partitions Switch the Barebox update handler to install Barebox in the eMMC boot partitions, which is preferred due to the capability to do atomic updates. Signed-off-by: Lucas Stach Link: https://lore.barebox.org/20220530175051.507579-1-l.stach@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/boards/nxp-imx8mq-evk/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/boards/nxp-imx8mq-evk/board.c b/arch/arm/boards/nxp-imx8mq-evk/board.c index c28107cb17..8d88bfe8c2 100644 --- a/arch/arm/boards/nxp-imx8mq-evk/board.c +++ b/arch/arm/boards/nxp-imx8mq-evk/board.c @@ -40,7 +40,7 @@ static int nxp_imx8mq_evk_init(void) barebox_set_hostname("imx8mq-evk"); flags = bootsource_get_instance() == 0 ? BBU_HANDLER_FLAG_DEFAULT : 0; - imx8m_bbu_internal_mmc_register_handler("eMMC", "/dev/mmc0.barebox", flags); + imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", flags); flags = bootsource_get_instance() == 1 ? BBU_HANDLER_FLAG_DEFAULT : 0; imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", flags); -- cgit v1.2.3 From 23f8d4680458ce9aa4bbd0d6275986b072c81664 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 13 Aug 2021 17:22:44 +0200 Subject: imx-usb-loader: Drop nearly unused struct usb_id 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 Tested-by: Ahmad Fatoum Link: https://lore.barebox.org/20210813152245.15841-3-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer --- 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 d8b2842989..96d36fa0a8 100644 --- a/scripts/imx/imx-usb-loader.c +++ b/scripts/imx/imx-usb-loader.c @@ -55,7 +55,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; @@ -82,11 +82,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, @@ -455,8 +450,8 @@ static void dump_bytes(const void *src, unsigned cnt, unsigned addr) 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); @@ -464,7 +459,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); @@ -550,7 +545,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", @@ -758,7 +753,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", @@ -769,7 +764,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; @@ -787,7 +782,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", @@ -1181,7 +1176,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; @@ -1201,7 +1196,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; @@ -1222,7 +1217,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; @@ -1263,7 +1258,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; @@ -1378,7 +1373,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; } @@ -1417,7 +1412,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); @@ -1480,7 +1475,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; @@ -1538,7 +1533,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; @@ -1610,7 +1604,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; @@ -1629,15 +1623,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; } @@ -1662,9 +1648,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); -- cgit v1.2.3 From f6e422513f75a8b2804e2665d6f1de60160072e4 Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Thu, 9 Jun 2022 23:43:30 +0200 Subject: ARM: mnt-reform: switch to upstream DT Now that all the necessary bits are upstream, we drop most of the Barebox DT for this board. Signed-off-by: Lucas Stach Link: https://lore.barebox.org/20220609214330.1443541-2-dev@lynxeye.de Signed-off-by: Sascha Hauer --- arch/arm/dts/imx8mq-mnt-reform2.dts | 164 +----------------------------------- 1 file changed, 1 insertion(+), 163 deletions(-) diff --git a/arch/arm/dts/imx8mq-mnt-reform2.dts b/arch/arm/dts/imx8mq-mnt-reform2.dts index 5a65324b3c..deb31abe54 100644 --- a/arch/arm/dts/imx8mq-mnt-reform2.dts +++ b/arch/arm/dts/imx8mq-mnt-reform2.dts @@ -6,17 +6,12 @@ /dts-v1/; -#include +#include #include "imx8mq.dtsi" #include "imx8mq-ddrc.dtsi" / { - model = "MNT Reform2"; - compatible = "mntre,reform2", "fsl,imx8mq"; - chosen { - stdout-path = &uart1; - environment-emmc { compatible = "barebox,environment"; device-path = &usdhc1, "partname:barebox-environment"; @@ -29,86 +24,13 @@ status = "disabled"; }; }; - - pcie1_refclk: pcie1-refclk { - compatible = "fixed-clock"; - #clock-cells = <0>; - clock-frequency = <100000000>; - }; -}; - -&fec1 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_fec1>; - phy-mode = "rgmii-id"; - phy-handle = <ðphy0>; - status = "okay"; - - mdio { - #address-cells = <1>; - #size-cells = <0>; - - ethphy0: ethernet-phy@4 { - compatible = "ethernet-phy-ieee802.3-c22"; - reg = <4>; - interrupts = <&gpio1 11 IRQ_TYPE_LEVEL_LOW>; - reset-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; - }; - }; }; &ocotp { barebox,provide-mac-address = <&fec1 0x640>; }; -&pcie1 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_pcie1>; - reset-gpio = <&gpio3 23 GPIO_ACTIVE_LOW>; - clocks = <&clk IMX8MQ_CLK_PCIE2_ROOT>, - <&clk IMX8MQ_CLK_PCIE2_AUX>, - <&clk IMX8MQ_CLK_PCIE2_PHY>, - <&pcie1_refclk>; - clock-names = "pcie", "pcie_aux", "pcie_phy", "pcie_bus"; - status = "okay"; -}; - -&uart1 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_uart1>; - status = "okay"; -}; - -&usb3_phy0 { - status = "okay"; -}; - -&usb3_phy1 { - status = "okay"; -}; - -&usb_dwc3_0 { - status = "okay"; - dr_mode = "host"; -}; - -&usb_dwc3_1 { - status = "okay"; - dr_mode = "host"; -}; - &usdhc1 { - assigned-clocks = <&clk IMX8MQ_CLK_USDHC1>; - assigned-clock-rates = <400000000>; - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_usdhc1>; - bus-width = <8>; - no-mmc-hs400; - non-removable; - no-sd; - no-sdio; - status = "okay"; - #address-cells = <1>; #size-cells = <1>; @@ -124,14 +46,6 @@ }; &usdhc2 { - assigned-clocks = <&clk IMX8MQ_CLK_USDHC2>; - assigned-clock-rates = <200000000>; - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_usdhc2>; - bus-width = <4>; - no-1-8-v; - status = "okay"; - #address-cells = <1>; #size-cells = <1>; @@ -145,79 +59,3 @@ reg = <0xe0000 0x20000>; }; }; - -&wdog1 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_wdog>; - fsl,ext-reset-output; - status = "okay"; -}; - -&iomuxc { - pinctrl_fec1: fec1grp { - fsl,pins = < - MX8MQ_IOMUXC_ENET_MDC_ENET1_MDC 0x3 - MX8MQ_IOMUXC_ENET_MDIO_ENET1_MDIO 0x23 - MX8MQ_IOMUXC_ENET_TX_CTL_ENET1_RGMII_TX_CTL 0x1f - MX8MQ_IOMUXC_ENET_TXC_ENET1_RGMII_TXC 0x1f - MX8MQ_IOMUXC_ENET_TD0_ENET1_RGMII_TD0 0x1f - MX8MQ_IOMUXC_ENET_TD1_ENET1_RGMII_TD1 0x1f - MX8MQ_IOMUXC_ENET_TD2_ENET1_RGMII_TD2 0x1f - MX8MQ_IOMUXC_ENET_TD3_ENET1_RGMII_TD3 0x1f - MX8MQ_IOMUXC_ENET_RX_CTL_ENET1_RGMII_RX_CTL 0x91 - MX8MQ_IOMUXC_ENET_RXC_ENET1_RGMII_RXC 0xd1 - MX8MQ_IOMUXC_ENET_RD0_ENET1_RGMII_RD0 0x91 - MX8MQ_IOMUXC_ENET_RD1_ENET1_RGMII_RD1 0x91 - MX8MQ_IOMUXC_ENET_RD2_ENET1_RGMII_RD2 0x91 - MX8MQ_IOMUXC_ENET_RD3_ENET1_RGMII_RD3 0xd1 - MX8MQ_IOMUXC_GPIO1_IO09_GPIO1_IO9 0x1 - MX8MQ_IOMUXC_GPIO1_IO11_GPIO1_IO11 0x1 - >; - }; - - pinctrl_pcie1: pcie1grp { - fsl,pins = < - MX8MQ_IOMUXC_SAI5_RXD2_GPIO3_IO23 0x16 - >; - }; - - pinctrl_uart1: uart1grp { - fsl,pins = < - MX8MQ_IOMUXC_UART1_RXD_UART1_DCE_RX 0x45 - MX8MQ_IOMUXC_UART1_TXD_UART1_DCE_TX 0x45 - >; - }; - - pinctrl_usdhc1: usdhc1grp { - fsl,pins = < - MX8MQ_IOMUXC_SD1_CLK_USDHC1_CLK 0x83 - MX8MQ_IOMUXC_SD1_CMD_USDHC1_CMD 0xc3 - MX8MQ_IOMUXC_SD1_DATA0_USDHC1_DATA0 0xc3 - MX8MQ_IOMUXC_SD1_DATA1_USDHC1_DATA1 0xc3 - MX8MQ_IOMUXC_SD1_DATA2_USDHC1_DATA2 0xc3 - MX8MQ_IOMUXC_SD1_DATA3_USDHC1_DATA3 0xc3 - MX8MQ_IOMUXC_SD1_DATA4_USDHC1_DATA4 0xc3 - MX8MQ_IOMUXC_SD1_DATA5_USDHC1_DATA5 0xc3 - MX8MQ_IOMUXC_SD1_DATA6_USDHC1_DATA6 0xc3 - MX8MQ_IOMUXC_SD1_DATA7_USDHC1_DATA7 0xc3 - MX8MQ_IOMUXC_SD1_RESET_B_GPIO2_IO10 0x41 - >; - }; - - pinctrl_usdhc2: usdhc2grp { - fsl,pins = < - MX8MQ_IOMUXC_SD2_CLK_USDHC2_CLK 0x03 - MX8MQ_IOMUXC_SD2_CMD_USDHC2_CMD 0xc3 - MX8MQ_IOMUXC_SD2_DATA0_USDHC2_DATA0 0xc3 - MX8MQ_IOMUXC_SD2_DATA1_USDHC2_DATA1 0xc3 - MX8MQ_IOMUXC_SD2_DATA2_USDHC2_DATA2 0xc3 - MX8MQ_IOMUXC_SD2_DATA3_USDHC2_DATA3 0xc - >; - }; - - pinctrl_wdog: wdog1grp { - fsl,pins = < - MX8MQ_IOMUXC_GPIO1_IO02_WDOG1_WDOG_B 0xc6 - >; - }; -}; -- cgit v1.2.3 From 7c2191e612fb1fba89d49a62b70fea9d7408433c Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 10 Jun 2022 09:11:43 +0200 Subject: ARM: i.MX7/8M: Fix boot source detection on i.MX8MP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On i.MX8MP the indicator for serial boot is 14, which is different from the value found for i.MX8MM. So consider 14 as serial boot, too and document the machines where the respective values are found. Signed-off-by: Uwe Kleine-König Link: https://lore.barebox.org/20220610071143.2832473-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/boot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c index 63afdf1ef4..7344af0d8b 100644 --- a/arch/arm/mach-imx/boot.c +++ b/arch/arm/mach-imx/boot.c @@ -522,7 +522,8 @@ static void __imx7_get_boot_source(enum bootsource *src, int *instance, case 5: *src = BOOTSOURCE_NOR; break; - case 15: + case 14: /* observed on i.MX8MP for USB "serial" booting */ + case 15: /* observed on i.MX8MM for USB "serial" booting */ *src = BOOTSOURCE_SERIAL; break; default: -- cgit v1.2.3 From 32f05fa24bb481906ff23e496d3a09260c8959dd Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 10 Jun 2022 18:50:57 +0200 Subject: ARM: i.MX: Make sure *_get_boot_source always assignes *src MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Callers of *_get_boot_source (e.g. start_atf() of nxp-imx8mm-evk or protonic-imx8m) expect src to hold the bootsource after return. So assign a value also for the "unknown" case. Fixes: ea55770308c0 ("ARM: i.MX: Add i.MX7 base architecture support") Signed-off-by: Uwe Kleine-König Link: https://lore.barebox.org/20220610165057.86722-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/boot.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c index 7344af0d8b..16a377341c 100644 --- a/arch/arm/mach-imx/boot.c +++ b/arch/arm/mach-imx/boot.c @@ -285,6 +285,8 @@ void imx53_get_boot_source(enum bootsource *src, int *instance) default: if (imx53_bootsource_nand(cfg1)) *src = BOOTSOURCE_NAND; + else + *src = BOOTSOURCE_UNKNOWN; break; } @@ -464,6 +466,8 @@ void imx6_get_boot_source(enum bootsource *src, int *instance) default: if (imx53_bootsource_nand(bootmode)) *src = BOOTSOURCE_NAND; + else + *src = BOOTSOURCE_UNKNOWN; break; } } @@ -527,6 +531,7 @@ static void __imx7_get_boot_source(enum bootsource *src, int *instance, *src = BOOTSOURCE_SERIAL; break; default: + *src = BOOTSOURCE_UNKNOWN; break; } } @@ -630,6 +635,8 @@ void vf610_get_boot_source(enum bootsource *src, int *instance) default: if (imx53_bootsource_nand(sbmr1)) *src = BOOTSOURCE_NAND; + else + *src = BOOTSOURCE_UNKNOWN; break; } } -- cgit v1.2.3 From 1d17f4a901735f23f5412e9e4d68ba520268e27a Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Thu, 16 Jun 2022 16:02:45 +0200 Subject: ARM: i.MX8MM: fix phy-reset gpio Drop the Barebox local property since the upstream/linux device-tree is handling it now within the phy and we get an error: ERROR: gpiolib: _gpio_request: gpio-118 (ethernet-phy@0) status -16 ERROR: miibus0: failed to request reset gpio for: ethernet-phy@0 Signed-off-by: Marco Felsch Link: https://lore.barebox.org/20220616140246.2191569-1-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/dts/imx8mm-evk.dts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/arm/dts/imx8mm-evk.dts b/arch/arm/dts/imx8mm-evk.dts index 304f150307..854e9db869 100644 --- a/arch/arm/dts/imx8mm-evk.dts +++ b/arch/arm/dts/imx8mm-evk.dts @@ -24,10 +24,6 @@ }; }; -&fec1 { - phy-reset-gpios = <&gpio4 22 GPIO_ACTIVE_LOW>; -}; - &usdhc2 { #address-cells = <1>; #size-cells = <1>; -- cgit v1.2.3 From 15559d8bf46d1778c581ae7c0862b8c8b5876411 Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Thu, 16 Jun 2022 16:02:46 +0200 Subject: ARM: i.MX8MM: increase off-on delay on the SD Vcc regulator This commit is ported from u-boot commit 247bbeb74c ("ARM: dts: imx8m: increase off-on delay on the SD Vcc regulator"). Currently barebox supports only SDR25/HS mode but it gets important as soon as barebox supports faster modes. 8<--------------------------------------------------------------------- ARM: dts: imx8m: increase off-on delay on the SD Vcc regulator Some SD Card controller and power circuitry has increased capacitance, which keeps the internal logic remains powered after regulator is switch off. This is generally the case when card is switched to SD104 mode, where a power cycle should be performed. In case if the card internal logic remains powered, it causes a subsequent failure of mode transition, effectively leading to failed enumeration. Introduce a delay of 20 msec in order to provide a possibility for internal card circuitry to drain voltages and perform a power cycle correctly. Similar fix is done in commit c49d0ac38a76 ("ARM: dts: rmobile: Increase off-on delay on the SD Vcc regulator") targeted Renesas SOCs. Signed-off-by: Andrey Zhizhikin Cc: Stefano Babic 8<--------------------------------------------------------------------- Signed-off-by: Marco Felsch Link: https://lore.barebox.org/20220616140246.2191569-2-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/dts/imx8mm-evk.dts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/dts/imx8mm-evk.dts b/arch/arm/dts/imx8mm-evk.dts index 854e9db869..6c06ad7e47 100644 --- a/arch/arm/dts/imx8mm-evk.dts +++ b/arch/arm/dts/imx8mm-evk.dts @@ -24,6 +24,10 @@ }; }; +®_usdhc2_vmmc { + off-on-delay-us = <20000>; +}; + &usdhc2 { #address-cells = <1>; #size-cells = <1>; -- cgit v1.2.3 From 3367ebc55ebe92e21c9a9045e1eab35593cfcf57 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 17 Jun 2022 10:24:14 +0200 Subject: scripts: imx-usb-loader: simplify code flow for file size calculations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change contains several changes that make the code flow easier to understand (in my eyes at least): - Rename max_length to firststage_len In some cases the image is loaded in two stages: First the PBL which is started after the PBL is loaded completely and then the whole image. So the size of the first stage isn't about some maximum. - Drop unintuitive total_size variable This variable used to be 0 in the one stage case and the filesize otherwise. Just use firststage_len for the first stage and use the filesize for the second stage (if needed). - Don't call the first stage size "fsize" in the debug output. - Add offset for second stage to debug output. Signed-off-by: Uwe Kleine-König Link: https://lore.barebox.org/20220617082414.323238-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer --- scripts/imx/imx-usb-loader.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c index 96d36fa0a8..69df9bbe92 100644 --- a/scripts/imx/imx-usb-loader.c +++ b/scripts/imx/imx-usb-loader.c @@ -1213,7 +1213,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start, } static int get_dl_start(const unsigned char *p, const unsigned char *file_start, - unsigned cnt, unsigned *max_length, unsigned *plugin, + unsigned cnt, size_t *firststage_len, unsigned *plugin, unsigned *header_addr) { const unsigned char *file_end = file_start + cnt; @@ -1228,7 +1228,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start, *header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd); *plugin = 0; if (err >= 0) - *max_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24); + *firststage_len = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24); break; } @@ -1244,7 +1244,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start, return -1; } - *max_length = ((struct imx_boot_data *)bd)->size; + *firststage_len = ((struct imx_boot_data *)bd)->size; *plugin = ((struct imx_boot_data *)bd)->plugin; ((struct imx_boot_data *)bd)->plugin = 0; @@ -1271,7 +1271,7 @@ static int get_payload_start(const unsigned char *p, uint32_t *ofs) } static int process_header(struct usb_work *curr, unsigned char *buf, int cnt, - unsigned *p_max_length, unsigned *p_plugin, + size_t *p_firststage_len, unsigned *p_plugin, unsigned *p_header_addr) { int ret; @@ -1286,7 +1286,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt, if (!is_header(p)) continue; - ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr); + ret = get_dl_start(p, buf, cnt, p_firststage_len, p_plugin, p_header_addr); if (ret < 0) { printf("!!get_dl_start returned %i\n", ret); return ret; @@ -1303,7 +1303,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt, if (*p_plugin && (!curr->plug) && (!header_cnt)) { header_cnt++; - header_max = header_offset + *p_max_length + 0x400; + header_max = header_offset + *p_firststage_len + 0x400; if (header_max > cnt - 32) header_max = cnt - 32; printf("header_max=%x\n", header_max); @@ -1329,18 +1329,17 @@ static int do_irom_download(struct usb_work *curr, int verify) unsigned char *buf = NULL; unsigned char *image; unsigned char *verify_buffer = NULL; - unsigned max_length; + size_t firststage_len; unsigned plugin = 0; unsigned header_addr = 0; - unsigned total_size = 0; buf = read_file(curr->filename, &fsize); if (!buf) return -errno; - max_length = fsize; + firststage_len = fsize; - ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr); + ret = process_header(curr, buf, fsize, &firststage_len, &plugin, &header_addr); if (ret < 0) goto cleanup; @@ -1352,14 +1351,10 @@ static int do_irom_download(struct usb_work *curr, int verify) goto cleanup; } + /* skip over the imx-image-part */ image = buf + header_offset; fsize -= header_offset; - if (fsize > max_length) { - total_size = fsize; - fsize = max_length; - } - type = FT_APP; if (verify) { @@ -1379,10 +1374,10 @@ static int do_irom_download(struct usb_work *curr, int verify) } } - printf("loading binary file(%s) to 0x%08x, fsize=%zu type=%d...\n", - curr->filename, header_addr, fsize, type); + printf("loading binary file(%s) to 0x%08x, firststage_len=%zu type=%d, hdroffset=%u...\n", + curr->filename, header_addr, firststage_len, type, header_offset); - ret = load_file(image, fsize, header_addr, type, false); + ret = load_file(image, firststage_len, header_addr, type, false); if (ret < 0) goto cleanup; @@ -1420,7 +1415,7 @@ static int do_irom_download(struct usb_work *curr, int verify) return ret; } - if (total_size) { + if (firststage_len < fsize) { uint32_t ofs; ret = get_payload_start(image, &ofs); @@ -1428,9 +1423,9 @@ static int do_irom_download(struct usb_work *curr, int verify) printf("Cannot get offset of payload\n"); goto cleanup; } - printf("Loading full image\n"); + printf("Loading full image from offset %u\n", ofs); printf("Note: This needs board support on the other end\n"); - load_file(image + ofs, total_size - ofs, 0, 0, true); + load_file(image + ofs, fsize - ofs, 0, 0, true); } ret = 0; -- cgit v1.2.3