Skip to contentSkip to conversation

arm64 patch

PATCH New fenghua at phytium.com.cn 5 participants 19 messages Dec 14, 2013 – Jan 10, 2014

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

v16 cover arm64 patch

From: David Feng <[email protected]>

Changes for v16:
- make the patches work with latest recently u-boot. add rela relocation type to OBJCFLAGS definition at arm/config.mk.

Changes for v15:
- modify boot process, u-boot will run at the highest exception level until it prepare jump to OS.
- Fix a few bugs in cache.S.These bug is reported by York Sun <[email protected]> and Scott Wood <[email protected]>.
- when booting, slaves will wait on WFI, master wakeup slaves by SGI interrupt.
- add generic_timer.c to utilize the newest timer architecture.
- add gic.S to support gic initialization and interrupt operations, currently only support GICv2.

Changes for v14:
- Merge rela relocation patches from Scott Wood <[email protected]>.
- Remove all CONFIG_NEED_MANUAL_RELOC and other fixups due to manual relocation. With rela relocation patches them are not needed.
- Fix the bug of MEMORY_ATTRIBUTES definition due to assembler. That need put brackets around (MT_NORMAL*8). Otherwise the result is wrong.This bug is reported by York Sun <[email protected]>.
- -msoft-float is not supported by aarch64-gcc,

    make a test though $(call cc-option,-msoft-float).

- Adjust the virtual address space to 42 bits.
- Filter armv8 boards from LIST_arm in MAKEALL.
- remove gpio.h in asm/arch-armv8/ and move mmu.h to asm/armv8/ directory.
- remove vexpress64.dts from this patch, it could be accessed from linux kernel.

Changes for v13:
- fix the bug of board_r.c and arm/lib/board.c due to CONFIG_NEED_MANUAL_RELOC. adjust initr_serial() in board_r.c to the first entry of init_sequence_r[] and relocate serial_initialize() in arm/lib/board.c, routines of serial_device should be relocated firstly by serial_initialize(), so that printf access the correct puts function, otherwise uninitialized serial_current will be selected as the output device.
- fix the bug of dcache_enable(). after mmu_setup the sctrl register value should be fetched again because it has been modifed by mmu_seup() function. This bug is reported by York Sun <[email protected]>.
- add macro branch_if_slave to macro.h, it choose processor with all zero affinity value as the master and is used in start.S.

Changes for v12:
- custom the patches to new format boards.cfg.

Changes for v11:
- Replace CONFIG_ARMV8 with CONFIG_ARM64. Currently, it's hard to distinguish what is armv8 specific and what is aarch64 specific, so we use CONFIG_ARM64
only, no CONFIG_ARMV8 used.
- rename README.armv8 with README.arm64 and make some modification.

Changes for v10:
- add weak definition to include/linux/linkage.h and make setup_el2/setup_el3/lowlevel_init weak routines, so them can be easily overridden by processor specific code.
- modify s-o-f of 0002-board-support-of-vexpress_aemv8a which use wrong mail address of Bhupesh Sharma.

Changes for v9:
- add Signed-off-by information to patch "board support of vexpress_aemv8a" which SMC91111 support is integrated from Sharma Bhupesh's patch.
- adjust pt_regs struct and add exception state preservation in exception.S.

Changes for v8:
- Integrate SMC91111 patch of sharma bhupesh.
- remove v8_outer_cache* which is not need currently.
- Change license tag.
- Mov crt0.S/relocate.S/interrupts.c to arm/lib and rename them with _64 suffix.
- Make el3/el2 initializing process of start.S as two separate routines. It could be easier to be replaced with processor specific codes.
- Remove exception stack save and restore routine, it is unnecessary now.
- simplify __weak function declaration.

Changes for v7:
- Check the patches with checkpatch.pl and get rid of almost all warnings. There are a few warnings still, but I think it should be that.
- change printf format in cmd_pxe.c, use %zd indtead of %ld to format size_t type variable.
- add macro PGTABLE_SIZE to identify tlb table size.

Changes for v6:
- Make modification to inappropriate licensed file and bugs according to ScottWood's advice. Thanks Scott for his checking to these patches.
- Enable u-boot's running at EL1.
- Get rid of compiling warnings originated from cmd_pxe.c.

Changes for v5:
- fix the generic board_f.c, remove zero_global_data from init_sequence_f array and move it to board_init_f() function with CONFIG_X86 switch. The previous fixup is inaccurate.
- Replace __ARMEB__ with __AARCH64EB__ in byteorder.h and unaligned.h, gcc for aarch64 use __AARCH64EB__ and __AARCH64EL__ to identify endian.
- Some modification to README.armv8

Changes for v4:
- merge arm64 to arm architecture.

David Feng (10):
fdt_support: 64bit initrd start address support
cmd_pxe: remove compiling warnings
add weak entry definition
arm64: Add tool to statically apply RELA relocations
arm64: Turn u-boot.bin back into an ELF file after relocate-rela
arm64: Make checkarmreloc accept arm64 relocations
arm64: core support
arm64: generic board support
arm64: board support of vexpress_aemv8a
arm64: MAKEALL, filter armv8 boards from LIST_arm

 MAKEALL                                 |   12 +-
 Makefile                                |   39 +++++-
 arch/arm/config.mk                      |    7 +-
 arch/arm/cpu/armv8/Makefile             |   17 +++
 arch/arm/cpu/armv8/cache.S              |  136 +++++++++++++++++++
 arch/arm/cpu/armv8/cache_v8.c           |  219 +++++++++++++++++++++++++++++++
 arch/arm/cpu/armv8/config.mk            |   15 +++
 arch/arm/cpu/armv8/cpu.c                |   43 ++++++
 arch/arm/cpu/armv8/exceptions.S         |  113 ++++++++++++++++
 arch/arm/cpu/armv8/generic_timer.c      |   31 +++++
 arch/arm/cpu/armv8/gic.S                |  106 +++++++++++++++
 arch/arm/cpu/armv8/start.S              |  164 +++++++++++++++++++++++
 arch/arm/cpu/armv8/tlb.S                |   34 +++++
 arch/arm/cpu/armv8/transition.S         |   83 ++++++++++++
 arch/arm/cpu/armv8/u-boot.lds           |   89 +++++++++++++
 arch/arm/include/asm/armv8/mmu.h        |  111 ++++++++++++++++
 arch/arm/include/asm/byteorder.h        |   12 ++
 arch/arm/include/asm/cache.h            |    5 +
 arch/arm/include/asm/config.h           |    6 +
 arch/arm/include/asm/gic.h              |   49 ++++++-
 arch/arm/include/asm/global_data.h      |    6 +-
 arch/arm/include/asm/io.h               |   15 ++-
 arch/arm/include/asm/macro.h            |   53 ++++++++
 arch/arm/include/asm/posix_types.h      |   10 ++
 arch/arm/include/asm/proc-armv/ptrace.h |   21 +++
 arch/arm/include/asm/proc-armv/system.h |   59 ++++++++-
 arch/arm/include/asm/system.h           |   84 ++++++++++++
 arch/arm/include/asm/types.h            |    4 +
 arch/arm/include/asm/u-boot.h           |    4 +
 arch/arm/include/asm/unaligned.h        |    2 +-
 arch/arm/lib/Makefile                   |   20 ++-
 arch/arm/lib/board.c                    |    7 +-
 arch/arm/lib/bootm.c                    |   24 ++++
 arch/arm/lib/crt0_64.S                  |  113 ++++++++++++++++
 arch/arm/lib/interrupts_64.c            |  120 +++++++++++++++++
 arch/arm/lib/relocate_64.S              |   58 ++++++++
 board/armltd/vexpress64/Makefile        |    8 ++
 board/armltd/vexpress64/vexpress64.c    |   56 ++++++++
 boards.cfg                              |    1 +
 common/board_f.c                        |   20 ++-
 common/cmd_pxe.c                        |    4 +-
 common/fdt_support.c                    |   66 +++++-----
 common/image.c                          |    1 +
 doc/README.arm64                        |   46 +++++++
 examples/standalone/stubs.c             |   15 +++
 include/configs/vexpress_aemv8a.h       |  189 ++++++++++++++++++++++++++
 include/image.h                         |    1 +
 include/linux/linkage.h                 |    4 +
 tools/Makefile                          |    6 +
 tools/relocate-rela.c                   |  189 ++++++++++++++++++++++++++
 50 files changed, 2429 insertions(+), 68 deletions(-)
 create mode 100644 arch/arm/cpu/armv8/Makefile
 create mode 100644 arch/arm/cpu/armv8/cache.S
 create mode 100644 arch/arm/cpu/armv8/cache_v8.c
 create mode 100644 arch/arm/cpu/armv8/config.mk
 create mode 100644 arch/arm/cpu/armv8/cpu.c
 create mode 100644 arch/arm/cpu/armv8/exceptions.S
 create mode 100644 arch/arm/cpu/armv8/generic_timer.c
 create mode 100644 arch/arm/cpu/armv8/gic.S
 create mode 100644 arch/arm/cpu/armv8/start.S
 create mode 100644 arch/arm/cpu/armv8/tlb.S
 create mode 100644 arch/arm/cpu/armv8/transition.S
 create mode 100644 arch/arm/cpu/armv8/u-boot.lds
 create mode 100644 arch/arm/include/asm/armv8/mmu.h
 create mode 100644 arch/arm/lib/crt0_64.S
 create mode 100644 arch/arm/lib/interrupts_64.c
 create mode 100644 arch/arm/lib/relocate_64.S
 create mode 100644 board/armltd/vexpress64/Makefile
 create mode 100644 board/armltd/vexpress64/vexpress64.c
 create mode 100644 doc/README.arm64
 create mode 100644 include/configs/vexpress_aemv8a.h
 create mode 100644 tools/relocate-rela.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v16 1/10 fdt_support: 64bit initrd start address support

From: David Feng <[email protected]>

---
 common/fdt_support.c |   66 ++++++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 32 deletions(-)
common/fdt_support.c +34 -32
index 1f0d8f5..a3f7442 100644
@@ -21,6 +21,34 @@
  */
 DECLARE_GLOBAL_DATA_PTR;
 
+/*
+ * Get cells len in bytes
+ *     if #NNNN-cells property is 2 then len is 8
+ *     otherwise len is 4
+ */
+static int get_cells_len(void *blob, char *nr_cells_name)
+{
+	const fdt32_t *cell;
+
+	cell = fdt_getprop(blob, 0, nr_cells_name, NULL);
+	if (cell && fdt32_to_cpu(*cell) == 2)
+		return 8;
+
+	return 4;
+}
+
+/*
+ * Write a 4 or 8 byte big endian cell
+ */
+static void write_cell(u8 *addr, u64 val, int size)
+{
+	int shift = (size - 1) * 8;
+	while (size-- > 0) {
+		*addr++ = (val >> shift) & 0xff;
+		shift -= 8;
+	}
+}
+
 /**
  * fdt_getprop_u32_default - Find a node and return it's property or a default
  *
@@ -131,9 +159,9 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
 
 int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 {
-	int   nodeoffset;
+	int   nodeoffset, addr_cell_len;
 	int   err, j, total;
-	fdt32_t  tmp;
+	fdt64_t  tmp;
 	const char *path;
 	uint64_t addr, size;
 
@@ -170,9 +198,11 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 		return err;
 	}
 
+	addr_cell_len = get_cells_len(fdt, "#address-cells");
+
 	path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
 	if ((path == NULL) || force) {
-		tmp = cpu_to_fdt32(initrd_start);
+		write_cell((u8 *)&tmp, initrd_start, addr_cell_len);
 		err = fdt_setprop(fdt, nodeoffset,
 			"linux,initrd-start", &tmp, sizeof(tmp));
 		if (err < 0) {
@@ -181,7 +211,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 				fdt_strerror(err));
 			return err;
 		}
-		tmp = cpu_to_fdt32(initrd_end);
+		write_cell((u8 *)&tmp, initrd_end, addr_cell_len);
 		err = fdt_setprop(fdt, nodeoffset,
 			"linux,initrd-end", &tmp, sizeof(tmp));
 		if (err < 0) {
@@ -343,34 +373,6 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
 	do_fixup_by_compat(fdt, compat, prop, &tmp, 4, create);
 }
 
-/*
- * Get cells len in bytes
- *     if #NNNN-cells property is 2 then len is 8
- *     otherwise len is 4
- */
-static int get_cells_len(void *blob, char *nr_cells_name)
-{
-	const fdt32_t *cell;
-
-	cell = fdt_getprop(blob, 0, nr_cells_name, NULL);
-	if (cell && fdt32_to_cpu(*cell) == 2)
-		return 8;
-
-	return 4;
-}
-
-/*
- * Write a 4 or 8 byte big endian cell
- */
-static void write_cell(u8 *addr, u64 val, int size)
-{
-	int shift = (size - 1) * 8;
-	while (size-- > 0) {
-		*addr++ = (val >> shift) & 0xff;
-		shift -= 8;
-	}
-}
-
 #ifdef CONFIG_NR_DRAM_BANKS
 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS
 #else
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v16 2/10 cmd_pxe: remove compiling warnings

From: David Feng <[email protected]>

---
 common/cmd_pxe.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/cmd_pxe.c +2 -2
index db6b156..c27ec35 100644
@@ -59,7 +59,7 @@ static int format_mac_pxe(char *outbuf, size_t outbuf_len)
 	uchar ethaddr[6];
 
 	if (outbuf_len < 21) {
-		printf("outbuf is too small (%d < 21)\n", outbuf_len);
+		printf("outbuf is too small (%zd < 21)\n", outbuf_len);
 
 		return -EINVAL;
 	}
@@ -103,7 +103,7 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 	path_len = (last_slash - bootfile) + 1;
 
 	if (bootfile_path_size < path_len) {
-		printf("bootfile_path too small. (%d < %d)\n",
+		printf("bootfile_path too small. (%zd < %zd)\n",
 				bootfile_path_size, path_len);
 
 		return -1;
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v16 3/10 add weak entry definition

From: David Feng <[email protected]>

---
 include/linux/linkage.h |    4 ++++
 1 file changed, 4 insertions(+)
include/linux/linkage.h +4 -0
index 39c712e..7435fcd 100644
@@ -48,6 +48,10 @@
 	.globl SYMBOL_NAME(name); \
 	LENTRY(name)
 
+#define WEAK(name) \
+	.weak SYMBOL_NAME(name); \
+	LENTRY(name)
+
 #ifndef END
 #define END(name) \
 	.size name, .-name
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v16 4/10 arm64: Add tool to statically apply RELA relocations

From: Scott Wood <[email protected]>

ARM64 uses the newer RELA-style relocations rather than the older REL. RELA relocations have an addend in the relocation struct, rather than expecting the loader to read a value from the location to be updated.

While this is beneficial for ordinary program loading, it's problematic for U-Boot because the location to be updated starts out with zero, rather than a pre-relocation value. Since we need to be able to run C code before relocation, we need a tool to apply the relocations at build time.

In theory this tool is applicable to other newer architectures (mainly 64-bit), but currently the only relocations it supports are for arm64, and it assumes a 64-bit little-endian target. If the latter limitation is ever to be changed, we'll need a way to tell the tool what format the image is in. Eventually this may be replaced by a tool that uses libelf or similar and operates directly on the ELF file. I've written some code for such an approach but libelf does not make it easy to poke addresses by memory address (rather than by section), and I was hesitant to write code to manually parse the program headers and do the update outside of libelf (or to iterate over sections) -- especially since it wouldn't get test coverage on things like binaries with multiple PT_LOAD segments. This should be good enough for now to let the manual relocation stuff be removed from the arm64 patches.

---
 Makefile              |   12 ++++
 tools/Makefile        |    6 ++
 tools/relocate-rela.c |  189 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+)
 create mode 100644 tools/relocate-rela.c
Makefile +12 -0
index 7310c4e..4a8e8c5 100644
@@ -334,6 +334,17 @@ else
 BOARD_SIZE_CHECK =
 endif
 
+# Statically apply RELA-style relocations (currently arm64 only)
+ifneq ($(CONFIG_STATIC_RELA),)
+# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base
+DO_STATIC_RELA = \
+	start=$$($(NM) $(1) | grep __rel_dyn_start | cut -f 1 -d ' '); \
+	end=$$($(NM) $(1) | grep __rel_dyn_end | cut -f 1 -d ' '); \
+	$(obj)tools/relocate-rela $(2) $(3) $$start $$end
+else
+DO_STATIC_RELA =
+endif
+
 # Always append ALL so that arch config.mk's can add custom ones
 ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map
 
@@ -376,6 +387,7 @@ $(obj)u-boot.srec:	$(obj)u-boot
 
 $(obj)u-boot.bin:	$(obj)u-boot
 		$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
+		$(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
 		$(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr:	$(obj)u-boot
tools/Makefile +6 -0
index 14d94e3..6d40398 100644
@@ -59,6 +59,7 @@ BIN_FILES-$(CONFIG_NETCONSOLE) += ncb$(SFX)
 BIN_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
 BIN_FILES-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
 BIN_FILES-y += proftool(SFX)
+BIN_FILES-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
 
 # Source files which exist outside the tools directory
 EXT_OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += common/env_embedded.o
@@ -84,6 +85,7 @@ NOPED_OBJ_FILES-y += os_support.o
 NOPED_OBJ_FILES-y += pblimage.o
 NOPED_OBJ_FILES-y += proftool.o
 NOPED_OBJ_FILES-y += ublimage.o
+NOPED_OBJ_FILES-y += relocate-rela.o
 OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc.o
 OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
 OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
@@ -250,6 +252,10 @@ $(obj)kwboot$(SFX): $(obj)kwboot.o
 	$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
 	$(HOSTSTRIP) $@
 
+$(obj)relocate-rela$(SFX): $(obj)relocate-rela.o
+	$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+	$(HOSTSTRIP) $@
+
 # Some of the tool objects need to be accessed from outside the tools directory
 $(obj)%.o: $(SRCTREE)/common/%.c
 	$(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
tools/relocate-rela.c new file +189 -0

189 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v16 5/10 arm64: Turn u-boot.bin back into an ELF file after relocate-rela

From: Scott Wood <[email protected]>

While performing relocations on u-boot.bin should be good enough for booting on real hardware, some simulators insist on booting an ELF file (and yet don't perform ELF relocations), so convert the relocated binary back into an ELF file. This can go away in the future if we change relocate-rela to operate directly on the ELF file, or if and when we stop caring about a simulator with this restriction.

---
 Makefile |   13 +++++++++++++
 1 file changed, 13 insertions(+)
Makefile +13 -0
index 4a8e8c5..861f31e 100644
@@ -358,6 +358,7 @@ ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin
 ifneq ($(CONFIG_SPL_TARGET),)
 ALL-$(CONFIG_SPL) += $(obj)$(subst ",,$(CONFIG_SPL_TARGET))
 endif
+ALL-$(CONFIG_REMAKE_ELF) += $(obj)u-boot.elf
 
 # enable combined SPL/u-boot/dtb rules for tegra
 ifneq ($(CONFIG_TEGRA),)
@@ -526,6 +527,18 @@ $(obj)u-boot-img-spl-at-end.bin: $(obj)spl/u-boot-spl.bin $(obj)u-boot.img
 			conv=notrunc 2>/dev/null
 		cat $(obj)u-boot-pad.img $(obj)spl/u-boot-spl.bin > $@
 
+# Create a new ELF from a raw binary file.  This is useful for arm64
+# where static relocation needs to be performed on the raw binary,
+# but certain simulators only accept an ELF file (but don't do the
+# relocation).
+# FIXME refactor dts/Makefile to share target/arch detection
+$(obj)u-boot.elf: $(obj)u-boot.bin
+	@$(OBJCOPY)  -B aarch64 -I binary -O elf64-littleaarch64 \
+		$< $(obj)u-boot-elf.o
+	@$(LD) $(obj)u-boot-elf.o -o $@ \
+		--defsym=_start=$(CONFIG_SYS_TEXT_BASE) \
+		-Ttext=$(CONFIG_SYS_TEXT_BASE)
+
 ifeq ($(CONFIG_SANDBOX),y)
 GEN_UBOOT = \
 		cd $(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v16 6/10 arm64: Make checkarmreloc accept arm64 relocations

From: Scott Wood <[email protected]>

---
 Makefile |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
Makefile +9 -5
index 861f31e..e331d35 100644
@@ -742,12 +742,16 @@ tools: $(VERSION_FILE) $(TIMESTAMP_FILE)
 	$(MAKE) -C $@ all
 endif	# config.mk
 
-# ARM relocations should all be R_ARM_RELATIVE.
+# ARM relocations should all be R_ARM_RELATIVE (32-bit) or
+# R_AARCH64_RELATIVE (64-bit).
 checkarmreloc: $(obj)u-boot
-	@if test "R_ARM_RELATIVE" != \
-		"`$(CROSS_COMPILE)readelf -r $< | cut -d ' ' -f 4 | grep R_ARM | sort -u`"; \
-		then echo "$< contains relocations other than \
-		R_ARM_RELATIVE"; false; fi
+	@RELOC="`$(CROSS_COMPILE)readelf -r -W $< | cut -d ' ' -f 4 | \
+		grep R_A | sort -u`"; \
+	if test "$$RELOC" != "R_ARM_RELATIVE" -a \
+		 "$$RELOC" != "R_AARCH64_RELATIVE"; then \
+		echo "$< contains unexpected relocations: $$RELOC"; \
+		false; \
+	fi
 
 $(VERSION_FILE):
 		@mkdir -p $(dir $(VERSION_FILE))
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v16 7/10 arm64: core support

From: David Feng <[email protected]>

Relocation code based on a patch by Scott Wood, which is:

---
 arch/arm/config.mk                      |    7 +-
 arch/arm/cpu/armv8/Makefile             |   17 +++
 arch/arm/cpu/armv8/cache.S              |  136 +++++++++++++++++++
 arch/arm/cpu/armv8/cache_v8.c           |  219 +++++++++++++++++++++++++++++++
 arch/arm/cpu/armv8/config.mk            |   15 +++
 arch/arm/cpu/armv8/cpu.c                |   43 ++++++
 arch/arm/cpu/armv8/exceptions.S         |  113 ++++++++++++++++
 arch/arm/cpu/armv8/generic_timer.c      |   31 +++++
 arch/arm/cpu/armv8/gic.S                |  106 +++++++++++++++
 arch/arm/cpu/armv8/start.S              |  164 +++++++++++++++++++++++
 arch/arm/cpu/armv8/tlb.S                |   34 +++++
 arch/arm/cpu/armv8/transition.S         |   83 ++++++++++++
 arch/arm/cpu/armv8/u-boot.lds           |   89 +++++++++++++
 arch/arm/include/asm/armv8/mmu.h        |  111 ++++++++++++++++
 arch/arm/include/asm/byteorder.h        |   12 ++
 arch/arm/include/asm/cache.h            |    5 +
 arch/arm/include/asm/config.h           |    6 +
 arch/arm/include/asm/gic.h              |   49 ++++++-
 arch/arm/include/asm/global_data.h      |    6 +-
 arch/arm/include/asm/io.h               |   15 ++-
 arch/arm/include/asm/macro.h            |   53 ++++++++
 arch/arm/include/asm/posix_types.h      |   10 ++
 arch/arm/include/asm/proc-armv/ptrace.h |   21 +++
 arch/arm/include/asm/proc-armv/system.h |   59 ++++++++-
 arch/arm/include/asm/system.h           |   84 ++++++++++++
 arch/arm/include/asm/types.h            |    4 +
 arch/arm/include/asm/u-boot.h           |    4 +
 arch/arm/include/asm/unaligned.h        |    2 +-
 arch/arm/lib/Makefile                   |   20 ++-
 arch/arm/lib/board.c                    |    7 +-
 arch/arm/lib/bootm.c                    |   24 ++++
 arch/arm/lib/crt0_64.S                  |  113 ++++++++++++++++
 arch/arm/lib/interrupts_64.c            |  120 +++++++++++++++++
 arch/arm/lib/relocate_64.S              |   58 ++++++++
 common/image.c                          |    1 +
 doc/README.arm64                        |   46 +++++++
 examples/standalone/stubs.c             |   15 +++
 include/image.h                         |    1 +
 38 files changed, 1882 insertions(+), 21 deletions(-)
 create mode 100644 arch/arm/cpu/armv8/Makefile
 create mode 100644 arch/arm/cpu/armv8/cache.S
 create mode 100644 arch/arm/cpu/armv8/cache_v8.c
 create mode 100644 arch/arm/cpu/armv8/config.mk
 create mode 100644 arch/arm/cpu/armv8/cpu.c
 create mode 100644 arch/arm/cpu/armv8/exceptions.S
 create mode 100644 arch/arm/cpu/armv8/generic_timer.c
 create mode 100644 arch/arm/cpu/armv8/gic.S
 create mode 100644 arch/arm/cpu/armv8/start.S
 create mode 100644 arch/arm/cpu/armv8/tlb.S
 create mode 100644 arch/arm/cpu/armv8/transition.S
 create mode 100644 arch/arm/cpu/armv8/u-boot.lds
 create mode 100644 arch/arm/include/asm/armv8/mmu.h
 create mode 100644 arch/arm/lib/crt0_64.S
 create mode 100644 arch/arm/lib/interrupts_64.c
 create mode 100644 arch/arm/lib/relocate_64.S
 create mode 100644 doc/README.arm64
arch/arm/config.mk +6 -1
index fd3e5fb..329c7a7 100644
@@ -17,7 +17,8 @@ endif
 
 LDFLAGS_FINAL += --gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections \
-		     -fno-common -ffixed-r9 -msoft-float
+		     -fno-common -ffixed-r9
+PLATFORM_RELFLAGS += $(call cc-option, -msoft-float)
 
 # Support generic board on ARM
 __HAVE_ARCH_GENERIC_BOARD := y
@@ -105,4 +106,8 @@ PLATFORM_CPPFLAGS += $(call cc-option, -mword-relocations)
 endif
 
 # limit ourselves to the sections we want in the .bin.
+ifdef CONFIG_ARM64
+OBJCFLAGS += -j .text -j .rodata -j .data -j .u_boot_list -j .rela.dyn
+else
 OBJCFLAGS += -j .text -j .rodata -j .data -j .u_boot_list -j .rel.dyn
+endif
arch/arm/cpu/armv8/Makefile new file +17 -0
new file mode 100644
index 0000000..b6eb6de
@@ -0,0 +1,17 @@
+#
+# (C) Copyright 2000-2003
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+extra-y	:= start.o
+
+obj-y	+= cpu.o
+obj-y	+= generic_timer.o
+obj-y	+= cache_v8.o
+obj-y	+= exceptions.o
+obj-y	+= cache.o
+obj-y	+= tlb.o
+obj-y	+= gic.o
+obj-y	+= transition.o
arch/arm/cpu/armv8/cache.S new file +136 -0

136 lines not on this page · raw message

arch/arm/cpu/armv8/cache_v8.c new file +219 -0

219 lines not on this page · raw message

arch/arm/cpu/armv8/config.mk new file +15 -0
new file mode 100644
index 0000000..027a68c
@@ -0,0 +1,15 @@
+#
+# (C) Copyright 2002
+# Gary Jennejohn, DENX Software Engineering, <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+PLATFORM_RELFLAGS += -fno-common -ffixed-x18
+
+# SEE README.arm-unaligned-accesses
+PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
+PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED)
+
+PF_CPPFLAGS_ARMV8 := $(call cc-option, -march=armv8-a)
+PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV8)
+PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED)
arch/arm/cpu/armv8/cpu.c new file +43 -0

43 lines not on this page · raw message

arch/arm/cpu/armv8/exceptions.S new file +113 -0

113 lines not on this page · raw message

arch/arm/cpu/armv8/generic_timer.c new file +31 -0
new file mode 100644
index 0000000..223b95e
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2013
+ * David Feng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/system.h>
+
+/*
+ * Generic timer implementation of get_tbclk()
+ */
+unsigned long get_tbclk(void)
+{
+	unsigned long cntfrq;
+	asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
+	return cntfrq;
+}
+
+/*
+ * Generic timer implementation of timer_read_counter()
+ */
+unsigned long timer_read_counter(void)
+{
+	unsigned long cntpct;
+	isb();
+	asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
+	return cntpct;
+}
arch/arm/cpu/armv8/gic.S new file +106 -0

106 lines not on this page · raw message

arch/arm/cpu/armv8/start.S new file +164 -0

164 lines not on this page · raw message

arch/arm/cpu/armv8/tlb.S new file +34 -0
new file mode 100644
index 0000000..f840b04
@@ -0,0 +1,34 @@
+/*
+ * (C) Copyright 2013
+ * David Feng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <asm-offsets.h>
+#include <config.h>
+#include <version.h>
+#include <linux/linkage.h>
+#include <asm/macro.h>
+
+/*
+ * void __asm_invalidate_tlb_all(void)
+ *
+ * invalidate all tlb entries.
+ */
+ENTRY(__asm_invalidate_tlb_all)
+	switch_el x9, 3f, 2f, 1f
+3:	tlbi	alle3
+	dsb	sy
+	isb
+	b	0f
+2:	tlbi	alle2
+	dsb	sy
+	isb
+	b	0f
+1:	tlbi	vmalle1
+	dsb	sy
+	isb
+0:
+	ret
+ENDPROC(__asm_invalidate_tlb_all)
arch/arm/cpu/armv8/transition.S new file +83 -0

83 lines not on this page · raw message

arch/arm/cpu/armv8/u-boot.lds new file +89 -0

89 lines not on this page · raw message

arch/arm/include/asm/armv8/mmu.h new file +111 -0

111 lines not on this page · raw message

arch/arm/include/asm/byteorder.h +12 -0
index c3489f1..71a9966 100644
@@ -23,10 +23,22 @@
 #  define __SWAB_64_THRU_32__
 #endif
 
+#ifdef	CONFIG_ARM64
+
+#ifdef __AARCH64EB__
+#include <linux/byteorder/big_endian.h>
+#else
+#include <linux/byteorder/little_endian.h>
+#endif
+
+#else	/* CONFIG_ARM64 */
+
 #ifdef __ARMEB__
 #include <linux/byteorder/big_endian.h>
 #else
 #include <linux/byteorder/little_endian.h>
 #endif
 
+#endif	/* CONFIG_ARM64 */
+
 #endif
arch/arm/include/asm/cache.h +5 -0
index 6d60a4a..ddebbc8 100644
@@ -11,6 +11,8 @@
 
 #include <asm/system.h>
 
+#ifndef CONFIG_ARM64
+
 /*
  * Invalidate L2 Cache using co-proc instruction
  */
@@ -28,6 +30,9 @@ void l2_cache_disable(void);
 void set_section_dcache(int section, enum dcache_option option);
 
 void dram_bank_mmu_setup(int bank);
+
+#endif
+
 /*
  * The current upper bound for ARM L1 data cache line sizes is 64 bytes.  We
  * use that value for aligning DMA buffers unless the board config has specified
arch/arm/include/asm/config.h +6 -0
index 99b703e..abf79e5 100644
@@ -9,4 +9,10 @@
 
 #define CONFIG_LMB
 #define CONFIG_SYS_BOOT_RAMDISK_HIGH
+
+#ifdef CONFIG_ARM64
+#define CONFIG_PHYS_64BIT
+#define CONFIG_STATIC_RELA
+#endif
+
 #endif
arch/arm/include/asm/gic.h +42 -7

61 lines not on this page · raw message

arch/arm/include/asm/global_data.h +5 -1
index e126436..60e8726 100644
@@ -47,6 +47,10 @@ struct arch_global_data {
 
 #include <asm-generic/global_data.h>
 
-#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r9")
+#ifdef CONFIG_ARM64
+#define DECLARE_GLOBAL_DATA_PTR		register volatile gd_t *gd asm ("x18")
+#else
+#define DECLARE_GLOBAL_DATA_PTR		register volatile gd_t *gd asm ("r9")
+#endif
 
 #endif /* __ASM_GBL_DATA_H */
arch/arm/include/asm/io.h +9 -6
index 1fbc531..6a1f05a 100644
@@ -75,42 +75,45 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 #define __arch_putw(v,a)		(*(volatile unsigned short *)(a) = (v))
 #define __arch_putl(v,a)		(*(volatile unsigned int *)(a) = (v))
 
-extern inline void __raw_writesb(unsigned int addr, const void *data, int bytelen)
+extern inline void __raw_writesb(unsigned long addr, const void *data,
+				 int bytelen)
 {
 	uint8_t *buf = (uint8_t *)data;
 	while(bytelen--)
 		__arch_putb(*buf++, addr);
 }
 
-extern inline void __raw_writesw(unsigned int addr, const void *data, int wordlen)
+extern inline void __raw_writesw(unsigned long addr, const void *data,
+				 int wordlen)
 {
 	uint16_t *buf = (uint16_t *)data;
 	while(wordlen--)
 		__arch_putw(*buf++, addr);
 }
 
-extern inline void __raw_writesl(unsigned int addr, const void *data, int longlen)
+extern inline void __raw_writesl(unsigned long addr, const void *data,
+				 int longlen)
 {
 	uint32_t *buf = (uint32_t *)data;
 	while(longlen--)
 		__arch_putl(*buf++, addr);
 }
 
-extern inline void __raw_readsb(unsigned int addr, void *data, int bytelen)
+extern inline void __raw_readsb(unsigned long addr, void *data, int bytelen)
 {
 	uint8_t *buf = (uint8_t *)data;
 	while(bytelen--)
 		*buf++ = __arch_getb(addr);
 }
 
-extern inline void __raw_readsw(unsigned int addr, void *data, int wordlen)
+extern inline void __raw_readsw(unsigned long addr, void *data, int wordlen)
 {
 	uint16_t *buf = (uint16_t *)data;
 	while(wordlen--)
 		*buf++ = __arch_getw(addr);
 }
 
-extern inline void __raw_readsl(unsigned int addr, void *data, int longlen)
+extern inline void __raw_readsl(unsigned long addr, void *data, int longlen)
 {
 	uint32_t *buf = (uint32_t *)data;
 	while(longlen--)
arch/arm/include/asm/macro.h +53 -0

58 lines not on this page · raw message

arch/arm/include/asm/posix_types.h +10 -0
index c412486..9ba9add 100644
@@ -13,6 +13,8 @@
 #ifndef __ARCH_ARM_POSIX_TYPES_H
 #define __ARCH_ARM_POSIX_TYPES_H
 
+#include <config.h>
+
 /*
  * This file is generally used by user-level software, so you need to
  * be a little careful about namespace pollution etc.  Also, we cannot
@@ -28,9 +30,17 @@ typedef int			__kernel_pid_t;
 typedef unsigned short		__kernel_ipc_pid_t;
 typedef unsigned short		__kernel_uid_t;
 typedef unsigned short		__kernel_gid_t;
+
+#ifdef	CONFIG_ARM64
+typedef unsigned long		__kernel_size_t;
+typedef long			__kernel_ssize_t;
+typedef long			__kernel_ptrdiff_t;
+#else	/* CONFIG_ARM64 */
 typedef unsigned int		__kernel_size_t;
 typedef int			__kernel_ssize_t;
 typedef int			__kernel_ptrdiff_t;
+#endif	/* CONFIG_ARM64 */
+
 typedef long			__kernel_time_t;
 typedef long			__kernel_suseconds_t;
 typedef long			__kernel_clock_t;
arch/arm/include/asm/proc-armv/ptrace.h +21 -0
index a060ee6..21aef58 100644
@@ -10,6 +10,25 @@
 #ifndef __ASM_PROC_PTRACE_H
 #define __ASM_PROC_PTRACE_H
 
+#ifdef CONFIG_ARM64
+
+#define PCMASK		0
+
+#ifndef __ASSEMBLY__
+
+/*
+ * This struct defines the way the registers are stored
+ * on the stack during an exception.
+ */
+struct pt_regs {
+	unsigned long elr;
+	unsigned long regs[31];
+};
+
+#endif	/* __ASSEMBLY__ */
+
+#else	/* CONFIG_ARM64 */
+
 #define USR26_MODE	0x00
 #define FIQ26_MODE	0x01
 #define IRQ26_MODE	0x02
@@ -104,4 +123,6 @@ static inline int valid_user_regs(struct pt_regs *regs)
 
 #endif	/* __ASSEMBLY__ */
 
+#endif	/* CONFIG_ARM64 */
+
 #endif
arch/arm/include/asm/proc-armv/system.h +58 -1

71 lines not on this page · raw message

arch/arm/include/asm/system.h +84 -0

100 lines not on this page · raw message

arch/arm/include/asm/types.h +4 -0
index 71dc049..2326420 100644
@@ -39,7 +39,11 @@ typedef unsigned int u32;
 typedef signed long long s64;
 typedef unsigned long long u64;
 
+#ifdef	CONFIG_ARM64
+#define BITS_PER_LONG 64
+#else	/* CONFIG_ARM64 */
 #define BITS_PER_LONG 32
+#endif	/* CONFIG_ARM64 */
 
 /* Dma addresses are 32-bits wide.  */
 
arch/arm/include/asm/u-boot.h +4 -0
index 2b5fce8..cb81232 100644
@@ -44,6 +44,10 @@ typedef struct bd_info {
 #endif /* !CONFIG_SYS_GENERIC_BOARD */
 
 /* For image.h:image_check_target_arch() */
+#ifndef CONFIG_ARM64
 #define IH_ARCH_DEFAULT IH_ARCH_ARM
+#else
+#define IH_ARCH_DEFAULT IH_ARCH_ARM64
+#endif
 
 #endif	/* _U_BOOT_H_ */
arch/arm/include/asm/unaligned.h +1 -1
index 44593a8..0a228fb 100644
@@ -8,7 +8,7 @@
 /*
  * Select endianness
  */
-#ifndef __ARMEB__
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 #define get_unaligned	__get_unaligned_le
 #define put_unaligned	__put_unaligned_le
 #else
arch/arm/lib/Makefile +17 -3
index 679f19a..321997c 100644
@@ -17,14 +17,22 @@ lib-y	+= _umodsi3.o
 lib-y	+= div0.o
 endif
 
-obj-y += crt0.o
+ifdef CONFIG_ARM64
+obj-y	+= crt0_64.o
+else
+obj-y	+= crt0.o
+endif
 
 ifndef CONFIG_SPL_BUILD
-obj-y += relocate.o
+ifdef CONFIG_ARM64
+obj-y	+= relocate_64.o
+else
+obj-y	+= relocate.o
+endif
 ifndef CONFIG_SYS_GENERIC_BOARD
 obj-y	+= board.o
 endif
-obj-y += sections.o
+obj-y	+= sections.o
 
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
@@ -35,11 +43,17 @@ else
 obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
 endif
 
+ifdef CONFIG_ARM64
+obj-y	+= interrupts_64.o
+else
 obj-y	+= interrupts.o
+endif
 obj-y	+= reset.o
 
 obj-y	+= cache.o
+ifndef CONFIG_ARM64
 obj-y	+= cache-cp15.o
+endif
 
 # For EABI conformant tool chains, provide eabi_compat()
 ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
arch/arm/lib/board.c +6 -1
index 9c72a53..b770e25 100644
@@ -344,7 +344,7 @@ void board_init_f(ulong bootflag)
 
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
 	/* reserve TLB table */
-	gd->arch.tlb_size = 4096 * 4;
+	gd->arch.tlb_size = PGTABLE_SIZE;
 	addr -= gd->arch.tlb_size;
 
 	/* round down to next 64 kB limit */
@@ -419,6 +419,7 @@ void board_init_f(ulong bootflag)
 	}
 #endif
 
+#ifndef CONFIG_ARM64
 	/* setup stackpointer for exeptions */
 	gd->irq_sp = addr_sp;
 #ifdef CONFIG_USE_IRQ
@@ -431,6 +432,10 @@ void board_init_f(ulong bootflag)
 
 	/* 8-byte alignment for ABI compliance */
 	addr_sp &= ~0x07;
+#else	/* CONFIG_ARM64 */
+	/* 16-byte alignment for ABI compliance */
+	addr_sp &= ~0x0f;
+#endif	/* CONFIG_ARM64 */
 #else
 	addr_sp += 128;	/* leave 32 words for abort-stack   */
 	gd->irq_sp = addr_sp;
arch/arm/lib/bootm.c +24 -0
index f476a89..77f1a5c 100644
@@ -196,6 +196,14 @@ static void do_nonsec_virt_switch(void)
 		debug("entered non-secure state\n");
 #endif
 #endif
+
+#ifdef CONFIG_ARM64
+	smp_kick_all_cpus();
+	armv8_switch_to_el2();
+#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
+	armv8_switch_to_el1();
+#endif
+#endif
 }
 
 /* Subcommand: PREP */
@@ -240,6 +248,21 @@ static void boot_prep_linux(bootm_headers_t *images)
 /* Subcommand: GO */
 static void boot_jump_linux(bootm_headers_t *images, int flag)
 {
+#ifdef CONFIG_ARM64
+	void (*kernel_entry)(void *fdt_addr);
+	int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
+
+	kernel_entry = (void (*)(void *fdt_addr))images->ep;
+
+	debug("## Transferring control to Linux (at address %lx)...\n",
+		(ulong) kernel_entry);
+	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
+
+	announce_and_cleanup(fake);
+
+	if (!fake)
+		kernel_entry(images->ft_addr);
+#else
 	unsigned long machid = gd->bd->bi_arch_number;
 	char *s;
 	void (*kernel_entry)(int zero, int arch, uint params);
@@ -266,6 +289,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 
 	if (!fake)
 		kernel_entry(0, machid, r2);
+#endif
 }
 
 /* Main Entry point for arm bootm implementation
arch/arm/lib/crt0_64.S new file +113 -0

113 lines not on this page · raw message

arch/arm/lib/interrupts_64.c new file +120 -0

120 lines not on this page · raw message

arch/arm/lib/relocate_64.S new file +58 -0

58 lines not on this page · raw message

common/image.c +1 -0
index b0ae58f..4145354 100644
@@ -81,6 +81,7 @@ static const table_entry_t uimage_arch[] = {
 	{	IH_ARCH_NDS32,		"nds32",	"NDS32",	},
 	{	IH_ARCH_OPENRISC,	"or1k",		"OpenRISC 1000",},
 	{	IH_ARCH_SANDBOX,	"sandbox",	"Sandbox",	},
+	{	IH_ARCH_ARM64,		"arm64",	"AArch64",	},
 	{	-1,			"",		"",		},
 };
 
doc/README.arm64 new file +46 -0

46 lines not on this page · raw message

examples/standalone/stubs.c +15 -0
index 5d2ab56..32a19ce 100644
@@ -39,6 +39,20 @@ gd_t *global_data;
 "	bctr\n"				\
 	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
 #elif defined(CONFIG_ARM)
+#ifdef CONFIG_ARM64
+/*
+ * x18 holds the pointer to the global_data, x9 is a call-clobbered
+ * register
+ */
+#define EXPORT_FUNC(x) \
+	asm volatile (			\
+"	.globl " #x "\n"		\
+#x ":\n"				\
+"	ldr	x9, [x18, %0]\n"		\
+"	ldr	x9, [x9, %1]\n"		\
+"	br	x9\n"		\
+	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "x9");
+#else
 /*
  * r9 holds the pointer to the global_data, ip is a call-clobbered
  * register
@@ -50,6 +64,7 @@ gd_t *global_data;
 "	ldr	ip, [r9, %0]\n"		\
 "	ldr	pc, [ip, %1]\n"		\
 	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
+#endif
 #elif defined(CONFIG_MIPS)
 /*
  * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
include/image.h +1 -0
index ee6eb8d..7de2bb2 100644
@@ -156,6 +156,7 @@ struct lmb;
 #define IH_ARCH_SANDBOX		19	/* Sandbox architecture (test only) */
 #define IH_ARCH_NDS32	        20	/* ANDES Technology - NDS32  */
 #define IH_ARCH_OPENRISC        21	/* OpenRISC 1000  */
+#define IH_ARCH_ARM64		22	/* ARM64	*/
 
 /*
  * Image Types
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v16 8/10 arm64: generic board support

From: David Feng <[email protected]>

---
 common/board_f.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
common/board_f.c +13 -7
index f0664bc..d918e4b 100644
@@ -462,7 +462,7 @@ static int reserve_round_4k(void)
 static int reserve_mmu(void)
 {
 	/* reserve TLB table */
-	gd->arch.tlb_size = 4096 * 4;
+	gd->arch.tlb_size = PGTABLE_SIZE;
 	gd->relocaddr -= gd->arch.tlb_size;
 
 	/* round down to next 64 kB limit */
@@ -614,7 +614,7 @@ static int reserve_stacks(void)
 	 * TODO(sjg at chromium.org): Perhaps create arch_reserve_stack()
 	 * to handle this and put in arch/xxx/lib/stack.c
 	 */
-# ifdef CONFIG_ARM
+# if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
 #  ifdef CONFIG_USE_IRQ
 	gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
 	debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
@@ -811,11 +811,6 @@ static int mark_bootstage(void)
 }
 
 static init_fnc_t init_sequence_f[] = {
-#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
-		!defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
-		!defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
-	zero_global_data,
-#endif
 #ifdef CONFIG_SANDBOX
 	setup_ram_buf,
 #endif
@@ -1009,6 +1004,17 @@ void board_init_f(ulong boot_flags)
 	gd = &data;
 #endif
 
+	/*
+	 * Clear global data before it is accessed at debug print
+	 * in initcall_run_list. Otherwise the debug print probably
+	 * get the wrong vaule of gd->have_console.
+	 */
+#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
+		!defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
+		!defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
+	zero_global_data();
+#endif
+
 	gd->flags = boot_flags;
 
 	if (initcall_run_list(init_sequence_f))
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v16 9/10 arm64: board support of vexpress_aemv8a

From: David Feng <[email protected]>

---
 board/armltd/vexpress64/Makefile     |    8 ++
 board/armltd/vexpress64/vexpress64.c |   56 ++++++++++
 boards.cfg                           |    1 +
 include/configs/vexpress_aemv8a.h    |  189 ++++++++++++++++++++++++++++++++++
 4 files changed, 254 insertions(+)
 create mode 100644 board/armltd/vexpress64/Makefile
 create mode 100644 board/armltd/vexpress64/vexpress64.c
 create mode 100644 include/configs/vexpress_aemv8a.h
board/armltd/vexpress64/Makefile new file +8 -0
new file mode 100644
index 0000000..e009141
@@ -0,0 +1,8 @@
+#
+# (C) Copyright 2000-2004
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y	:= vexpress64.o
board/armltd/vexpress64/vexpress64.c new file +56 -0

56 lines not on this page · raw message

boards.cfg +1 -0
index b662149..7572f88 100644
@@ -395,6 +395,7 @@ Active  arm         pxa            -           -               vpac270
 Active  arm         pxa            -           icpdas          lp8x4x              lp8x4x                               -                                                                                                                                 Sergey Yanovich <[email protected]>
 Active  arm         pxa            -           toradex         -                   colibri_pxa270                       -                                                                                                                                 Marek Vasut <[email protected]>
 Active  arm         sa1100         -           -               -                   jornada                              -                                                                                                                                 Kristoffer Ericson <[email protected]>
+Active  arm         armv8          -           armltd          vexpress64          vexpress_aemv8a                      vexpress_aemv8a:ARM64                                                                                                             David Feng <[email protected]>
 Active  avr32       at32ap         at32ap700x  atmel           -                   atngw100                             -                                                                                                                                 Haavard Skinnemoen <[email protected]>
 Active  avr32       at32ap         at32ap700x  atmel           -                   atngw100mkii                         -                                                                                                                                 Andreas Bie?mann <[email protected]>
 Active  avr32       at32ap         at32ap700x  atmel           atstk1000           atstk1002                            -                                                                                                                                 Haavard Skinnemoen <[email protected]>
include/configs/vexpress_aemv8a.h new file +189 -0

189 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v16 10/10 arm64: MAKEALL, filter armv8 boards from LIST_arm

From: David Feng <[email protected]>

---
 MAKEALL |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
MAKEALL +11 -1
index a74f0fc..562071a 100755
@@ -381,6 +381,12 @@ LIST_ARM11="$(targets_by_cpu arm1136)	\
 LIST_ARMV7="$(targets_by_cpu armv7)"
 
 #########################################################################
+## ARMV8 Systems
+#########################################################################
+
+LIST_ARMV8="$(targets_by_cpu armv8)"
+
+#########################################################################
 ## AT91 Systems
 #########################################################################
 
@@ -404,7 +410,11 @@ LIST_spear="$(targets_by_soc spear)"
 ## ARM groups
 #########################################################################
 
-LIST_arm="$(targets_by_arch arm)"
+LIST_arm="$(targets_by_arch arm |		\
+	for ARMV8_TARGET in $LIST_ARMV8;	\
+		do sed "/$ARMV8_TARGET/d";	\
+	done)					\
+"
 
 #########################################################################
 ## MIPS Systems		(default = big endian)
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v16 4/10 arm64: Add tool to statically apply RELA relocations

In reply to fenghua at phytium.com.cn
Quoted 195 lines · On Sat, Dec 14, 2013 at 9:17 AM, <[email protected]> wrote:

From: Scott Wood <[email protected]>

ARM64 uses the newer RELA-style relocations rather than the older REL. RELA relocations have an addend in the relocation struct, rather than expecting the loader to read a value from the location to be updated.

While this is beneficial for ordinary program loading, it's problematic for U-Boot because the location to be updated starts out with zero, rather than a pre-relocation value. Since we need to be able to run C code before relocation, we need a tool to apply the relocations at build time.

In theory this tool is applicable to other newer architectures (mainly 64-bit), but currently the only relocations it supports are for arm64, and it assumes a 64-bit little-endian target. If the latter limitation is ever to be changed, we'll need a way to tell the tool what format the image is in. Eventually this may be replaced by a tool that uses libelf or similar and operates directly on the ELF file. I've written some code for such an approach but libelf does not make it easy to poke addresses by memory address (rather than by section), and I was hesitant to write code to manually parse the program headers and do the update outside of libelf (or to iterate over sections) -- especially since it wouldn't get test coverage on things like binaries with multiple PT_LOAD segments. This should be good enough for now to let the manual relocation stuff be removed from the arm64 patches.

---
 Makefile              |   12 ++++
 tools/Makefile        |    6 ++
 tools/relocate-rela.c |  189 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+)
 create mode 100644 tools/relocate-rela.c
Makefile +12 -0
index 7310c4e..4a8e8c5 100644
@@ -334,6 +334,17 @@ else
 BOARD_SIZE_CHECK =
 endif
 
+# Statically apply RELA-style relocations (currently arm64 only)
+ifneq ($(CONFIG_STATIC_RELA),)
+# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base
+DO_STATIC_RELA = \
+       start=$$($(NM) $(1) | grep __rel_dyn_start | cut -f 1 -d ' '); \
+       end=$$($(NM) $(1) | grep __rel_dyn_end | cut -f 1 -d ' '); \
+       $(obj)tools/relocate-rela $(2) $(3) $$start $$end
+else
+DO_STATIC_RELA =
+endif
+
 # Always append ALL so that arch config.mk's can add custom ones
 ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map
 
@@ -376,6 +387,7 @@ $(obj)u-boot.srec:  $(obj)u-boot
 
 $(obj)u-boot.bin:      $(obj)u-boot
                $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
+               $(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
                $(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr:      $(obj)u-boot
tools/Makefile +6 -0
index 14d94e3..6d40398 100644
@@ -59,6 +59,7 @@ BIN_FILES-$(CONFIG_NETCONSOLE) += ncb$(SFX)
 BIN_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
 BIN_FILES-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
 BIN_FILES-y += proftool(SFX)
+BIN_FILES-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
 
 # Source files which exist outside the tools directory
 EXT_OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += common/env_embedded.o
@@ -84,6 +85,7 @@ NOPED_OBJ_FILES-y += os_support.o
 NOPED_OBJ_FILES-y += pblimage.o
 NOPED_OBJ_FILES-y += proftool.o
 NOPED_OBJ_FILES-y += ublimage.o
+NOPED_OBJ_FILES-y += relocate-rela.o
 OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc.o
 OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
 OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
@@ -250,6 +252,10 @@ $(obj)kwboot$(SFX): $(obj)kwboot.o
        $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
        $(HOSTSTRIP) $@
 
+$(obj)relocate-rela$(SFX): $(obj)relocate-rela.o
+       $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+       $(HOSTSTRIP) $@
+
 # Some of the tool objects need to be accessed from outside the tools directory
 $(obj)%.o: $(SRCTREE)/common/%.c
        $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
tools/relocate-rela.c new file +93 -0
new file mode 100644
index 0000000..93b4c39
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2013 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+ BSD-2-Clause
+ *
+ * 64-bit and little-endian target only until we need to support a different
+ * arch that needs this.
+ */
+
+#include <elf.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef R_AARCH64_RELATIVE
+#define R_AARCH64_RELATIVE     1027
+#endif
+
+static const bool debug_en;
+
+static void debug(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       if (debug_en)
+               vprintf(fmt, args);
+}
+
+static bool supported_rela(Elf64_Rela *rela)
+{
+       uint64_t mask = 0xffffffffULL; /* would be different on 32-bit */
+       uint32_t type = rela->r_info & mask;
+
+       switch (type) {
+#ifdef R_AARCH64_RELATIVE
+       case R_AARCH64_RELATIVE:
+               return true;
+#endif
+       default:
+               fprintf(stderr, "warning: unsupported relocation type %"
+                               PRIu32 " at %" PRIx64 "\n",
+                       type, rela->r_offset);
+
+               return false;
+       }
+}
+
+static inline uint64_t swap64(uint64_t val)
+{
+       return ((val >> 56) & 0x00000000000000ffULL) |
+              ((val >> 40) & 0x000000000000ff00ULL) |
+              ((val >> 24) & 0x0000000000ff0000ULL) |
+              ((val >>  8) & 0x00000000ff000000ULL) |
+              ((val <<  8) & 0x000000ff00000000ULL) |
+              ((val << 24) & 0x0000ff0000000000ULL) |
+              ((val << 40) & 0x00ff000000000000ULL) |
+              ((val << 56) & 0xff00000000000000ULL);
+}
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint64_t be64(uint64_t val)
+{
+       return swap64(val);
+}
+
+static inline uint64_t le64(uint64_t val)
+{
+       return val;
+}
+#else
+static inline uint64_t le64(uint64_t val)
+{
+       return swap64(val);
+}
+
+static inline uint64_t be64(uint64_t val)
+{
+       return val;
+}
+#endif
+
+static bool read_num(const char *str, uint64_t *num)
+{
+       char *endptr;
+       *num = strtoull(str, &endptr, 16);
+       return str[0] && !endptr[0];
+}
+

tools/relocate-rela.c line 103

Quoted 10 lines
tools/relocate-rela.c new file +10 -0
+int main(int argc, char **argv)
+{
+       FILE *f;
+       int i, num;
+       uint64_t rela_start, rela_end, text_base;
+
+       if (argc != 5) {
+               fprintf(stderr, "Statically apply ELF rela relocations\n");
+               fprintf(stderr, "Usage: %s <bin file> <text base> " \
+                               "<rela start> <rela end>\n", argv[0]);

Try to avoid unnecessary line continuations at fprintf

Signature · 8 lines
Thanks,
Jagan.
--------
Jagannadha Sutradharudu Teki,
E: jagannadh.teki at gmail.com, P: +91-9676773388
Engineer - System Software Hacker
U-boot - SPI Custodian and Zynq APSOC
Ln: http://www.linkedin.com/in/jaganteki
#12 lore raw

PATCH v16 4/10 arm64: Add tool to statically apply RELA relocations

Quoted 3 lines · Jagan Teki
Quoted 2 lines · On Sat, Dec 14, 2013 at 9:17 AM, <[email protected]> wrote:

From: Scott Wood <[email protected]>

[snip]

Quoted 6 lines

tools/relocate-rela.c line 103

Quoted 4 lines
tools/relocate-rela.c new file +4 -0
+       if (argc != 5) {
+               fprintf(stderr, "Statically apply ELF rela relocations\n");
+               fprintf(stderr, "Usage: %s <bin file> <text base> " \
+                               "<rela start> <rela end>\n", argv[0]);

Try to avoid unnecessary line continuations at fprintf

FWIW, it wasn't like that it in my original patch. I'm guessing he changed it due to checkpatch output; checkpatch recognizes printf() but not fprintf(). It should probably be changed to recognize *printf(), just as it recognizes *printk().

-Scott

#13 lore raw

PATCH v16 2/10 cmd_pxe: remove compiling warnings

In reply to fenghua at phytium.com.cn
Quoted 21 lines · On Sat, Dec 14, 2013 at 9:17 AM, <[email protected]> wrote:

From: David Feng <[email protected]>

---
 common/cmd_pxe.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/cmd_pxe.c +1 -1
index db6b156..c27ec35 100644
@@ -59,7 +59,7 @@ static int format_mac_pxe(char *outbuf, size_t outbuf_len)
        uchar ethaddr[6];
 
        if (outbuf_len < 21) {
-               printf("outbuf is too small (%d < 21)\n", outbuf_len);
+               printf("outbuf is too small (%zd < 21)\n", outbuf_len);
 
                return -EINVAL;
        }

common/cmd_pxe.c static int get_bootfile_path(const char *file_path, char *bootfile_path, · line 107

Quoted 6 lines
common/cmd_pxe.c +1 -1
@@ -103,7 +103,7 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
        path_len = (last_slash - bootfile) + 1;
 
        if (bootfile_path_size < path_len) {
-               printf("bootfile_path too small. (%d < %d)\n",
+               printf("bootfile_path too small. (%zd < %zd)\n",
                                bootfile_path_size, path_len);

CHECK: Alignment should match open parenthesis
#40: FILE: common/cmd_pxe.c:107:
+ printf("bootfile_path too small. (%zd < %zd)\n",

                 bootfile_path_size, path_len);
Signature · 8 lines
Thanks,
Jagan.
--------
Jagannadha Sutradharudu Teki,
E: [email protected], P: +91-9676773388
Engineer - System Software Hacker
U-boot - SPI Custodian and Zynq APSOC
Ln: http://www.linkedin.com/in/jaganteki
author
#14 lore raw

PATCH v16 2/10 cmd_pxe: remove compiling warnings

Quoted 33 lines · On Sat, Dec 14, 2013 at 9:17 AM, <[email protected]> wrote:
Quoted 21 lines

From: David Feng <[email protected]>

---
 common/cmd_pxe.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/cmd_pxe.c +1 -1
index db6b156..c27ec35 100644
@@ -59,7 +59,7 @@ static int format_mac_pxe(char *outbuf, size_t outbuf_len)
        uchar ethaddr[6];
 
        if (outbuf_len < 21) {
-               printf("outbuf is too small (%d < 21)\n", outbuf_len);
+               printf("outbuf is too small (%zd < 21)\n", outbuf_len);
 
                return -EINVAL;
        }

common/cmd_pxe.c static int get_bootfile_path(const char *file_path, char *bootfile_path, · line 107

Quoted 6 lines
common/cmd_pxe.c +1 -1
@@ -103,7 +103,7 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
        path_len = (last_slash - bootfile) + 1;
 
        if (bootfile_path_size < path_len) {
-               printf("bootfile_path too small. (%d < %d)\n",
+               printf("bootfile_path too small. (%zd < %zd)\n",
                                bootfile_path_size, path_len);

CHECK: Alignment should match open parenthesis
#40: FILE: common/cmd_pxe.c:107:
+ printf("bootfile_path too small. (%zd < %zd)\n",

Quoted 1 line
                 bootfile_path_size, path_len);

Yes, this should be fixed. I only replace %d with %z and did not notice the alignment.

#15 lore raw

v16 cover arm64 patch

In reply to fenghua at phytium.com.cn

Hi fenghua at phytium.com.cn,

Quoted 6 lines · fenghua at phytium.com.cn

From: David Feng <[email protected]>

Changes for v16:
- make the patches work with latest recently u-boot. add rela relocation type to OBJCFLAGS definition at arm/config.mk.

The series applies well and builds armv8 targets well if I set the CROSS_COMPILE prefix to a 64-bit toolchain. However, if I use a 32-bit toolchain prefix,

1) it still tries to build armv8 target, and fails understandably;

2) it causes the following boards to fail building:

trats2 snow smdk5250 vexpress_aemv8a smdkv310 origen s5pc210_universal trats s5p_goni smdkc100 smdk5420 arndale

All with the same error, starting with:

/home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h:45:1:
error: unknown type name '__le64' /home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h: In function '__cpu_to_le64p':
/home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h:47:18:
error: '__le64' undeclared (first use in this function) /home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h:47:18:
note: each undeclared identifier is reported only once for each function it appears in /home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h: At top level:
/home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h:49:1:
error: unknown type name '__le64' /home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h:53:1:
error: unknown type name '__le32' /home/albert/src/u-boot-arm/include/linux/byteorder/little_endian.h: In function '__cpu_to_le32p':

Etc.

Can you look into it on your side and determine what causes this? I don't necessarily need a v16 series; a bugfix patch is ok.

Amicalement,

Signature · 1 line
Albert.
#16 lore raw

v16 cover arm64 patch

Hi, Albtert:
How to download u-boot source code with arm64 patch code. Such as :
Include arch/arm/cpu/armv8 directory.

I used "git clone git://www.denx.de/git/u-boot.git" to download source code.
But not find arm64 patch code in the downloaded source code.

Best wishes,

#17 lore raw

v16 cover arm64 patch

Hi TigerLiu at viatech.com.cn,

Quoted 8 lines · On Fri, 10 Jan 2014 09:58:11 +0800, <[email protected]> wrote:

Hi, Albtert:
How to download u-boot source code with arm64 patch code. Such as :
Include arch/arm/cpu/armv8 directory.

I used "git clone git://www.denx.de/git/u-boot.git" to download source code.
But not find arm64 patch code in the downloaded source code.

This is normal as the series is not yet applied to the ARM repo, let alone the main repo.

I have just finished testing the series with the corrective patch from Tom re: the 32-bit boards failing to build, and another patch from me which prevents building 32-bit and 64-bit targets in a single 'MAKEALL -a' command, as no toolchain currently exists that can build both types of targets.

Quoted 1 line

Best wishes,

Amicalement,

Signature · 1 line
Albert.