[U-Boot] [PATCH 1/3] spl: add ymodem support

We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot. --- arch/arm/cpu/arm926ejs/davinci/spl.c | 25 +++++++++++++++ common/Makefile | 4 ++- common/xyzModem.c | 55 ++++++++++++++++++++++++++++++++++ include/xyzModem.h | 5 +++ lib/Makefile | 1 + 5 files changed, 89 insertions(+), 1 deletions(-)
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com
diff --git a/arch/arm/cpu/arm926ejs/davinci/spl.c b/arch/arm/cpu/arm926ejs/davinci/spl.c index 74632e5..1fedf7d 100644 --- a/arch/arm/cpu/arm926ejs/davinci/spl.c +++ b/arch/arm/cpu/arm926ejs/davinci/spl.c @@ -28,6 +28,7 @@ #include <ns16550.h> #include <malloc.h> #include <spi_flash.h> +#include <xyzModem.h>
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -93,4 +94,28 @@ void board_init_r(gd_t *id, ulong dummy) puts("SPI boot...\n"); spi_boot(); #endif +#ifdef CONFIG_SPL_YMODEM_LOAD + mem_malloc_init(CONFIG_SYS_TEXT_BASE - CONFIG_SYS_MALLOC_LEN, + CONFIG_SYS_MALLOC_LEN); + + gd = &gdata; + gd->bd = &bdata; + gd->flags |= GD_FLG_RELOC; + gd->baudrate = CONFIG_BAUDRATE; + serial_init(); /* serial communications setup */ + gd->have_console = 1; + + while(1){ + char ch; + + while(!tstc()){ + puts("Ymodem boot: press Enter to continue...\n"); + mdelay(1000); + } + ch = getc(); + if ((ch == '\r') || (ch == '\n')) break; + } + puts("Ymodem boot...\n"); + ymodem_boot(); +#endif } diff --git a/common/Makefile b/common/Makefile index 2a31c62..417a517 100644 --- a/common/Makefile +++ b/common/Makefile @@ -188,7 +188,9 @@ COBJS-y += console.o COBJS-y += dlmalloc.o COBJS-y += memsize.o COBJS-y += stdio.o - +ifdef CONFIG_SPL_BUILD +COBJS-$(CONFIG_SPL_YMODEM_LOAD) += xyzModem.o +endif
COBJS := $(sort $(COBJS-y)) XCOBJS := $(sort $(XCOBJS-y)) diff --git a/common/xyzModem.c b/common/xyzModem.c index a1f955b..8e024d0 100644 --- a/common/xyzModem.c +++ b/common/xyzModem.c @@ -847,3 +847,58 @@ GETC_IO_FUNCS (xyzModem_io, xyzModem_stream_open, xyzModem_stream_close, RedBoot_load (xmodem, xyzModem_io, false, false, xyzModem_xmodem); RedBoot_load (ymodem, xyzModem_io, false, false, xyzModem_ymodem); #endif + + +#ifdef CONFIG_SPL_BUILD +#ifdef CONFIG_SPL_YMODEM_LOAD +static int getcxmodem(void) { + if (tstc()) + return (getc()); + return -1; +} + +/* + * The main entry for YMODEM booting. It's necessary that SDRAM is already + * configured and available since this code loads the main U-Boot image + * from serial line into SDRAM and starts it from there. + */ +void ymodem_boot(void) +{ + int size; + int err; + int res; + connection_info_t info; + void (*uboot)(void) __noreturn; + ulong store_addr = ~0; + + /* + * Load U-Boot image from serial line into RAM + */ + size = 0; + info.mode = xyzModem_ymodem; + res = xyzModem_stream_open (&info, &err); + if (!res) { + store_addr = CONFIG_SYS_TEXT_BASE; + while ((res = + xyzModem_stream_read (store_addr, 1024, &err)) > 0) { + store_addr += res; + size += res; + } + } else { + printf ("%s\n", xyzModem_error (err)); + hang(); + } + + xyzModem_stream_close (&err); + xyzModem_stream_terminate (false, &getcxmodem); + + printf ("## Total Size = 0x%08x = %d Bytes\n", size, size); + + /* + * Jump to U-Boot image + */ + uboot = (void *) CONFIG_SYS_TEXT_BASE; + (*uboot)(); +} +#endif /* CONFIG_SPL_YMODEM_LOAD */ +#endif /* CONFIG_SPL_BUILD */ diff --git a/include/xyzModem.h b/include/xyzModem.h index f437bbd..275894c 100644 --- a/include/xyzModem.h +++ b/include/xyzModem.h @@ -58,6 +58,9 @@ #ifndef _XYZMODEM_H_ #define _XYZMODEM_H_
+#include <linux/types.h> +#include <linux/compiler.h> + #define xyzModem_xmodem 1 #define xyzModem_ymodem 2 /* Don't define this until the protocol support is in place */ @@ -114,4 +117,6 @@ void xyzModem_stream_terminate(bool method, int (*getc)(void)); int xyzModem_stream_read(char *buf, int size, int *err); char *xyzModem_error(int err);
+void ymodem_boot(void) __noreturn; + #endif /* _XYZMODEM_H_ */ diff --git a/lib/Makefile b/lib/Makefile index e6e6ec6..2983530 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -52,6 +52,7 @@ COBJS-$(CONFIG_SHA256) += sha256.o COBJS-y += strmhz.o COBJS-$(CONFIG_RBTREE) += rbtree.o else +COBJS-$(CONFIG_SPL_YMODEM_LOAD) += crc16.o COBJS-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += display_options.o endif

also fix NS16550_init() as we need 16x divider --- drivers/serial/ns16550.c | 2 +- include/ns16550.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletions(-)
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 0c23955..e6dec0c 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -52,7 +52,7 @@ void NS16550_init(NS16550_t com_port, int baud_divisor) serial_out((baud_divisor >> 8) & 0xff, &com_port->dlm); serial_out(UART_LCRVAL, &com_port->lcr); #if (defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)) || \ - defined(CONFIG_AM33XX) + defined(CONFIG_AM33XX) || defined(CONFIG_SOC_DA8XX)
#if defined(CONFIG_APTIX) /* /13 mode so Aptix 6MHz can hit 115200 */ diff --git a/include/ns16550.h b/include/ns16550.h index e9d2eda..51cb5b4 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -46,6 +46,14 @@ struct NS16550 { UART_REG(lsr); /* 5 */ UART_REG(msr); /* 6 */ UART_REG(spr); /* 7 */ +#ifdef CONFIG_SOC_DA8XX + UART_REG(reg8); /* 8 */ + UART_REG(reg9); /* 9 */ + UART_REG(revid1); /* A */ + UART_REG(revid2); /* B */ + UART_REG(pwr_mgmt); /* C */ + UART_REG(mdr1); /* D */ +#else UART_REG(mdr1); /* 8 */ UART_REG(reg9); /* 9 */ UART_REG(regA); /* A */ @@ -58,6 +66,7 @@ struct NS16550 { UART_REG(ssr); /* 11*/ UART_REG(reg12); /* 12*/ UART_REG(osc_12m_sel); /* 13*/ +#endif };
#define thr rbr

--- arch/arm/cpu/arm926ejs/davinci/da850_pinmux.c | 5 +++++ arch/arm/include/asm/arch-davinci/hardware.h | 1 + arch/arm/include/asm/arch-davinci/pinmux_defs.h | 1 + 3 files changed, 7 insertions(+), 0 deletions(-)
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com
diff --git a/arch/arm/cpu/arm926ejs/davinci/da850_pinmux.c b/arch/arm/cpu/arm926ejs/davinci/da850_pinmux.c index fa07fb5..dbae5fa 100644 --- a/arch/arm/cpu/arm926ejs/davinci/da850_pinmux.c +++ b/arch/arm/cpu/arm926ejs/davinci/da850_pinmux.c @@ -35,6 +35,11 @@ const struct pinmux_config spi1_pins_scs0[] = { };
/* UART pin muxer settings */ +const struct pinmux_config uart0_pins_txrx[] = { + { pinmux(3), 2, 4 }, /* UART0_RXD */ + { pinmux(3), 2, 5 }, /* UART0_TXD */ +}; + const struct pinmux_config uart1_pins_txrx[] = { { pinmux(4), 2, 6 }, /* UART1_RXD */ { pinmux(4), 2, 7 }, /* UART1_TXD */ diff --git a/arch/arm/include/asm/arch-davinci/hardware.h b/arch/arm/include/asm/arch-davinci/hardware.h index b145c6e..0a1e2cd 100644 --- a/arch/arm/include/asm/arch-davinci/hardware.h +++ b/arch/arm/include/asm/arch-davinci/hardware.h @@ -447,6 +447,7 @@ struct davinci_pllc_regs { /* Clock IDs */ enum davinci_clk_ids { DAVINCI_SPI0_CLKID = 2, + DAVINCI_UART0_CLKID = 2, DAVINCI_UART2_CLKID = 2, DAVINCI_MMC_CLKID = 2, DAVINCI_MDIO_CLKID = 4, diff --git a/arch/arm/include/asm/arch-davinci/pinmux_defs.h b/arch/arm/include/asm/arch-davinci/pinmux_defs.h index 07aceaa..eddb3f7 100644 --- a/arch/arm/include/asm/arch-davinci/pinmux_defs.h +++ b/arch/arm/include/asm/arch-davinci/pinmux_defs.h @@ -28,6 +28,7 @@ extern const struct pinmux_config spi1_pins_base[3]; extern const struct pinmux_config spi1_pins_scs0[1];
/* UART pin muxer settings */ +extern const struct pinmux_config uart0_pins_txrx[2]; extern const struct pinmux_config uart1_pins_txrx[2]; extern const struct pinmux_config uart2_pins_txrx[2]; extern const struct pinmux_config uart2_pins_rtscts[2];

On Tue, Mar 6, 2012 at 5:54 PM, Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
arch/arm/cpu/arm926ejs/davinci/spl.c | 25 +++++++++++++++ common/Makefile | 4 ++- common/xyzModem.c | 55 ++++++++++++++++++++++++++++++++++ include/xyzModem.h | 5 +++ lib/Makefile | 1 + 5 files changed, 89 insertions(+), 1 deletions(-)
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com
Your Signed-off-by line should be placed above the --- line.
Same applies for the other patches.

On Tue, 6 Mar 2012 18:34:05 -0300 Fabio Estevam festevam@gmail.com wrote:
On Tue, Mar 6, 2012 at 5:54 PM, Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
arch/arm/cpu/arm926ejs/davinci/spl.c | 25 +++++++++++++++ common/Makefile | 4 ++- common/xyzModem.c | 55 ++++++++++++++++++++++++++++++++++ include/xyzModem.h | 5 +++ lib/Makefile | 1 + 5 files changed, 89 insertions(+), 1 deletions(-)
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com
Your Signed-off-by line should be placed above the --- line.
Same applies for the other patches.
fix and resend?

On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
Dear Mikhail,
I am asking mainly out of curiousity, rather than giving feedback on the patch, but the OMAP-L138 boot ROM has the capability to load both SPL and U-Boot into empty SPI flash using the UART and sfh program or equivalent. (sfh is "serial flash host" for those following along, a program to talk to the boot ROM over the UART and download some code that the boot ROM can burn into SPI flash).
What is the advantage in allowing the SPL to flash U-Boot also?
Many thanks, and bye for now,

On Tue, 6 Mar 2012 22:28:46 +0000 Laurence Withers lwithers@guralp.com wrote:
On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
Dear Mikhail,
I am asking mainly out of curiousity, rather than giving feedback on the patch, but the OMAP-L138 boot ROM has the capability to load both SPL and U-Boot into empty SPI flash using the UART and sfh program or equivalent. (sfh is "serial flash host" for those following along, a program to talk to the boot ROM over the UART and download some code that the boot ROM can burn into SPI flash).
What is the advantage in allowing the SPL to flash U-Boot also?
sfh and boot rom does not understand our flash.
Many thanks, and bye for now,
Laurence Withers, lwithers@guralp.com http://www.guralp.com/ Direct tel:+447753988197 or tel:+443333408643 Software Engineer General support queries: support@guralp.com CMG-DCM CMG-EAM CMG-NAM

On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
This conflicts a bit with the SPL ymodem support that's now in u-boot-arm/master and making its way into mainline. Please rebase (and perhaps play some Makefile magic games to get arch/arm/cpu/armv7/omap-common/spl_ymodem.c available to davinci, and yes, we all know we need to unify more of the SPL codebase).

On Wed, 7 Mar 2012 08:25:39 -0700 Tom Rini trini@ti.com wrote:
On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
This conflicts a bit with the SPL ymodem support that's now in u-boot-arm/master and making its way into mainline. Please rebase (and perhaps play some Makefile magic games to get arch/arm/cpu/armv7/omap-common/spl_ymodem.c available to davinci, and yes, we all know we need to unify more of the SPL codebase).
Hm, spl_ymodem_load_image() should be arch independent, so I suggest moving it and getcymodem() out from arch/arm/cpu/armv7/omap-common/spl_ymodem.c to common/xyzModem.c (similarly to my patch).
any comments, suggestions?
Mikhail
-- Tom

On Wed, Mar 7, 2012 at 12:10 PM, Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com wrote:
On Wed, 7 Mar 2012 08:25:39 -0700 Tom Rini trini@ti.com wrote:
On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
This conflicts a bit with the SPL ymodem support that's now in u-boot-arm/master and making its way into mainline. Please rebase (and perhaps play some Makefile magic games to get arch/arm/cpu/armv7/omap-common/spl_ymodem.c available to davinci, and yes, we all know we need to unify more of the SPL codebase).
Hm, spl_ymodem_load_image() should be arch independent, so I suggest moving it and getcymodem() out from arch/arm/cpu/armv7/omap-common/spl_ymodem.c to common/xyzModem.c (similarly to my patch).
any comments, suggestions?
Stefano is working on trying to unify SPL, but the first step is getting the SPL loads Linux patch series in.

Hi,
On Wednesday, March 7, 2012, Mikhail Kshevetskiy < mikhail.kshevetskiy@gmail.com> wrote:
On Tue, 6 Mar 2012 22:28:46 +0000 Laurence Withers lwithers@guralp.com wrote:
On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
Dear Mikhail,
I am asking mainly out of curiousity, rather than giving feedback on the patch, but the OMAP-L138 boot ROM has the capability to load both SPL and U-Boot into empty SPI flash using the UART and sfh program or equivalent. (sfh is "serial flash host" for those following along, a program to talk
to
the boot ROM over the UART and download some code that the boot ROM can
burn
into SPI flash).
It's a combination of boot ROM and a programmer code (sfh) that is downloaded to the SoC and does the actual lowlevel config of the chip and the programming to flash. This code must be adapted (and maintained) for custom boards.
What is the advantage in allowing the SPL to flash U-Boot also?
sfh and boot rom does not understand our flash.
So there is also another advantage: You can use the same lowlevel initialization code for downloading code and for normal operation, you will only need to maintain u-boot for your board.
Christian

On 07/03/2012 20:30, Tom Rini wrote:
On Wed, Mar 7, 2012 at 12:10 PM, Mikhail Kshevetskiy mikhail.kshevetskiy@gmail.com wrote:
On Wed, 7 Mar 2012 08:25:39 -0700 Tom Rini trini@ti.com wrote:
On Wed, Mar 07, 2012 at 12:54:05AM +0400, Mikhail Kshevetskiy wrote:
We have an omap l138 based board without jtag and empty spi flash. UART is an only way to load something on this board, so we are using uart to load spl image u-boot and then we are using ymodem to load the rest part of u-boot.
This conflicts a bit with the SPL ymodem support that's now in u-boot-arm/master and making its way into mainline. Please rebase (and perhaps play some Makefile magic games to get arch/arm/cpu/armv7/omap-common/spl_ymodem.c available to davinci, and yes, we all know we need to unify more of the SPL codebase).
Hm, spl_ymodem_load_image() should be arch independent, so I suggest moving it and getcymodem() out from arch/arm/cpu/armv7/omap-common/spl_ymodem.c to common/xyzModem.c (similarly to my patch).
any comments, suggestions?
Stefano is working on trying to unify SPL, but the first step is getting the SPL loads Linux patch series in.
Yes - I have already tried to factorize SPL to make it common for all SOCs, but I broke some boards and discussing with Tom we decided that it is better to proceed step by step.
Stefano
participants (6)
-
Christian Riesch
-
Fabio Estevam
-
Laurence Withers
-
Mikhail Kshevetskiy
-
Stefano Babic
-
Tom Rini