From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE0E7C433F5 for ; Fri, 14 Jan 2022 11:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hU7DD2e+o2/BkqP8xSLybGJuK+t2CFhPU8Zk5q1KFbs=; b=Dxw9mZ2OWCALJJ 0OYQOBxvuLWPFkNJ3CPEqhr9UaGyCtwYVFDXcscxRaUAcrQMpK6k6oe2vRJ2O74vtKOVtD0jLV6c2 aYQNGPgmKKz0YYJKJM7Z/F9wMJQix92Z0d6Y3lTPbT/s2DK3cQ1nAEkP1L3KMKbMAB8VHvVb3WGoM OdYsB/nn8RJn8x5r4Vxxbrl9bEQ4af5XDdoKm9xBgJf45wL9h6G3KAq4Mn6dg6N52EWXSzgchjwzC +1IEODlmYuRgvFsMZb7hukXhZI+RquFahvftgrYM+AMge+5I3c0VwkskVaq+Z0lbxU1V0zoJc6Pd/ GYIc2Ebah5QQ0fvpRFow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8KIX-008p3k-Gw; Fri, 14 Jan 2022 10:59:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8KGi-008o5v-Dl for linux-arm-kernel@lists.infradead.org; Fri, 14 Jan 2022 10:57:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1B5AC11B3; Fri, 14 Jan 2022 02:57:16 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A2B43F766; Fri, 14 Jan 2022 02:57:14 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: andre.przywara@arm.com, Jaxson.Han@arm.com, mark.rutland@arm.com, robin.murphy@arm.com, vladimir.murzin@arm.com, Wei.Chen@arm.com Subject: [bootwrapper PATCH v2 08/13] Announce boot-wrapper mode / exception level Date: Fri, 14 Jan 2022 10:56:48 +0000 Message-Id: <20220114105653.3003399-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220114105653.3003399-1-mark.rutland@arm.com> References: <20220114105653.3003399-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220114_025716_591907_D55E01FB X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When something goes wrong within the boot-wrapper, it can be very helpful to know where we started from. Add an arch_announce() function to log this early in the boot process. More information can be added here in future. This is logged ot the serial console as: | Boot-wrapper v0.2 | Entered at EL3 Signed-off-by: Mark Rutland --- Makefile.am | 2 +- arch/aarch32/include/asm/cpu.h | 9 +++++++++ arch/aarch32/init.c | 30 ++++++++++++++++++++++++++++++ arch/aarch64/init.c | 19 +++++++++++++++++++ common/init.c | 6 +++++- common/platform.c | 24 ++++++++++++++---------- include/platform.h | 1 + 7 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 arch/aarch32/init.c create mode 100644 arch/aarch64/init.c diff --git a/Makefile.am b/Makefile.am index 0651c38..885a77c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,7 +36,7 @@ PSCI_CPU_OFF := 0x84000002 COMMON_SRC := common/ COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o init.o -ARCH_OBJ := boot.o stack.o utils.o +ARCH_OBJ := boot.o stack.o utils.o init.o if BOOTWRAPPER_32 CPPFLAGS += -DBOOTWRAPPER_32 diff --git a/arch/aarch32/include/asm/cpu.h b/arch/aarch32/include/asm/cpu.h index d691c7b..aa72204 100644 --- a/arch/aarch32/include/asm/cpu.h +++ b/arch/aarch32/include/asm/cpu.h @@ -44,6 +44,15 @@ #define sevl() asm volatile ("sev" : : : "memory") #endif +static inline unsigned long read_cpsr(void) +{ + unsigned long cpsr; + asm volatile ("mrs %0, cpsr\n" : "=r" (cpsr)); + return cpsr; +} + +#define read_cpsr_mode() (read_cpsr() & PSR_MODE_MASK) + #define MPIDR "p15, 0, %0, c0, c0, 5" #define ID_PFR1 "p15, 0, %0, c0, c1, 1" #define ICIALLU "p15, 0, %0, c7, c5, 0" diff --git a/arch/aarch32/init.c b/arch/aarch32/init.c new file mode 100644 index 0000000..b29ebb4 --- /dev/null +++ b/arch/aarch32/init.c @@ -0,0 +1,30 @@ +/* + * init.c - common boot-wrapper initialization + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#include + +#include + +static const char *mode_string(void) +{ + switch (read_cpsr_mode()) { + case PSR_MON: + return "PL1"; + case PSR_HYP: + return "PL2 (Non-secure)"; + default: + return ""; + } +} + +void announce_arch(void) +{ + print_string("Entered at "); + print_string(mode_string()); + print_string("\r\n"); +} diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c new file mode 100644 index 0000000..82816e7 --- /dev/null +++ b/arch/aarch64/init.c @@ -0,0 +1,19 @@ +/* + * init.c - common boot-wrapper initialization + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#include +#include + +void announce_arch(void) +{ + unsigned char el = mrs(CurrentEl) >> 2; + + print_string("Entered at EL"); + print_char('0' + el); + print_string("\r\n"); +} diff --git a/common/init.c b/common/init.c index 9c471c9..2600f73 100644 --- a/common/init.c +++ b/common/init.c @@ -11,14 +11,18 @@ static void announce_bootwrapper(void) { - print_string("Boot-wrapper v0.2\r\n\r\n"); + print_string("Boot-wrapper v0.2\r\n"); } +void announce_arch(void); + void cpu_init_bootwrapper(void) { if (this_cpu_logical_id() == 0) { init_uart(); announce_bootwrapper(); + announce_arch(); + print_string("\r\n"); init_platform(); } } diff --git a/common/platform.c b/common/platform.c index 47bf547..80d0562 100644 --- a/common/platform.c +++ b/common/platform.c @@ -31,21 +31,25 @@ #define V2M_SYS(reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) #endif -void print_string(const char *str) +void print_char(char c) { uint32_t flags; - while (*str) { - do - flags = raw_readl(PL011(UARTFR)); - while (flags & PL011_UARTFR_FIFO_FULL); + do { + flags = raw_readl(PL011(UARTFR)); + } while (flags & PL011_UARTFR_FIFO_FULL); + + raw_writel(c, PL011(UARTDR)); - raw_writel(*str++, PL011(UARTDR)); + do { + flags = raw_readl(PL011(UARTFR)); + } while (flags & PL011_UARTFR_BUSY); +} - do - flags = raw_readl(PL011(UARTFR)); - while (flags & PL011_UARTFR_BUSY); - } +void print_string(const char *str) +{ + while (*str) + print_char(*str++); } void init_uart(void) diff --git a/include/platform.h b/include/platform.h index e5248e1..237b481 100644 --- a/include/platform.h +++ b/include/platform.h @@ -9,6 +9,7 @@ #ifndef __PLATFORM_H #define __PLATFORM_H +void print_char(char c); void print_string(const char *str); void init_uart(void); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel