From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81260606A32F for ; Sat, 5 Dec 2026 10:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.u-boot-project.org header.i=@lists.u-boot-project.org header.a=rsa-sha256 header.s=default header.b=G7pPgjCR; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bmZY6NGP Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5D16540E06; Sat, 5 Dec 2026 10:06:32 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 5iGOhLKt14Y5; Sat, 5 Dec 2026 10:06:31 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org E7B5840E07 Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796465191; b=iSvRM1kkotBVmZNdYZ10M6A2MlYbaY0eTxVhsUh7u/sa+I6rarZcmD1M+MedAvm7Ikiq 9F3zLAsgp02O2ftsTEzhFqWB8hVGz9KY/ZFyQNQF+Rl8YL4gAKz2mL+kVQ9GDN3vgXNrI V2+MrGQArYH2VlGmYsri7/I9aKlHCmU9pWrewtw07vqGDvQTrDrGgamCdQB+iAFIIECOZ 2+vOTZObCn7Cpg3Y/8avwvB08CCQu9wJJxnM5oMrWjz6X4jq3bOcWXTbUxoywjIZ77OkG ZeXM3zkzO2dpucIsug9eIDVlyvWZViaMLA8eLIaI7enQS8nPIHkqRyEoycB+PuDypWQ== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796465191; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:X-Comment:Received:Received: Received:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Virus-Scanned:X-Virus-Status:X-BeenThere: X-Mailman-Version:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Errors-To; bh=rISBVCOEKbRnsPUACSzaZFoBjRpQ3ApHSnSCaMe63nU=; b=GOxWFPwbdQDw6P6gHlS2yv7rQhmZZGj3MQOR8FGcm8FT/6Mpscqr7V7iG0OlNusC9zIR WGxwSOrYl9D1j2R0ahnpx+UQEIKAZolGanJRFbWsxQx0PFRlQuEYVCnYLQHY+6CVMQc+Q sBZElBRtaDqKwZi/W6UQkeGLjIA2IAaxD22jhrXq1OqsHaGVZgWLIQ6TGTTyLAY6IaIqb 0r4+MyTGS2g1XcyUCBRzRffECyzgc8d0ZO16bqwE/TrzNInYUEIwRUAzoc1HJkV4cTyBl DsmSdJlXkp6vzHfgJdkAyWBec0NES5z9uWXGt1ZxNkDDHQ45YTyitJHmmLB17PT0EAA== ARC-Authentication-Results: i=1; smtp4.osuosl.org; dmarc=pass header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bmZY6NGP; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=u-boot-bounces@lists.u-boot-project.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.u-boot-project.org; s=default; t=1796465191; bh=rISBVCOEKbRnsPUACSzaZFoBjRpQ3ApHSnSCaMe63nU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=G7pPgjCRT6UstQNJD2Y7IRa3Jg2iaa9egrhGsAULDk6lh9pK5xSdfGvSLIWaDD1w3 +CXxSqG4BP1xc1Lo5yjPrPrwxiClA1WkG9MxIDRZtjcCaXqDkC6wkkNqLxzzD8m+wg SF2ujhxpOIiuk3DWhvSxEtxiQ54hM01M7/MgH+JQobVT/NN94u8+69Bi9pVT3BuWcC 3W7nFbYy/JYgHwohZvMzattzCXlimMc7byNsETDV/UkYPV/b06QYCwFiG43R+EMBZ6 KSMpOnYxTAFNW1MooBOLenULhLkpERUrA+P/qKlParUyWko1uBrc1Z0m+FrogyKPG3 1e8oQOuXDa4fA== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp4.osuosl.org (Postfix) with ESMTP id E7B5840E07; Sat, 5 Dec 2026 10:06:30 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists1.osuosl.org (Postfix) with ESMTP id 71874158 for ; Sat, 5 Dec 2026 10:06:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5641340E05 for ; Sat, 5 Dec 2026 10:06:25 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id oJPHd40aRVK2 for ; Sat, 5 Dec 2026 10:06:24 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org A558040E06 Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip=85.214.62.61 X-Comment: SPF check N/A for local connections - client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=clamor95@gmail.com; receiver= Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp4.osuosl.org; spf=fail smtp.mailfrom=gmail.com Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bmZY6NGP Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by smtp4.osuosl.org (Postfix) with ESMTPS id A558040E06 for ; Sat, 5 Dec 2026 10:06:23 +0000 (UTC) Received: by phobos.denx.de (Postfix, from userid 109) id D94BC847F4; Sat, 5 Dec 2026 11:06:21 +0100 (CET) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7AF5B846F7 for ; Sat, 5 Dec 2026 11:06:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-c554097da5fso16607466b.0 for ; Sat, 05 Dec 2026 02:06:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796465174; x=1797069974; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rISBVCOEKbRnsPUACSzaZFoBjRpQ3ApHSnSCaMe63nU=; b=bmZY6NGPS9z2hEt8FWQ4vMlTgU7ICEu+UJQ9vv2MYWGVwGFLZ/D5pl5xyRazBvQlJS Pzi8hdzVpNoTwrQXubY8mZhxSILeR4FZqxTQKwZXzEMhzSoiyTcyhh+/hz/zqTDqDa+k QZlXX9EVsJLV+7lFW/ZcsMhCETQCMJzcz1lRKMOlgO4oJK9sO8LBdKw2YCujiOG44m5n Wmrjf/wZWPe+JG7TbWQL9wZchEn6hfyTvTUwwPcrfgrS882dOajC628fweWs5h2NkNGX uT1u6nwwy+R6/YWuNm4kM2U/tAE1X3PfMCzbUkZ5mM8+hq1E6dwj9kVVBA0iGTUEM8Ai EtAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796465174; x=1797069974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=rISBVCOEKbRnsPUACSzaZFoBjRpQ3ApHSnSCaMe63nU=; b=polWriezYyf2sfHTkY7mIKw6wE0BldBVmqjYGYicgu6e2lrA7AzG2LToidz+EpI9y3 MzSJ2fCc8vtApC/KRBRLJ7ZhTAJuAtZKrgvSCrCA3hDqdUpt85jEa17FV5aM3U+eMgvC hKIznPyC6OweEv4R1m4bRMX0dk2HtvR2mn7qyzc86X1DAzdqiOEbtrFosBXkZ9n4HXay OhXBvQUsNfV+jS1nZ2ntgJRJNsOWqYfDZJdymr/Gv1C5nrOiYxWFWNTAaN2OaUE0Cksq KfkMpFo+Cnmz2eADPoqEIwyQdicgeSqrXgus7nZl/WgX59nXVC8LttV2xMCg+q/fQX+S 52DQ== X-Gm-Message-State: APuU4Z9zLBOgZTqxJh4ZuA8dFe2bUrOCqpUrqaRm1w1V5W/OfyvGV9ZC vjdDp9of5b3Y3eMOzopw7TqJFt/uaykRtY5bDfmf9Gr2oGfMN7CipKlP X-Gm-Gg: AZFdTZcKcv6ao60R/mAyKsf6gzlX4EvKvnyCVos3IAE+XMDTJy3awuQbB2ZYWRU7cZ9 FxZhXsptY8fTpeAj9H3jwgnoCF009j8nYv5Jz7lNrnLLw7nt3J2tj/kbSVeek37l0gMP/SYIhlI 3SplOPO+02NEybmC2vnpL4TQMUZhfTH9Pgf6uHOtLs8OnR+nN9YAKm70+DXcbGKGBTR7O85ZUj7 XWDPxoq2mON4hxT8hua6r6I1313Ofy9VjFdIC25Mg/v5mFaaO17h5HkTNpsL31z5nVUMzepGaQG d7T8eTWT1oeqAXWvhs8haDzwd+Iki+4FxGZn1/FoUIEbUfugGACyaebogELJmKacUoeXjEIKET7 NlL3Du/83Wxg3dE7U4JROzCrlWPicIg5D3T8F0LWV+RYINoxYmLySGEVyTj9epKrmEhCUCHXjSN emKYS/Ay7f3V4B9qxN0nqJG8FgTjZp3OgMOIrgPmUGDcxYCK+UNVieyMP86R1CfTclwAOqNpT5y IEbV2lNO1F5p5flMPjVZMXPXVtIZaiolaDOldwgkjTw3ohYw6fqhnqUBiJnkLH2IwDW2xs8NpEH AoO7uUZ4ucpPrNRM7GFli1CpiiRlhCGgQSrRT8xA+wtX/61SesOtnR7kteYiueSlBHsNufQyWYi xNCYc+uPDjg== X-Received: by 2002:a17:907:d16:b0:c33:ae8b:817d with SMTP id a640c23a62f3a-c5262542c7fmr334143866b.46.1796465173744; Sat, 05 Dec 2026 02:06:13 -0800 (PST) Received: from xeon ([188.163.112.54]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b64dd0dsm231759366b.83.2026.12.05.02.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 02:06:13 -0800 (PST) From: Svyatoslav Ryhel To: Svyatoslav Ryhel , Thierry Reding , Tom Rini , Ilias Apalodimas , =?UTF-8?q?Jonas=20Schw=C3=B6bel?= , Ion Agorria , Peter Geis , Mattijs Korpershoek , Guillaume La Roque Cc: u-boot@lists.denx.de Subject: [PATCH v2 2/9] ARM: tegra: Refactor BCT patching process Date: Sat, 5 Dec 2026 12:05:38 +0200 Message-ID: <20261205100545.106967-3-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205100545.106967-1-clamor95@gmail.com> References: <20261205100545.106967-1-clamor95@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: u-boot@lists.u-boot-project.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: U-Boot discussion List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_FAIL,SPF_HELO_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Ion Agorria Commonize the BCT patching process across all supported Tegra SoC generations. Refactor the function to handle core logic only, allowing it to be used in other execution pathways. Signed-off-by: Ion Agorria Signed-off-by: Svyatoslav Ryhel --- arch/arm/mach-tegra/Kconfig | 7 +- arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/{tegra20 => }/bct.c | 63 +++++++++--------- arch/arm/mach-tegra/bct.h | 44 +++++++++++++ arch/arm/mach-tegra/tegra124/Makefile | 1 - arch/arm/mach-tegra/tegra124/bct.c | 86 ------------------------- arch/arm/mach-tegra/tegra124/bct.h | 24 +------ arch/arm/mach-tegra/tegra20/Makefile | 1 - arch/arm/mach-tegra/tegra20/bct.h | 22 ++----- arch/arm/mach-tegra/tegra30/Makefile | 1 - arch/arm/mach-tegra/tegra30/bct.c | 84 ------------------------ arch/arm/mach-tegra/tegra30/bct.h | 22 ++----- 12 files changed, 95 insertions(+), 261 deletions(-) rename arch/arm/mach-tegra/{tegra20 => }/bct.c (54%) create mode 100644 arch/arm/mach-tegra/bct.h delete mode 100644 arch/arm/mach-tegra/tegra124/bct.c delete mode 100644 arch/arm/mach-tegra/tegra30/bct.c diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig index 32cdfebfc01..ec4993788f1 100644 --- a/arch/arm/mach-tegra/Kconfig +++ b/arch/arm/mach-tegra/Kconfig @@ -21,6 +21,11 @@ config TEGRA_CRYPTO select AES select TEGRA_AES +config TEGRA_BCT + bool "Tegra BCT operations" + depends on TEGRA20 || TEGRA30 || TEGRA124 + select TEGRA_CRYPTO + config TEGRA_GP_PADCTRL bool @@ -267,7 +272,7 @@ config CMD_ENTERRCM config CMD_EBTUPDATE bool "Enable 'ebtupdate' command" depends on TEGRA20 || TEGRA30 || TEGRA124 - select TEGRA_CRYPTO + select TEGRA_BCT help Updating u-boot from within u-boot in rather complex or even impossible on production devices. To make it easier procedure of diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile index 2f0341bc02a..63fd95d7208 100644 --- a/arch/arm/mach-tegra/Makefile +++ b/arch/arm/mach-tegra/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_TEGRA_GPU) += gpu.o obj-$(CONFIG_TEGRA_IVC) += ivc.o ifndef CONFIG_XPL_BUILD obj-$(CONFIG_ARMV7_PSCI) += psci.o +obj-$(CONFIG_TEGRA_BCT) += bct.o endif obj-$(CONFIG_DISPLAY_CPUINFO) += sys_info.o obj-y += pmc.o diff --git a/arch/arm/mach-tegra/tegra20/bct.c b/arch/arm/mach-tegra/bct.c similarity index 54% rename from arch/arm/mach-tegra/tegra20/bct.c rename to arch/arm/mach-tegra/bct.c index 0270cf592c1..a4647d854a7 100644 --- a/arch/arm/mach-tegra/tegra20/bct.c +++ b/arch/arm/mach-tegra/bct.c @@ -13,72 +13,67 @@ #include "bct.h" #include "uboot_aes.h" -/* - * @param bct boot config table start in RAM - * @param ect bootloader start in RAM - * @param ebt_size bootloader file size in bytes - * Return: 0, or 1 if failed - */ -static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size) +int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size) { - struct nvboot_config_table *bct_tbl = NULL; - u8 ebt_hash[AES128_KEY_LENGTH] = { 0 }; - u8 *bct_hash = bct; + struct nvboot_config_table *bct_tbl = (struct nvboot_config_table *)bct; bool encrypted; int ret; - bct += BCT_HASH; + bct += UBCT_LENGTH; ebt_size = roundup(ebt_size, EBT_ALIGNMENT); - encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE; - - if (encrypted) { - ret = decrypt_data_block(bct, bct, BCT_LENGTH); - if (ret) - return 1; - - ret = encrypt_data_block(ebt, ebt, ebt_size); - if (ret) - return 1; - } - - ret = sign_data_block(ebt, ebt_size, ebt_hash); + ret = sign_data_block(ebt, ebt_size, (u8 *)bct_tbl->bootloader[0].crypto_hash); if (ret) return 1; - bct_tbl = (struct nvboot_config_table *)bct; - - memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash, - ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4); bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE; bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE; bct_tbl->bootloader[0].length = ebt_size; + encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE; if (encrypted) { - ret = encrypt_data_block(bct, bct, BCT_LENGTH); + ret = encrypt_data_block(bct, bct, SBCT_LENGTH); if (ret) return 1; } - ret = sign_data_block(bct, BCT_LENGTH, bct_hash); + ret = sign_data_block(bct, SBCT_LENGTH, (u8 *)bct_tbl->crypto_hash); if (ret) return 1; return 0; + } +#ifdef CONFIG_CMD_EBTUPDATE static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - u32 bct_addr = hextoul(argv[1], NULL); - u32 ebt_addr = hextoul(argv[2], NULL); + u8 *bct = (u8 *)hextoul(argv[1], NULL); + u8 *ebt = (u8 *)hextoul(argv[2], NULL); u32 ebt_size = hextoul(argv[3], NULL); + bool encrypted; + int ret; + + ebt_size = roundup(ebt_size, EBT_ALIGNMENT); + encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE; + + if (encrypted) { + ret = decrypt_data_block(bct, bct, SBCT_LENGTH); + if (ret) + return 1; + + ret = encrypt_data_block(ebt, ebt, ebt_size); + if (ret) + return 1; + } - return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size); + return bct_patch(bct, ebt, ebt_size); } U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate, - "update bootloader on re-crypted Tegra20 devices", + "update bootloader on re-crypted Tegra devices", "" ); +#endif diff --git a/arch/arm/mach-tegra/bct.h b/arch/arm/mach-tegra/bct.h new file mode 100644 index 00000000000..76756cba8ed --- /dev/null +++ b/arch/arm/mach-tegra/bct.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _BCT_H_ +#define _BCT_H_ + +#define EBT_ALIGNMENT 0x10 + +/* + * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) + */ +#define NVBOOT_CMAC_AES_HASH_LENGTH 4 + +/* + * Defines the RSA modulus length in 32 bit words used for PKC secure boot. + */ +#define NVBOOT_SE_RSA_MODULUS_LENGTH 64 + +/* + * Defines the maximum number of bootloader descriptions in the BCT. + */ +#define NVBOOT_MAX_BOOTLOADERS 4 + +#ifdef CONFIG_TEGRA20 +#include "tegra20/bct.h" +#elif CONFIG_TEGRA30 +#include "tegra30/bct.h" +#elif CONFIG_TEGRA124 +#include "tegra124/bct.h" +#endif + +#define BCT_LENGTH (UBCT_LENGTH + SBCT_LENGTH) + +/* + * Updates the hash of bootloader entry and the BCT itself + * It will encrypt BCT in place if the device requires it + * + * @param bct boot config table start in RAM + * @param ebt bootloader start in RAM + * @param ebt_size bootloader file size in bytes + * Return: 0, or 1 if failed + */ +int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size); + +#endif /* _BCT_H_ */ diff --git a/arch/arm/mach-tegra/tegra124/Makefile b/arch/arm/mach-tegra/tegra124/Makefile index 7b93db89c0f..dee790015a3 100644 --- a/arch/arm/mach-tegra/tegra124/Makefile +++ b/arch/arm/mach-tegra/tegra124/Makefile @@ -6,7 +6,6 @@ # obj-$(CONFIG_XPL_BUILD) += cpu.o -obj-$(CONFIG_$(XPL_)CMD_EBTUPDATE) += bct.o obj-y += clock.o obj-y += pmc.o diff --git a/arch/arm/mach-tegra/tegra124/bct.c b/arch/arm/mach-tegra/tegra124/bct.c deleted file mode 100644 index 676b68dc5de..00000000000 --- a/arch/arm/mach-tegra/tegra124/bct.c +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (c) 2022, Ramin - * Copyright (c) 2022, Svyatoslav Ryhel - */ - -#include -#include -#include -#include -#include -#include -#include "bct.h" -#include "uboot_aes.h" - -/* - * @param bct boot config table start in RAM - * @param ect bootloader start in RAM - * @param ebt_size bootloader file size in bytes - * Return: 0, or 1 if failed - */ -static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size) -{ - struct nvboot_config_table *bct_tbl = NULL; - u8 ebt_hash[AES128_KEY_LENGTH] = { 0 }; - u8 bct_hash[AES128_KEY_LENGTH] = { 0 }; - u8 *sbct = bct + UBCT_LENGTH; - bool encrypted; - int ret; - - ebt_size = roundup(ebt_size, EBT_ALIGNMENT); - - encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE; - - if (encrypted) { - ret = decrypt_data_block(sbct, sbct, SBCT_LENGTH); - if (ret) - return 1; - - ret = encrypt_data_block(ebt, ebt, ebt_size); - if (ret) - return 1; - } - - ret = sign_data_block(ebt, ebt_size, ebt_hash); - if (ret) - return 1; - - bct_tbl = (struct nvboot_config_table *)bct; - - memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash, - ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4); - bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE; - bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE; - bct_tbl->bootloader[0].length = ebt_size; - - if (encrypted) { - ret = encrypt_data_block(sbct, sbct, SBCT_LENGTH); - if (ret) - return 1; - } - - ret = sign_data_block(sbct, SBCT_LENGTH, bct_hash); - if (ret) - return 1; - - memcpy((u8 *)&bct_tbl->crypto_hash, bct_hash, - NVBOOT_CMAC_AES_HASH_LENGTH * 4); - - return 0; -} - -static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) -{ - u32 bct_addr = hextoul(argv[1], NULL); - u32 ebt_addr = hextoul(argv[2], NULL); - u32 ebt_size = hextoul(argv[3], NULL); - - return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size); -} - -U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate, - "update bootloader on re-crypted Tegra124 devices", - "" -); diff --git a/arch/arm/mach-tegra/tegra124/bct.h b/arch/arm/mach-tegra/tegra124/bct.h index eb0f712d595..f7d65621c0a 100644 --- a/arch/arm/mach-tegra/tegra124/bct.h +++ b/arch/arm/mach-tegra/tegra124/bct.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -#ifndef _BCT_H_ -#define _BCT_H_ +#ifndef _TEGRA124_BCT_H_ +#define _TEGRA124_BCT_H_ /* * Defines the BCT parametres for T124 @@ -9,24 +9,6 @@ #define UBCT_LENGTH 0x6b0 /* bytes */ #define SBCT_LENGTH 0x1950 /* bytes */ -#define BCT_HASH 0x10 -#define EBT_ALIGNMENT 0x10 - -/* - * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) - */ -#define NVBOOT_CMAC_AES_HASH_LENGTH 4 - -/* - * Defines the RSA modulus length in 32 bit words used for PKC secure boot. - */ -#define NVBOOT_SE_RSA_MODULUS_LENGTH 64 - -/* - * Defines the maximum number of bootloader descriptions in the BCT. - */ -#define NVBOOT_MAX_BOOTLOADERS 4 - struct nv_bootloader_info { u32 version; u32 start_blk; @@ -52,4 +34,4 @@ struct nvboot_config_table { u32 sbct_unused2; }; -#endif /* _BCT_H_ */ +#endif /* _TEGRA124_BCT_H_ */ diff --git a/arch/arm/mach-tegra/tegra20/Makefile b/arch/arm/mach-tegra/tegra20/Makefile index a3ea759d764..fad4b1bc07d 100644 --- a/arch/arm/mach-tegra/tegra20/Makefile +++ b/arch/arm/mach-tegra/tegra20/Makefile @@ -3,7 +3,6 @@ # (C) Copyright 2010,2011 Nvidia Corporation. obj-$(CONFIG_XPL_BUILD) += cpu.o -obj-$(CONFIG_$(PHASE_)CMD_EBTUPDATE) += bct.o # The AVP is ARMv4T architecture so we must use special compiler # flags for any startup files it might use. diff --git a/arch/arm/mach-tegra/tegra20/bct.h b/arch/arm/mach-tegra/tegra20/bct.h index 4b78aef7cfd..a9feba42bf6 100644 --- a/arch/arm/mach-tegra/tegra20/bct.h +++ b/arch/arm/mach-tegra/tegra20/bct.h @@ -1,24 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -#ifndef _BCT_H_ -#define _BCT_H_ +#ifndef _TEGRA20_BCT_H_ +#define _TEGRA20_BCT_H_ /* * Defines the BCT parametres for T20 */ -#define BCT_LENGTH 0xFE0 -#define BCT_HASH 0x10 -#define EBT_ALIGNMENT 0x10 - -/* - * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) - */ -#define NVBOOT_CMAC_AES_HASH_LENGTH 4 - -/* - * Defines the maximum number of bootloader descriptions in the BCT. - */ -#define NVBOOT_MAX_BOOTLOADERS 4 +#define UBCT_LENGTH 0x10 +#define SBCT_LENGTH 0xFE0 struct nv_bootloader_info { u32 version; @@ -32,6 +21,7 @@ struct nv_bootloader_info { }; struct nvboot_config_table { + u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH]; u32 unused0[4]; u32 boot_data_version; u32 unused1[668]; @@ -39,4 +29,4 @@ struct nvboot_config_table { u32 unused2[508]; }; -#endif /* _BCT_H_ */ +#endif /* _TEGRA20_BCT_H_ */ diff --git a/arch/arm/mach-tegra/tegra30/Makefile b/arch/arm/mach-tegra/tegra30/Makefile index d6351734ec0..d983800a89c 100644 --- a/arch/arm/mach-tegra/tegra30/Makefile +++ b/arch/arm/mach-tegra/tegra30/Makefile @@ -3,6 +3,5 @@ # Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved. obj-$(CONFIG_XPL_BUILD) += cpu.o -obj-$(CONFIG_$(PHASE_)CMD_EBTUPDATE) += bct.o obj-y += clock.o diff --git a/arch/arm/mach-tegra/tegra30/bct.c b/arch/arm/mach-tegra/tegra30/bct.c deleted file mode 100644 index de668214517..00000000000 --- a/arch/arm/mach-tegra/tegra30/bct.c +++ /dev/null @@ -1,84 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (c) 2022, Ramin - * Copyright (c) 2022, Svyatoslav Ryhel - */ - -#include -#include -#include -#include -#include -#include -#include "bct.h" -#include "uboot_aes.h" - -/* - * @param bct boot config table start in RAM - * @param ect bootloader start in RAM - * @param ebt_size bootloader file size in bytes - * Return: 0, or 1 if failed - */ -static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size) -{ - struct nvboot_config_table *bct_tbl = NULL; - u8 ebt_hash[AES128_KEY_LENGTH] = { 0 }; - u8 *bct_hash = bct; - bool encrypted; - int ret; - - bct += BCT_HASH; - - ebt_size = roundup(ebt_size, EBT_ALIGNMENT); - - encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE; - - if (encrypted) { - ret = decrypt_data_block(bct, bct, BCT_LENGTH); - if (ret) - return 1; - - ret = encrypt_data_block(ebt, ebt, ebt_size); - if (ret) - return 1; - } - - ret = sign_data_block(ebt, ebt_size, ebt_hash); - if (ret) - return 1; - - bct_tbl = (struct nvboot_config_table *)bct; - - memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash, - ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4); - bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE; - bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE; - bct_tbl->bootloader[0].length = ebt_size; - - if (encrypted) { - ret = encrypt_data_block(bct, bct, BCT_LENGTH); - if (ret) - return 1; - } - - ret = sign_data_block(bct, BCT_LENGTH, bct_hash); - if (ret) - return 1; - - return 0; -} - -static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) -{ - u32 bct_addr = hextoul(argv[1], NULL); - u32 ebt_addr = hextoul(argv[2], NULL); - u32 ebt_size = hextoul(argv[3], NULL); - - return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size); -} - -U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate, - "update bootloader on re-crypted Tegra30 devices", - "" -); diff --git a/arch/arm/mach-tegra/tegra30/bct.h b/arch/arm/mach-tegra/tegra30/bct.h index 9797384da32..8420615ce62 100644 --- a/arch/arm/mach-tegra/tegra30/bct.h +++ b/arch/arm/mach-tegra/tegra30/bct.h @@ -1,24 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -#ifndef _BCT_H_ -#define _BCT_H_ +#ifndef _TEGRA30_BCT_H_ +#define _TEGRA30_BCT_H_ /* * Defines the BCT parametres for T30 */ -#define BCT_LENGTH 0x17E0 -#define BCT_HASH 0x10 -#define EBT_ALIGNMENT 0x10 - -/* - * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) - */ -#define NVBOOT_CMAC_AES_HASH_LENGTH 4 - -/* - * Defines the maximum number of bootloader descriptions in the BCT. - */ -#define NVBOOT_MAX_BOOTLOADERS 4 +#define UBCT_LENGTH 0x10 +#define SBCT_LENGTH 0x17E0 struct nv_bootloader_info { u32 version; @@ -32,6 +21,7 @@ struct nv_bootloader_info { }; struct nvboot_config_table { + u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH]; u32 unused0[4]; u32 boot_data_version; u32 unused1[972]; @@ -39,4 +29,4 @@ struct nvboot_config_table { u32 unused2[508]; }; -#endif /* _BCT_H_ */ +#endif /* _TEGRA30_BCT_H_ */ -- 2.53.0