Skip to contentSkip to conversation

imx_common: check for Serial Downloader in spl_boot_device

PATCH New Stefano Babic 5 participants 11 messages Dec 4, 2015 – Dec 7, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

CC Tim Harvey <[email protected]>
CC Fabio Estevam <[email protected]>
CC Eric Nelson <[email protected]>

---

Note: I know we have already discussed more complicated solution
for adding multilple files to imx_usb_loader. However, fixing ymodem support for i.MX6
was trivial and imx_usb_loader is working again.

 arch/arm/imx-common/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/imx-common/spl.c +7 -0
index ac6e40e..28217d2 100644
@@ -20,7 +20,14 @@ u32 spl_boot_device(void)
 	struct src *psrc = (struct src *)SRC_BASE_ADDR;
 	unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
 	unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
+	unsigned int bmode = readl(&psrc->sbmr2);
 
+	/*
+	 * Check for BMODE if serial downloader is enabled
+	 * BOOT_MODE - see IMX6DQRM Table 8-1
+	 */
+	if ((bmode >> 24) == 0x01) /* Serial Downloader */
+		return BOOT_DEVICE_UART;
 	/* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
 	switch ((reg & 0x000000FF) >> 4) {
 	 /* EIM: See 8.5.1, Table 8-9 */
Signature · 1 line
1.9.1
reviewer
#1 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Stefano,

Quoted 9 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

Just curious: what were the commands you usned with imx_usb_loader to load SPL + u-boot.img?

Thanks,

Fabio Estevam

#2 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Fabio,

Quoted 9 lines · Fabio Estevam

Hi Stefano,

Quoted 6 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

Quoted 7 lines
Quoted 3 lines

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

Just curious: what were the commands you usned with imx_usb_loader to load SPL + u-boot.img?

I did in this way:

sudo ../imx_usb_loader/imx_usb -v SPL
kermit kermit_uboot

And kermit_uboot (a kermit script) contains the lines:

set line /dev/ttyUSB1
set speed 115200
SET CARRIER-WATCH OFF
set flow-control none
set handshake none
set prefixing all
set file type bin
set protocol ymodem
send u-boot.img
c

The last "c" command tells kermit (from ckermit package in most distro) to switch from command line mode to communication mode, and when the script is finished, I get U-Boot prompt in the same shell. I tested on a custom board booting from SPI (when internal mode is used), and changing BOOT_MODE to serial, SPL starts automatically a download with y-modem.

Best regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#3 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Stefano,

Quoted 36 lines · Stefano Babic
Quoted 9 lines · Fabio Estevam

Hi Stefano,

Quoted 6 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

Quoted 7 lines
Quoted 3 lines

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

Just curious: what were the commands you usned with imx_usb_loader to load SPL + u-boot.img?

I did in this way:

sudo ../imx_usb_loader/imx_usb -v SPL
kermit kermit_uboot

And kermit_uboot (a kermit script) contains the lines:

set line /dev/ttyUSB1
set speed 115200
SET CARRIER-WATCH OFF
set flow-control none
set handshake none
set prefixing all
set file type bin
set protocol ymodem
send u-boot.img
c

Quoted 5 lines

The last "c" command tells kermit (from ckermit package in most distro) to switch from command line mode to communication mode, and when the script is finished, I get U-Boot prompt in the same shell. I tested on a custom board booting from SPI (when internal mode is used), and changing BOOT_MODE to serial, SPL starts automatically a download with y-modem.

Could you please add this description to some imx README in the U-Boot source tree? I'm pretty sure this could be helpful to others as well.

Thanks,
Stefan

#4 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Quoted 51 lines · Stefan Roese

Hi Stefano,

Quoted 40 lines · Stefano Babic
Quoted 11 lines · Fabio Estevam

Hi Stefano,

Quoted 7 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

Quoted 8 lines
Quoted 3 lines

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

Just curious: what were the commands you usned with imx_usb_loader to load SPL + u-boot.img?

I did in this way:

sudo ../imx_usb_loader/imx_usb -v SPL
kermit kermit_uboot

And kermit_uboot (a kermit script) contains the lines:

set line /dev/ttyUSB1
set speed 115200
SET CARRIER-WATCH OFF
set flow-control none
set handshake none
set prefixing all
set file type bin
set protocol ymodem
send u-boot.img
c

Quoted 5 lines

The last "c" command tells kermit (from ckermit package in most distro) to switch from command line mode to communication mode, and when the script is finished, I get U-Boot prompt in the same shell. I tested on a custom board booting from SPI (when internal mode is used), and changing BOOT_MODE to serial, SPL starts automatically a download with y-modem.

Quoted 4 lines

Could you please add this description to some imx README in the U-Boot source tree? I'm pretty sure this could be helpful to others as well.

Stefano,

Agreed - this sounds like an excellent thing to document for IMX6 SPL!

Nice work!

Tim

#5 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

In reply to Stefan Roese
Quoted 45 lines · Stefan Roese

Hi Stefano,

Quoted 36 lines · Stefano Babic
Quoted 9 lines · Fabio Estevam

Hi Stefano,

Quoted 6 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

Quoted 7 lines
Quoted 3 lines

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

Just curious: what were the commands you usned with imx_usb_loader to load SPL + u-boot.img?

I did in this way:

sudo ../imx_usb_loader/imx_usb -v SPL
kermit kermit_uboot

And kermit_uboot (a kermit script) contains the lines:

set line /dev/ttyUSB1
set speed 115200
SET CARRIER-WATCH OFF
set flow-control none
set handshake none
set prefixing all
set file type bin
set protocol ymodem
send u-boot.img
c

Quoted 5 lines

The last "c" command tells kermit (from ckermit package in most distro) to switch from command line mode to communication mode, and when the script is finished, I get U-Boot prompt in the same shell. I tested on a custom board booting from SPI (when internal mode is used), and changing BOOT_MODE to serial, SPL starts automatically a download with y-modem.

Quoted 4 lines

Could you please add this description to some imx README in the U-Boot source tree? I'm pretty sure this could be helpful to others as well.

Sure, it will be done in V2.

Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#6 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

In reply to Stefano Babic

Hi Stefano,

Quoted 30 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

CC Tim Harvey <[email protected]>
CC Fabio Estevam <[email protected]>
CC Eric Nelson <[email protected]>

---

Note: I know we have already discussed more complicated solution
for adding multilple files to imx_usb_loader. However, fixing ymodem support for i.MX6
was trivial and imx_usb_loader is working again.

 arch/arm/imx-common/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/imx-common/spl.c +0 -0
index ac6e40e..28217d2 100644

arch/arm/imx-common/spl.c u32 spl_boot_device(void) · line 28

Quoted 9 lines
arch/arm/imx-common/spl.c +5 -0
@@ -20,7 +20,14 @@ u32 spl_boot_device(void)
 	struct src *psrc = (struct src *)SRC_BASE_ADDR;
 	unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
 	unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
+	unsigned int bmode = readl(&psrc->sbmr2);
 
+	/*
+	 * Check for BMODE if serial downloader is enabled
+	 * BOOT_MODE - see IMX6DQRM Table 8-1
+	 */

I think you may need to check only bits 24 and 25 here.

arch/arm/imx-common/spl.c u32 spl_boot_device(void) · line 30

Quoted 2 lines
arch/arm/imx-common/spl.c +2 -0
+	if ((bmode >> 24) == 0x01) /* Serial Downloader */
+		return BOOT_DEVICE_UART;

Even though the data sheet says the high bits should be zero, I'm seeing some other bits set on an i.MX6SL:

	=> mm 0x020d801c
	020d801c: 22000001 ? x

Separately, what's your thought about enabling this when the system is reset through "bmode usb"?

http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/cpu/armv7/mx6/soc.c;h=bf5ae8cdffd8b0887291249332b06f66dc644832;hb=HEAD#l389

Since the gpr9 value in this mode is 0x00000001, the switch statement currently falls into the NOR/OneNAND block, which is pretty useless.

#7 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Eric,

Quoted 45 lines · Eric Nelson

Hi Stefano,

Quoted 30 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

This allows to load again a SPL based board with imx_usb_loader together with a tool such as kermit.

CC Tim Harvey <[email protected]>
CC Fabio Estevam <[email protected]>
CC Eric Nelson <[email protected]>

---

Note: I know we have already discussed more complicated solution
for adding multilple files to imx_usb_loader. However, fixing ymodem support for i.MX6
was trivial and imx_usb_loader is working again.

 arch/arm/imx-common/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/imx-common/spl.c +0 -0
index ac6e40e..28217d2 100644

arch/arm/imx-common/spl.c u32 spl_boot_device(void) · line 28

Quoted 9 lines
arch/arm/imx-common/spl.c +5 -0
@@ -20,7 +20,14 @@ u32 spl_boot_device(void)
 	struct src *psrc = (struct src *)SRC_BASE_ADDR;
 	unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
 	unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
+	unsigned int bmode = readl(&psrc->sbmr2);
 
+	/*
+	 * Check for BMODE if serial downloader is enabled
+	 * BOOT_MODE - see IMX6DQRM Table 8-1
+	 */

I think you may need to check only bits 24 and 25 here.

Quoted 9 lines

arch/arm/imx-common/spl.c u32 spl_boot_device(void) · line 30

Quoted 2 lines
arch/arm/imx-common/spl.c +2 -0
+	if ((bmode >> 24) == 0x01) /* Serial Downloader */
+		return BOOT_DEVICE_UART;

Even though the data sheet says the high bits should be zero, I'm seeing some other bits set on an i.MX6SL:

	=> mm 0x020d801c
	020d801c: 22000001 ? x

Agree - I checked on Solo / DL, and bits were zero. I fix it in V2.

Quoted 8 lines

Separately, what's your thought about enabling this when the system is reset through "bmode usb"?

http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/cpu/armv7/mx6/soc.c;h=bf5ae8cdffd8b0887291249332b06f66dc644832;hb=HEAD#l389

Since the gpr9 value in this mode is 0x00000001, the switch statement currently falls into the NOR/OneNAND block, which is pretty useless.

I agree with you, in fact it does not work - but I do not see a way to inform the ROM that next time it should run with USB as boot device. From the fusemap, I tried to set BOOT_CFG4 as 0x40 ("Reserved for serial ROM"), and fixing BOOT_CFG1 to 0x30, but it was only a try. In fact, we need to change BMODE from internal to serial, and I do not see a way in the "official" documentation.

Regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#8 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Eric,

Quoted 7 lines · Stefano Babic

I agree with you, in fact it does not work - but I do not see a way to inform the ROM that next time it should run with USB as boot device. From the fusemap, I tried to set BOOT_CFG4 as 0x40 ("Reserved for serial ROM"), and fixing BOOT_CFG1 to 0x30, but it was only a try. In fact, we need to change BMODE from internal to serial, and I do not see a way in the "official" documentation.

Ok, it was quite confused - forget it ;-).

Anyway, the fact is that when "bmode usb" is issued, the board announces itself correctly to the USB bus, but reading SBMR2 we get again internal mode. It is like another information to be stored, we should require a bit in some of the GPR registers to store it.

Regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#9 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

In reply to Stefano Babic

Hi Stefano,

Quoted 12 lines · Stefano Babic

Hi Eric,

Quoted 9 lines · Eric Nelson

Hi Stefano,

Quoted 6 lines · Stefano Babic

Check for bmode before reading the boot device to check if a serial downloader is started, and returns UART if the serial downloader is set, letting SPL to wait for an image if CONFIG_SPL_YMODEM_SUPPORT is set.

...

Quoted 9 lines
Quoted 8 lines

Separately, what's your thought about enabling this when the system is reset through "bmode usb"?

http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/cpu/armv7/mx6/soc.c;h=bf5ae8cdffd8b0887291249332b06f66dc644832;hb=HEAD#l389

Since the gpr9 value in this mode is 0x00000001, the switch statement currently falls into the NOR/OneNAND block, which is pretty useless.

Quoted 7 lines

I agree with you, in fact it does not work - but I do not see a way to inform the ROM that next time it should run with USB as boot device. From the fusemap, I tried to set BOOT_CFG4 as 0x40 ("Reserved for serial ROM"), and fixing BOOT_CFG1 to 0x30, but it was only a try. In fact, we need to change BMODE from internal to serial, and I do not see a way in the "official" documentation.

It doesn't help that all of this is undocumented :), but reverse- engineering the bmode command

The "bmode usb" command sets gpr9 to 1, which isn't used for anything else, so something like this will work:

arch/arm/imx-common/spl.c +2 -1
index 28217d2..54f22e6 100644
@@ -26,8 +26,10 @@ u32 spl_boot_device(void)
         * Check for BMODE if serial downloader is enabled
         * BOOT_MODE - see IMX6DQRM Table 8-1
         */
-       if ((bmode >> 24) == 0x01) /* Serial Downloader */
+       if (((bmode >> 24) == 0x01) /* Serial Downloader */
+           || (gpr10_boot && (1 == reg)))
                return BOOT_DEVICE_UART;
 

AFAIK, there isn't any other way to get a value of 1 into GPR9, so the test is safe.

Secondarily, since the low four bits are discarded in the switch(), this prevents an almost-always-wrong interpretation of 1 as OneNAND/NOR (I think there are very few if any i.MX6 boards using OneNAND or NOR for boot).

Regards,

Eric

#10 lore raw

PATCH 1/1 imx_common: check for Serial Downloader in spl_boot_device

Hi Eric,

Quoted 10 lines · Eric Nelson
Quoted 7 lines

I agree with you, in fact it does not work - but I do not see a way to inform the ROM that next time it should run with USB as boot device. From the fusemap, I tried to set BOOT_CFG4 as 0x40 ("Reserved for serial ROM"), and fixing BOOT_CFG1 to 0x30, but it was only a try. In fact, we need to change BMODE from internal to serial, and I do not see a way in the "official" documentation.

It doesn't help that all of this is undocumented :), but reverse- engineering the bmode command

:-)

Quoted 18 lines

The "bmode usb" command sets gpr9 to 1, which isn't used for anything else, so something like this will work:

arch/arm/imx-common/spl.c +2 -1
index 28217d2..54f22e6 100644
@@ -26,8 +26,10 @@ u32 spl_boot_device(void)
         * Check for BMODE if serial downloader is enabled
         * BOOT_MODE - see IMX6DQRM Table 8-1
         */
-       if ((bmode >> 24) == 0x01) /* Serial Downloader */
+       if (((bmode >> 24) == 0x01) /* Serial Downloader */
+           || (gpr10_boot && (1 == reg)))
                return BOOT_DEVICE_UART;
 
 AFAIK, there isn't any other way to get a value of 1 into GPR9,
Quoted 2 lines

so the test is safe.

This is a nice trick - I cannot see as well any combination for obtaining a 0x01 in GPR9.

Quoted 4 lines

Secondarily, since the low four bits are discarded in the switch(), this prevents an almost-always-wrong interpretation of 1 as OneNAND/NOR (I think there are very few if any i.MX6 boards using OneNAND or NOR for boot).

Agree.

I add your proposal in V2, thanks !

Best regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================