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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F121C433EF for ; Mon, 14 Feb 2022 11:15:06 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6B45B83A5A; Mon, 14 Feb 2022 12:15:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="dJgg/exF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 79B0183A5A; Mon, 14 Feb 2022 12:15:01 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6AE6080615 for ; Mon, 14 Feb 2022 12:14:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=80449f5349=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21E86kYB004049; Mon, 14 Feb 2022 12:14:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=eNErHUuihOLJgFLrxZDyJkEbxeApcJGkGtwxQoTyn6E=; b=dJgg/exFb3ILdv+TRKNnn7rrnM6Wp6F5tbmagSS97sBgQ2C3/GbqplKrIO+8ga5b89Yw fj86o3yPZJ6DbwFmJgcvvozRvrvl+qW007yUD1AtFOrI2Ul2K5QztVjFCmu6adiKXGyu KiVVW4ibbZomweAvJIFMcBFWg4Zw/I4WCYon748njzEwCCENfJ8mCGYoihsbEFNtp9Ty CIl8b53BJtrM0JBlTOmjwxrxVwGr1V3PUgu8SGyTnnAkOzvw6sPkIYeJ4FNa7I8/l69E m056n51pJGDobuwmJ8zYeY5iSK8LHXdr1Wv4mQ3t6IEDp+kq976lOQLloPTTYEpojM1C XQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3e79tmb2hy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Feb 2022 12:14:46 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D92B910002A; Mon, 14 Feb 2022 12:14:45 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C95EF21B534; Mon, 14 Feb 2022 12:14:45 +0100 (CET) Received: from [10.211.2.202] (10.75.127.47) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 14 Feb 2022 12:14:45 +0100 Message-ID: Date: Mon, 14 Feb 2022 12:14:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: STM32MP: Can't lock PHK fuses through U-Boot cmd's "stm32key" or "fuse" Content-Language: en-US To: Johann Neuhauser , Patrice Chotard CC: "u-boot@lists.denx.de" , References: <1133c192473b46f1998fb3415bf7dbf2@dh-electronics.com> From: Patrick DELAUNAY In-Reply-To: <1133c192473b46f1998fb3415bf7dbf2@dh-electronics.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-14_02,2022-02-14_03,2021-12-02_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi Johann, On 2/11/22 15:02, Johann Neuhauser wrote: > Hello Patrick, Patrice and other devs, > > I'm trying to roll out secure boot with U-Boot v2022.01 only. > The boot flow should be like: > BootROM -(signed STM32 image)-> U-Boot SPL -(signed fit)-> U-Boot -(signed fit)-> Linux > > Everything except the first part in the chain is working as expected. > I've used the U-Boot cmd "stm32key" to programm the file "publicKeyhash.bin", > but the command failed with: "Lock OTP 24 failed". > > Here are the excact commands with output (hash values are replaced by xxxxxxxx): > STM32MP> load mmc 0:4 ${loadaddr} publicKeyhash.bin > STM32MP> stm32key read ${loadaddr} > Read KEY at 0xc2000000 > OTP value 24: xxxxxxxx > OTP value 25: xxxxxxxx > OTP value 26: xxxxxxxx > OTP value 27: xxxxxxxx > OTP value 28: xxxxxxxx > OTP value 29: xxxxxxxx > OTP value 30: xxxxxxxx > OTP value 31: xxxxxxxx > STM32MP> stm32key fuse -y ${loadaddr} > Lock OTP 24 failed > > A second call failed because the word 24 is already fused and not locked! > STM32MP> stm32key fuse ${loadaddr} > OTP HASH 24: xxxxxxxx lock : 0 > OTP HASH 25: 0 lock : 0 > OTP HASH 26: 0 lock : 0 > OTP HASH 27: 0 lock : 0 > OTP HASH 28: 0 lock : 0 > OTP HASH 29: 0 lock : 0 > OTP HASH 30: 0 lock : 0 > OTP HASH 31: 0 lock : 0 > OTP 0: closed status: 0 lock : 0 > Hash of key is not locked! > Error: can't fuse again the OTP > > After this failed attempt, I tried to fuse the hash with the command "fuse", like: > STM32MP> fuse prog -y 0 0x18 0x4e31bbcd > STM32MP> fuse prog -y 0 0x19 0x51e827dd > STM32MP> fuse prog -y 0 0x1a 0x3511f521 > STM32MP> fuse prog -y 0 0x1b 0xfd9c11a2 > STM32MP> fuse prog -y 0 0x1c 0x5b997b82 > STM32MP> fuse prog -y 0 0x1d 0x8150adc5 > STM32MP> fuse prog -y 0 0x1e 0xa9c68fa9 > STM32MP> fuse prog -y 0 0x1f 0x72a3ba74 > Which gives me a matching "stm32key read" == "stm32key read ${loadaddr}", > except that the fuses aren't locked. > > If I wanna lock the fuses with, it always fails with "ERROR": > STM32MP> fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1 > Programming bank 0 word 0x10000018 to 0x00000001... > ERROR > > According to the reference manual, chapter 4, only writes to the shadow registers aren't allowed! > Do you have any clue why locking the fuses isn't possilbe either with "stm32key" or with "fuse"? > > The next thing is, that I can't authenticate any signed STM32 images with the non locked PHK fuses. > And no, I haven't closed the device already nor have I locked/fused any other fuses. > I've implemented a authentication status output inside "arch/arm/mach-stm32mp/spl.c" > like in TF-A "plat/st/stm32mp1/bl2_plat_setup.c", which I'll probably mainline into U-Boot. > I'm using a STM32MP157C on a DHCOM with PDK2 from DH electronics GmbH. > > Best regards and a nice weekend, > Johann Neuhauser > > DH electronics GmbH | Am Anger 8 | 83346 Bergen | Germany | Fon: +49 8662 4882 0 > Board of Management: Stefan Daxenberger, Helmut Henschke | HRB Traunstein 9602 You correctly use the stm32key or the stm32fuse command https://wiki.st.com/stm32mpu/wiki/STM32MP15_ROM_code_secure_boot https://wiki.st.com/stm32mpu/wiki/How_to_update_OTP_with_U-Boot But in fact the OTP LOCK feature is NOT supported in U-Boot basic boot. As OpenSTLinux only use boot with TF-A and the OTP operations are managed by secure service (SMC), all the feature in basic boot with SPL wasn't developed By STMicroelectronics. Today OTP LOCK feature is a a security to avoid a 2nd write on lower OTP which will cause  an ECC error. So it wasn't a blocking feature, you can experiment the secure boot chain without  locking the OTP. Reference in code : CONFIG_ARM_SMCCC is not activated arch/arm/mach-stm32mp/bsec.c():: stm32mp_bsec_write_lock() static int stm32mp_bsec_write_lock(struct udevice *dev, u32 val, u32 otp) {     if (!IS_ENABLED(CONFIG_ARM_SMCCC) || IS_ENABLED(CONFIG_SPL_BUILD))         return -ENOTSUPP; .... => without TF-A the lock feature is not (yet ?) supported reference code in TF-A: drivers/st/bsec/bsec2.c::bsec_permanent_lock_otp() Regards Patrick