mirror of
				https://github.com/smaeul/u-boot.git
				synced 2025-11-04 05:50:17 +00:00 
			
		
		
		
	Usually ARMv8 platforms allow unaligned access for Normal memory. But
some chips might not allow it by default, having SCTLR.A bit set to 1
before U-Boot execution. One such example is Exynos850 SoC. As
allow_unaligned() is not implemented for ARMv8 at the moment, its __weak
implementation is used, which does nothing. That might lead to unaligned
access abort, for example when running EFI selftest. Fix that by
implementing allow_unaligned() for ARMv8.
The issue was found when running EFI selftest on E850-96 board
(Exynos850 based):
    => bootefi selftest $fdtcontroladdr
    ...
    Executing 'HII database protocols'
    "Synchronous Abort" handler, esr 0x96000021, far 0xbaac0991
    ...
    resetting ...
Unaligned abort happens in u16_strnlen(), which is called from
efi_hii_sibt_string_ucs2_block_next():
    u16_strlen(blk->string_text)
where 'blk' type is struct efi_hii_sibt_string_ucs2_block. Because this
struct is packed, doing "->string_text" makes 'blk' address incremented
by 1 byte, which makes it unaligned. Although allow_unaligned() was
called in efi_init_early() before EFI selftest execution, it wasn't
implemented for ARMv8 CPUs, so data abort happened.
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
		
	
			
		
			
				
	
	
		
			102 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0+
 | 
						|
/*
 | 
						|
 * (C) Copyright 2008 Texas Insturments
 | 
						|
 *
 | 
						|
 * (C) Copyright 2002
 | 
						|
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 | 
						|
 * Marius Groeger <mgroeger@sysgo.de>
 | 
						|
 *
 | 
						|
 * (C) Copyright 2002
 | 
						|
 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
 | 
						|
 */
 | 
						|
 | 
						|
#include <command.h>
 | 
						|
#include <cpu_func.h>
 | 
						|
#include <irq_func.h>
 | 
						|
#include <asm/cache.h>
 | 
						|
#include <asm/system.h>
 | 
						|
#include <asm/secure.h>
 | 
						|
#include <linux/compiler.h>
 | 
						|
 | 
						|
/*
 | 
						|
 * sdelay() - simple spin loop.
 | 
						|
 *
 | 
						|
 * Will delay execution by roughly (@loops * 2) cycles.
 | 
						|
 * This is necessary to be used before timers are accessible.
 | 
						|
 *
 | 
						|
 * A value of "0" will results in 2^64 loops.
 | 
						|
 */
 | 
						|
void sdelay(unsigned long loops)
 | 
						|
{
 | 
						|
	__asm__ volatile ("1:\n" "subs %0, %0, #1\n"
 | 
						|
			  "b.ne 1b" : "=r" (loops) : "0"(loops) : "cc");
 | 
						|
}
 | 
						|
 | 
						|
void __weak board_cleanup_before_linux(void){}
 | 
						|
 | 
						|
int cleanup_before_linux(void)
 | 
						|
{
 | 
						|
	/*
 | 
						|
	 * this function is called just before we call linux
 | 
						|
	 * it prepares the processor for linux
 | 
						|
	 *
 | 
						|
	 * disable interrupt and turn off caches etc ...
 | 
						|
	 */
 | 
						|
 | 
						|
	board_cleanup_before_linux();
 | 
						|
 | 
						|
	disable_interrupts();
 | 
						|
 | 
						|
	if (IS_ENABLED(CONFIG_CMO_BY_VA_ONLY)) {
 | 
						|
		/*
 | 
						|
		 * Disable D-cache.
 | 
						|
		 */
 | 
						|
		dcache_disable();
 | 
						|
	} else {
 | 
						|
		/*
 | 
						|
		 * Turn off I-cache and invalidate it
 | 
						|
		 */
 | 
						|
		icache_disable();
 | 
						|
		invalidate_icache_all();
 | 
						|
 | 
						|
		/*
 | 
						|
		 * turn off D-cache
 | 
						|
		 * dcache_disable() in turn flushes the d-cache and disables
 | 
						|
		 * MMU
 | 
						|
		 */
 | 
						|
		dcache_disable();
 | 
						|
		invalidate_dcache_all();
 | 
						|
	}
 | 
						|
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_ARMV8_PSCI
 | 
						|
static void relocate_secure_section(void)
 | 
						|
{
 | 
						|
#ifdef CONFIG_ARMV8_SECURE_BASE
 | 
						|
	size_t sz = __secure_end - __secure_start;
 | 
						|
 | 
						|
	memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz);
 | 
						|
	flush_dcache_range(CONFIG_ARMV8_SECURE_BASE,
 | 
						|
			   CONFIG_ARMV8_SECURE_BASE + sz + 1);
 | 
						|
	invalidate_icache_all();
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
void armv8_setup_psci(void)
 | 
						|
{
 | 
						|
	if (current_el() != 3)
 | 
						|
		return;
 | 
						|
 | 
						|
	relocate_secure_section();
 | 
						|
	secure_ram_addr(psci_setup_vectors)();
 | 
						|
	secure_ram_addr(psci_arch_init)();
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
void allow_unaligned(void)
 | 
						|
{
 | 
						|
	set_sctlr(get_sctlr() & ~CR_A);
 | 
						|
}
 |