diff mbox

[U-Boot] imx_common: check for Serial Downloader in spl_boot_device

Message ID 1449219732-5396-1-git-send-email-sbabic@denx.de
State Not Applicable
Delegated to: Stefano Babic
Headers show

Commit Message

Stefano Babic Dec. 4, 2015, 9:02 a.m. UTC
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(+)

Comments

Fabio Estevam Dec. 4, 2015, 10:51 a.m. UTC | #1
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
Stefano Babic Dec. 4, 2015, 11:49 a.m. UTC | #2
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
Stefan Roese Dec. 4, 2015, 1:09 p.m. UTC | #3
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
Tim Harvey Dec. 4, 2015, 2:30 p.m. UTC | #4
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
Stefano Babic Dec. 5, 2015, 7:10 a.m. UTC | #5
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
Eric Nelson Dec. 5, 2015, 8:13 p.m. UTC | #6
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=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.
Stefano Babic Dec. 7, 2015, 9:55 a.m. UTC | #7
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=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
Stefano Babic Dec. 7, 2015, 11:59 a.m. UTC | #8
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
diff mbox

Patch

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 */