Commit 942cb0b6a29f74507adeb0bce7ff7f23f69faf84

Authored by Simon Glass
Committed by Hans de Goede
1 parent c01c71bc16

sunxi: Normalise FEL support

Make sunxi's FEL code fit with the normal U-Boot boot sequence instead of
creating its own. There are some #ifdefs required in start.S. Future work
will hopefully remove these.

This series is available at u-boot-dm, branch sunxi-working.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Showing 10 changed files with 73 additions and 94 deletions Side-by-side Diff

arch/arm/cpu/armv7/start.S
... ... @@ -54,7 +54,8 @@
54 54 * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
55 55 * Continue to use ROM code vector only in OMAP4 spl)
56 56 */
57   -#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
  57 +#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD)) && \
  58 + !defined(CONFIG_SPL_FEL)
58 59 /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */
59 60 mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register
60 61 bic r0, #CR_V @ V = 0
61 62  
... ... @@ -67,7 +68,9 @@
67 68  
68 69 /* the mask ROM code should have PLL and others stable */
69 70 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  71 +#ifndef CONFIG_SPL_FEL
70 72 bl cpu_init_cp15
  73 +#endif
71 74 bl cpu_init_crit
72 75 #endif
73 76  
arch/arm/cpu/armv7/sunxi/Makefile
... ... @@ -39,8 +39,6 @@
39 39 obj-$(CONFIG_MACH_SUN6I) += dram_sun6i.o
40 40 obj-$(CONFIG_MACH_SUN7I) += dram_sun4i.o
41 41 obj-$(CONFIG_MACH_SUN8I) += dram_sun8i.o
42   -ifdef CONFIG_SPL_FEL
43   -obj-y += start.o
44   -endif
  42 +obj-y += fel_utils.o
45 43 endif
arch/arm/cpu/armv7/sunxi/board.c
... ... @@ -27,6 +27,13 @@
27 27  
28 28 #include <linux/compiler.h>
29 29  
  30 +struct fel_stash {
  31 + uint32_t sp;
  32 + uint32_t lr;
  33 +};
  34 +
  35 +struct fel_stash fel_stash __attribute__((section(".data")));
  36 +
30 37 static int gpio_init(void)
31 38 {
32 39 #if CONFIG_CONS_INDEX == 1 && defined(CONFIG_UART0_PORT_F)
... ... @@ -65,6 +72,12 @@
65 72 return 0;
66 73 }
67 74  
  75 +void spl_board_load_image(void)
  76 +{
  77 + debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr);
  78 + return_to_fel(fel_stash.sp, fel_stash.lr);
  79 +}
  80 +
68 81 void s_init(void)
69 82 {
70 83 #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I
... ... @@ -95,6 +108,14 @@
95 108 */
96 109 u32 spl_boot_device(void)
97 110 {
  111 + /*
  112 + * Have we been asked to return to the FEL portion of the boot ROM?
  113 + * TODO: We need a more robust test here, or bracket this with
  114 + * #ifdef CONFIG_SPL_FEL.
  115 + */
  116 + if (fel_stash.lr >= 0xffff0000 && fel_stash.lr < 0xffff4000)
  117 + return BOOT_DEVICE_BOARD;
  118 +
98 119 return BOOT_DEVICE_MMC1;
99 120 }
100 121  
arch/arm/cpu/armv7/sunxi/config.mk
1 1 # Build a combined spl + u-boot image
2 2 ifdef CONFIG_SPL
3 3 ifndef CONFIG_SPL_BUILD
4   -ifndef CONFIG_SPL_FEL
5 4 ALL-y += u-boot-sunxi-with-spl.bin
6   -endif
7 5 endif
8 6 endif
arch/arm/cpu/armv7/sunxi/fel_utils.S
  1 +/*
  2 + * Utility functions for FEL mode.
  3 + *
  4 + * Copyright (c) 2015 Google, Inc
  5 + *
  6 + * SPDX-License-Identifier: GPL-2.0+
  7 + */
  8 +
  9 +#include <asm-offsets.h>
  10 +#include <config.h>
  11 +#include <asm/system.h>
  12 +#include <linux/linkage.h>
  13 +
  14 +ENTRY(save_boot_params)
  15 + ldr r0, =fel_stash
  16 + str sp, [r0, #0]
  17 + str lr, [r0, #4]
  18 + b save_boot_params_ret
  19 +ENDPROC(save_boot_params)
  20 +
  21 +ENTRY(return_to_fel)
  22 + mov sp, r0
  23 + mov lr, r1
  24 + bx lr
  25 +ENDPROC(return_to_fel)
arch/arm/cpu/armv7/sunxi/u-boot-spl-fel.lds
1   -/*
2   - * (C) Copyright 2013
3   - * Henrik Nordstrom <henrik@henriknordstrom.net>
4   - *
5   - * SPDX-License-Identifier: GPL-2.0+
6   - */
7   -OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
8   -OUTPUT_ARCH(arm)
9   -ENTRY(s_init)
10   -SECTIONS
11   -{
12   - . = 0x00002000;
13   -
14   - . = ALIGN(4);
15   - .text :
16   - {
17   - *(.text.s_init)
18   - *(.text*)
19   - }
20   -
21   - . = ALIGN(4);
22   - .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
23   -
24   - . = ALIGN(4);
25   - .data : {
26   - *(.data*)
27   - }
28   -
29   - . = ALIGN(4);
30   - .u_boot_list : {
31   - KEEP(*(SORT(.u_boot_list*)));
32   - }
33   -
34   - . = ALIGN(4);
35   - . = .;
36   -
37   - . = ALIGN(4);
38   - .rel.dyn : {
39   - __rel_dyn_start = .;
40   - *(.rel*)
41   - __rel_dyn_end = .;
42   - }
43   -
44   - .dynsym : {
45   - __dynsym_start = .;
46   - *(.dynsym)
47   - }
48   -
49   - . = ALIGN(4);
50   - .note.gnu.build-id :
51   - {
52   - *(.note.gnu.build-id)
53   - }
54   - _end = .;
55   -
56   - . = ALIGN(4096);
57   - .mmutable : {
58   - *(.mmutable)
59   - }
60   -
61   - .bss_start __rel_dyn_start (OVERLAY) : {
62   - KEEP(*(.__bss_start));
63   - __bss_base = .;
64   - }
65   -
66   - .bss __bss_base (OVERLAY) : {
67   - *(.bss*)
68   - . = ALIGN(4);
69   - __bss_limit = .;
70   - }
71   -
72   - .bss_end __bss_limit (OVERLAY) : {
73   - KEEP(*(.__bss_end));
74   - }
75   -
76   - /DISCARD/ : { *(.dynstr*) }
77   - /DISCARD/ : { *(.dynamic*) }
78   - /DISCARD/ : { *(.plt*) }
79   - /DISCARD/ : { *(.interp*) }
80   - /DISCARD/ : { *(.gnu*) }
81   - /DISCARD/ : { *(.note*) }
82   -}
arch/arm/include/asm/arch-sunxi/sys_proto.h
... ... @@ -13,5 +13,15 @@
13 13  
14 14 void sdelay(unsigned long);
15 15  
  16 +/* return_to_fel() - Return to BROM from SPL
  17 + *
  18 + * This returns back into the BROM after U-Boot SPL has performed its initial
  19 + * init. It uses the provided lr and sp to do so.
  20 + *
  21 + * @lr: BROM link register value (return address)
  22 + * @sp: BROM stack pointer
  23 + */
  24 +void return_to_fel(uint32_t lr, uint32_t sp);
  25 +
16 26 #endif
... ... @@ -149,6 +149,16 @@
149 149 bool "SPL/FEL mode support"
150 150 depends on SPL
151 151 default n
  152 + help
  153 + This enables support for Fast Early Loader (FEL) mode. This
  154 + allows U-Boot to be loaded to the board over USB by the on-chip
  155 + boot rom. U-Boot should be sent in two parts: SPL first, with
  156 + 'fel write 0x2000 u-boot-spl.bin; fel exe 0x2000' then U-Boot with
  157 + 'fel write 0x4a000000 u-boot.bin; fel exe 0x4a000000'. This option
  158 + shrinks the amount of SRAM available to SPL, so only enable it if
  159 + you need FEL. Note that enabling this option only allows FEL to be
  160 + used; it is still possible to boot U-Boot from boot media. U-Boot
  161 + SPL detects when it is being loaded using FEL.
152 162  
153 163 config UART0_PORT_F
154 164 bool "UART0 on MicroSD breakout board"
include/configs/sunxi-common.h
... ... @@ -18,10 +18,8 @@
18 18 */
19 19 #define CONFIG_SUNXI /* sunxi family */
20 20 #ifdef CONFIG_SPL_BUILD
21   -#ifndef CONFIG_SPL_FEL
22 21 #define CONFIG_SYS_THUMB_BUILD /* Thumbs mode to save space in SPL */
23 22 #endif
24   -#endif
25 23  
26 24 #include <asm/arch/cpu.h> /* get chip and board defs */
27 25  
28 26  
... ... @@ -149,10 +147,10 @@
149 147 #define CONFIG_SPL_SERIAL_SUPPORT
150 148 #define CONFIG_SPL_LIBGENERIC_SUPPORT
151 149  
  150 +#define CONFIG_SPL_BOARD_LOAD_IMAGE
  151 +
152 152 #ifdef CONFIG_SPL_FEL
153 153  
154   -#define CONFIG_SPL_LDSCRIPT "arch/arm/cpu/armv7/sunxi/u-boot-spl-fel.lds"
155   -#define CONFIG_SPL_START_S_PATH "arch/arm/cpu/armv7/sunxi"
156 154 #define CONFIG_SPL_TEXT_BASE 0x2000
157 155 #define CONFIG_SPL_MAX_SIZE 0x4000 /* 16 KiB */
158 156  
scripts/Makefile.spl
... ... @@ -154,9 +154,7 @@
154 154 endif
155 155  
156 156 ifdef CONFIG_SUNXI
157   -ifndef CONFIG_SPL_FEL
158 157 ALL-y += $(obj)/sunxi-spl.bin
159   -endif
160 158 endif
161 159  
162 160 ifeq ($(CONFIG_SYS_SOC),"at91")