From patchwork Tue Feb 1 05:05:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 12731398 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 C6BABC433F5 for ; Tue, 1 Feb 2022 05:07:02 +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=kJeemuGGmM3iHFbsOfdvGTX/wZc03PHu1PUUZfh06IU=; b=D6s0H+M65jrXOh TSaAR7FkEcGigzfrCwHypw4wkcmgOHYjZk5NBWaNPkf3FnkG/HK7WujjW3HfyFMj4TOl9sF/hL+V1 c8zAh/kTsTWxtudFgldvgTj8qdAYU7l9CO2/DtB9ieIGFp7lE9kCLJeelBTkq9UubdmIwEmS2AGUk vof5+92Fqliomj01ATmRw28vE15q0vu55yCG5Hx20FL50ppEgb2baIA/uD1Bl1Ycsm6q0tFTcd7YB HXgKQYeM0L8AMhVvrU+tK6lWx6YKB/TINwwBaJUqa6zu71W0oNKcwQPAhKTvWCNWxFs6l9HsqEgYP E5YkEV69g1XWa5pqnPtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nElMG-00B9bq-8h; Tue, 01 Feb 2022 05:05:36 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nElLy-00B9ZJ-Nb for linux-arm-kernel@lists.infradead.org; Tue, 01 Feb 2022 05:05:20 +0000 Received: by mail-pf1-x42e.google.com with SMTP id e6so14818924pfc.7 for ; Mon, 31 Jan 2022 21:05:18 -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=KXZhXqP+hJTCEG0KLlnHSrSIKRsgu3yP6iR8K2/utRA=; b=cRTGOvUdVQ3VIpJHalZf12OyJMEycgkXop8Rx0kknHVuzOdzJ2MXCo9u3nKKw2GrGc PEZn8o0Xmseg8Zi1sphhHK9O1fd2s2IUN7UO/nY3Y6bqDFX6NtEZmqZqdGHdp9N9jKP6 i+Ls2/GRKXaFoYQvFXD5B/7aDkp7c4HzJh9a6tgunLySRbuB/xpwoXxxxCHaR4MUiktY 7dWUuETtJHy4bRiu1RRvaKHfEohjO18GsM2onAPSIa61wk0j7+GRgNzUcHVB/W2Wqd+i dSfoGiGC/iL8duI2rEPqjZyAV6AZMhm6L5zSoTyi5zdY0koHTXepGDEhtdQTUsrnsfxo MW0Q== 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=KXZhXqP+hJTCEG0KLlnHSrSIKRsgu3yP6iR8K2/utRA=; b=vSp698LxBJAhQy1GszdXv3xMnhvw0ZbXKwpVnHzxZIS6ZjPvIQnmLjIP/SFh23QUxq ewNZ9Yu5CgGpZ6jrN6YIztLSRN5LBHzRDGjyBLBvf9DiuRBHtBteDwji/x3e/E7ah0Gc OjBZXUEO5nIbCj8QEyE0mg6htcinCjXqbQADP0MQ2d/PPD6kV01aTMN2gCUSxY82RfC8 PnKQDkDr6wYQLRucEUCxlAj8tqNHnK8Gf3zowzgGvLQnk+xBKcqWButSHWPnJZSSWtEF lsACvaweULBeQJ4MaEylvJq6lmsQrV61iTS2MfUILubkwihvC1YkvjvO9KAj+xJmHo9O eruw== X-Gm-Message-State: AOAM532DUJpf1RyLXoof+XOtBIaaBNl5f/YpIAf8ksIosesqc0ergsi3 +wGm16Wh5CQ3Smzwc4jTGns= X-Google-Smtp-Source: ABdhPJyyiAnlj0jVqXEFutCAzEC/wZnZT8ZEHQEjaUAnr+6+PlrOSxgyRqfRvqoQBuDLXDpcscM7Lw== X-Received: by 2002:aa7:88c9:: with SMTP id k9mr23203828pff.58.1643691917941; Mon, 31 Jan 2022 21:05:17 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id u37sm6181991pga.2.2022.01.31.21.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 21:05:17 -0800 (PST) From: Joel Stanley To: Arnd Bergmann , Andrew Jeffery , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, Ryan Chen Subject: [PATCH 2/2] ARM: aspeed: Add secure boot controller support Date: Tue, 1 Feb 2022 15:35:01 +1030 Message-Id: <20220201050501.182961-3-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220201050501.182961-1-joel@jms.id.au> References: <20220201050501.182961-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-20220131_210518_803667_5D583D05 X-CRM114-Status: GOOD ( 17.82 ) 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 /sys/firmware/bootinfo/uart_boot:0 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 Reviewed-by: Ryan Chen --- drivers/soc/aspeed/aspeed-socinfo.c | 84 ++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/drivers/soc/aspeed/aspeed-socinfo.c b/drivers/soc/aspeed/aspeed-socinfo.c index 1ca140356a08..fe77b31e4d1d 100644 --- a/drivers/soc/aspeed/aspeed-socinfo.c +++ b/drivers/soc/aspeed/aspeed-socinfo.c @@ -8,6 +8,9 @@ #include #include #include +#include + +static u32 security_status; static struct { const char *name; @@ -74,6 +77,83 @@ static const char *siliconid_to_rev(u32 siliconid) return "??"; } +#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 ssize_t abr_image_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", !!(security_status & ABR_IMAGE_SOURCE)); +} +static DEVICE_ATTR_RO(abr_image); + +static ssize_t low_security_key_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", !!(security_status & LOW_SEC_KEY)); +} +static DEVICE_ATTR_RO(low_security_key); + +static ssize_t otp_protected_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", !!(security_status & OTP_PROTECTED)); +} +static DEVICE_ATTR_RO(otp_protected); + +static ssize_t secure_boot_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", !!(security_status & SECURE_BOOT)); +} +static DEVICE_ATTR_RO(secure_boot); + +static ssize_t uart_boot_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + /* Invert the bit, as 1 is boot from SPI/eMMC */ + return sprintf(buf, "%d\n", !(security_status & UART_BOOT)); +} +static DEVICE_ATTR_RO(uart_boot); + +static struct attribute *aspeed_attrs[] = { + &dev_attr_abr_image.attr, + &dev_attr_low_security_key.attr, + &dev_attr_otp_protected.attr, + &dev_attr_secure_boot.attr, + &dev_attr_uart_boot.attr, + NULL, +}; +ATTRIBUTE_GROUPS(aspeed); + +static int __init aspeed_bootinfo_init(void) +{ + struct device_node *np; + void __iomem *base; + + /* AST2600 only */ + np = of_find_compatible_node(NULL, NULL, "aspeed,ast2600-sbc"); + if (!of_device_is_available(np)) + return -ENODEV; + + base = of_iomap(np, 0); + if (!base) { + of_node_put(np); + return -ENODEV; + } + + security_status = readl(base + SEC_STATUS); + + iounmap(base); + of_node_put(np); + + firmware_bootinfo_init(aspeed_groups[0]); + + pr_info("AST2600 secure boot %s\n", + (security_status & SECURE_BOOT) ? "enabled" : "disabled"); + + return 0; +} + static int __init aspeed_socinfo_init(void) { struct soc_device_attribute *attrs; @@ -148,6 +228,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);