[U-Boot] [PATCH] 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.
Signed-off-by: Stefano Babic sbabic@denx.de CC: Tim Harvey tharvey@gateworks.com CC: Fabio Estevam Fabio.Estevam@freescale.com CC: Eric Nelson eric.nelson@boundarydevices.com ---
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(+)
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c index ac6e40e..28217d2 100644 --- a/arch/arm/imx-common/spl.c +++ b/arch/arm/imx-common/spl.c @@ -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 */

Hi Stefano,
On Fri, Dec 4, 2015 at 7:02 AM, Stefano Babic sbabic@denx.de wrote:
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

Hi Fabio,
On 04/12/2015 11:51, Fabio Estevam wrote:
Hi Stefano,
On Fri, Dec 4, 2015 at 7:02 AM, Stefano Babic sbabic@denx.de wrote:
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?
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

Hi Stefano,
On 04.12.2015 12:49, Stefano Babic wrote:
On 04/12/2015 11:51, Fabio Estevam wrote:
Hi Stefano,
On Fri, Dec 4, 2015 at 7:02 AM, Stefano Babic sbabic@denx.de wrote:
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?
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.
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

On Fri, Dec 4, 2015 at 5:09 AM, Stefan Roese sr@denx.de wrote:
Hi Stefano,
On 04.12.2015 12:49, Stefano Babic wrote:
On 04/12/2015 11:51, Fabio Estevam wrote:
Hi Stefano,
On Fri, Dec 4, 2015 at 7:02 AM, Stefano Babic sbabic@denx.de wrote:
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?
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.
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

On 04/12/2015 14:09, Stefan Roese wrote:
Hi Stefano,
On 04.12.2015 12:49, Stefano Babic wrote:
On 04/12/2015 11:51, Fabio Estevam wrote:
Hi Stefano,
On Fri, Dec 4, 2015 at 7:02 AM, Stefano Babic sbabic@denx.de wrote:
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?
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.
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

Hi Stefano,
On 12/04/2015 02:02 AM, Stefano Babic wrote:
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.
Signed-off-by: Stefano Babic sbabic@denx.de CC: Tim Harvey tharvey@gateworks.com CC: Fabio Estevam Fabio.Estevam@freescale.com CC: Eric Nelson eric.nelson@boundarydevices.com
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(+)
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c index ac6e40e..28217d2 100644 --- a/arch/arm/imx-common/spl.c +++ b/arch/arm/imx-common/spl.c @@ -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.
- 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=bf5...
Since the gpr9 value in this mode is 0x00000001, the switch statement currently falls into the NOR/OneNAND block, which is pretty useless.

Hi Eric,
On 05/12/2015 21:13, Eric Nelson wrote:
Hi Stefano,
On 12/04/2015 02:02 AM, Stefano Babic wrote:
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.
Signed-off-by: Stefano Babic sbabic@denx.de CC: Tim Harvey tharvey@gateworks.com CC: Fabio Estevam Fabio.Estevam@freescale.com CC: Eric Nelson eric.nelson@boundarydevices.com
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(+)
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c index ac6e40e..28217d2 100644 --- a/arch/arm/imx-common/spl.c +++ b/arch/arm/imx-common/spl.c @@ -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.
- 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.
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=bf5...
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

Hi Eric,
On 07/12/2015 10:55, Stefano Babic wrote:
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

Hi Stefano,
On 12/07/2015 02:55 AM, Stefano Babic wrote:
Hi Eric,
On 05/12/2015 21:13, Eric Nelson wrote:
Hi Stefano,
On 12/04/2015 02:02 AM, Stefano Babic wrote:
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.
...
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=bf5...
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.
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:
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c index 28217d2..54f22e6 100644 --- a/arch/arm/imx-common/spl.c +++ b/arch/arm/imx-common/spl.c @@ -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

Hi Eric,
On 07/12/2015 15:08, Eric Nelson wrote:
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:
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c index 28217d2..54f22e6 100644 --- a/arch/arm/imx-common/spl.c +++ b/arch/arm/imx-common/spl.c @@ -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.
This is a nice trick - I cannot see as well any combination for obtaining a 0x01 in GPR9.
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
participants (5)
-
Eric Nelson
-
Fabio Estevam
-
Stefan Roese
-
Stefano Babic
-
Tim Harvey