From patchwork Fri Feb 4 07:22:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 12734858 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 1857AC433EF for ; Fri, 4 Feb 2022 07:24:21 +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=Lp75EXef1q1YsIsIZgVSYGq5ZKLrlSm6nrvyEsZglfE=; b=aoFR+vDhKOuVQU F6C33nbco52OgU1CBqfm8B9QiE9WQ6F+PulZXr10eDtKj9+L0Ik2+UHgCZ3KLcMDR4WqZR9w8smCP VRmHp80EsQZcpwx87sJY4XnCELdtgG/KdOfViMDVYgUVIEBMDSmozSap+PoXFJ1T9IvTJ5Hd07jox nknyIElxLzAYHloHLzv/2f+mdnMBbsg+dDLsu7hxItZTX7uzB3negLbo9DNS62kqUcXOYBsVEd9nw 0WWAJ9yYesKmSGkILPj7EvnC2Fc2GLWS2zOQixnJ8CaKTNvhnWvnB2uGcjhPQmVrQlIkEU8uMcFvJ wEha4e+JAK7LqfUGxWSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFsw0-003dVN-OI; Fri, 04 Feb 2022 07:23:08 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFsvl-003dRb-AY for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 07:22:54 +0000 Received: by mail-pj1-x1035.google.com with SMTP id l24-20020a17090aec1800b001b55738f633so7288122pjy.1 for ; Thu, 03 Feb 2022 23:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r1QEEzychUMCoe5U0DSfc5Oq8DaKAXk74KjekRt/xBk=; b=W6qp7cTDZMWu2cumGId9gyog0wkFPZ6VWS/JnKyjaYHYoz5ep33RmlhmkdZHhrqMxf Rh037CyhguO34+KYPjPfU4Dhr8q1DIF1zY8bSTqPfX1WqonPbzPUALZIcz6s/Fo4T1b5 uejYahCQDjJ3kM2AfbMQkz1EW9pfzWz6cAt9P2XxhN/yDP9TymzKVCUvSc0Xq7aPQP/b Lf+oVCL/yWqKIb68vmDsFf6o2jEsjqxGQGh8qrDAnEW2NLSYv9R7w0cH+ngm1UNv0GUL YLLEuCvEJFgTrwEHJ8KJmLCnatwRzc9QhqifvLGkXoUP/YUkk+6kdkCj7rSFkePZtxOP T1qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=r1QEEzychUMCoe5U0DSfc5Oq8DaKAXk74KjekRt/xBk=; b=Hol+BikCGQQhStSL5VXnxTYVWyEqDgZDPnmCihTsdwbD6S102jkZv3H8/rItny+PG9 ipZ9zEA9r/NKpuNfw/cJHXCCk8MjLvhvGDoqAVsVP6Zs/V7oA5TQQusztgVE6nrlSPVZ HWQEtHFwOCKA6hIPOmD0OU50HjeO2oCQt56pKnAY5BNUfQ1UrBfAcvJmOptt5ZExSMQL EwBtQuMfFCRasFwMyEhShFFsoz706Vx98VtjVXaFjIwoDt9Av520w1GKdhqGUynpeEK+ HLAdUcTzyBcJvdi1iJ1ABX8vuaWxfRrTZxgFWeqwRPTPFAKqu2CZOqdlFgwmnJLpnXqH 5E3g== X-Gm-Message-State: AOAM533RSvPsXvj7gA5tFrRw37xtB0xXI5wT+2QlX94eMmSKF7Eyed8o Ji3kVNYNYSO49cXQ3f9KZ0Q= X-Google-Smtp-Source: ABdhPJzv/S6WjXTCMee8NeOApFsHfvQNWaNzQQYEDOSomwHAyzQX+uirIatWiFPa/UeV9TWHfDvo/g== X-Received: by 2002:a17:90b:4c4a:: with SMTP id np10mr1694513pjb.164.1643959371345; Thu, 03 Feb 2022 23:22:51 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id t14sm11665328pjd.6.2022.02.03.23.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 23:22:50 -0800 (PST) From: Joel Stanley To: Arnd Bergmann , Andrew Jeffery , Greg Kroah-Hartman , "Rafael J . Wysocki" , Robin Murphy Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org Subject: [PATCH v3 2/3] ARM: aspeed: Add secure boot controller support Date: Fri, 4 Feb 2022 17:52:33 +1030 Message-Id: <20220204072234.304543-3-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220204072234.304543-1-joel@jms.id.au> References: <20220204072234.304543-1-joel@jms.id.au> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220203_232253_386826_15741483 X-CRM114-Status: GOOD ( 16.58 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This reads out the status of the secure boot controller and exposes it in sysfs using the bootinfo sysfs api. An example on a AST2600A3 QEMU model: # grep -r . /sys/firmware/bootinfo/* /sys/firmware/bootinfo/abr_image:0 /sys/firmware/bootinfo/low_security_key:0 /sys/firmware/bootinfo/otp_protected:0 /sys/firmware/bootinfo/secure_boot:1 On boot the state of the system according to the secure boot controller will be printed: [ 0.037634] AST2600 secure boot enabled or [ 0.037935] AST2600 secure boot disabled The initialisation is changed from early_initcall to subsys_initcall because we need the firmware_kobj to be initialised, and because there's no requirement to print this information early. Signed-off-by: Joel Stanley --- v2: - Rewrite to new bootinfo api - Get rid of unused return values v3: - Drop uart_boot --- drivers/soc/aspeed/aspeed-socinfo.c | 44 ++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/soc/aspeed/aspeed-socinfo.c b/drivers/soc/aspeed/aspeed-socinfo.c index 1ca140356a08..e5ced9bebfa2 100644 --- a/drivers/soc/aspeed/aspeed-socinfo.c +++ b/drivers/soc/aspeed/aspeed-socinfo.c @@ -8,6 +8,7 @@ #include #include #include +#include static struct { const char *name; @@ -74,6 +75,45 @@ static const char *siliconid_to_rev(u32 siliconid) return "??"; } +/* Secure Boot Controller register */ +#define SEC_STATUS 0x14 +#define ABR_IMAGE_SOURCE BIT(13) +#define OTP_PROTECTED BIT(8) +#define LOW_SEC_KEY BIT(7) +#define SECURE_BOOT BIT(6) +#define UART_BOOT BIT(5) + +static void __init aspeed_bootinfo_init(void) +{ + struct device_node *np; + void __iomem *base; + struct bootinfo bootinfo = {}; + u32 reg; + + /* AST2600 only */ + np = of_find_compatible_node(NULL, NULL, "aspeed,ast2600-sbc"); + if (!of_device_is_available(np)) + return; + + base = of_iomap(np, 0); + if (!base) + of_node_put(np); + + reg = readl(base + SEC_STATUS); + + iounmap(base); + of_node_put(np); + + BOOTINFO_SET(bootinfo, abr_image, reg & ABR_IMAGE_SOURCE); + BOOTINFO_SET(bootinfo, low_security_key, reg & LOW_SEC_KEY); + BOOTINFO_SET(bootinfo, otp_protected, reg & OTP_PROTECTED); + BOOTINFO_SET(bootinfo, secure_boot, reg & SECURE_BOOT); + + firmware_bootinfo_init(&bootinfo); + + pr_info("AST2600 secure boot %s\n", (reg & SECURE_BOOT) ? "enabled" : "disabled"); +} + static int __init aspeed_socinfo_init(void) { struct soc_device_attribute *attrs; @@ -148,6 +188,8 @@ static int __init aspeed_socinfo_init(void) attrs->revision, attrs->soc_id); + aspeed_bootinfo_init(); + return 0; } -early_initcall(aspeed_socinfo_init); +subsys_initcall(aspeed_socinfo_init);