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 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 D7B89C77B6E for ; Thu, 13 Apr 2023 21:12:09 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BFF5A85D9D; Thu, 13 Apr 2023 23:12:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="j/Q1ibRN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 33AF280610; Thu, 13 Apr 2023 23:11:50 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (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 DDDE880610 for ; Thu, 13 Apr 2023 23:11:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B18A760AF1; Thu, 13 Apr 2023 21:11:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC375C4339C; Thu, 13 Apr 2023 21:11:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681420301; bh=rgB004+MA7NeSxf419+3uOou4Fc0Z//1MVYvrUbVf4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/Q1ibRNHJ89phPeomd9ZeV+DzR0AUAPZCLL+OrHOZXOiCivBRvxusuY/8b3+l/as J/fUeifVGaOciDWZOktw7pEWq+bEXPKEMUWsf06KSDF2w0iIVcbK4CiPcY7JgxksNP o7Bp5nr4ERpmbD48YqeAYdzHDfV2SeizY1fFDMpVeLCjRWnRGkdUrS20glslXf2Ebt vMQnOoqa+81LreHUQm8+43NMgxGGVWvPWnzU73iujxr12Ui+WEi/fTTsxjQabdC/oB ldPOBIl2Wy/5Lmk6XYk7bSiUIO5IkXgzMopYFLPHpgtygVSROXKW4c3wUKtY5b2hk7 t/9/ezWtcYv1A== Received: by pali.im (Postfix) id CC19C788; Thu, 13 Apr 2023 23:11:38 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Jaehoon Chung , Peng Fan , Stefan Roese Cc: u-boot@lists.denx.de Subject: [PATCH u-boot 2/4] cmd: mvebu/bubt: Validate EXT_CSD[179] eMMC register in mmc_burn_image() Date: Thu, 13 Apr 2023 23:10:55 +0200 Message-Id: <20230413211057.10975-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230413211057.10975-1-pali@kernel.org> References: <20230413211057.10975-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.8 at phobos.denx.de X-Virus-Status: Clean When determining eMMC boot partition for a bootloader, validate that EXT_CSD[179] eMMC register is set to recognized value. This prevent situation that EXT_CSD[179] Boot Enable value is improperly parsed and passed into EXT_CSD[179] Partition Access. Signed-off-by: Pali Rohár --- cmd/mvebu/bubt.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c index ca24a5c1c4ba..b8fe7c7a1461 100644 --- a/cmd/mvebu/bubt.c +++ b/cmd/mvebu/bubt.c @@ -223,9 +223,29 @@ static int mmc_burn_image(size_t image_size) orig_part = mmc->block_dev.hwpart; #endif - part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); - if (part == 7) + if (mmc->part_config == MMCPART_NOAVAILABLE) { part = 0; + } else { + switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) { + case 0: /* Booting from this eMMC device is disabled */ + printf("Error - Booting from this eMMC device is disabled\n"); + printf("Hint: Use 'mmc partconf' command to choose boot partition\n"); + return -ENODEV; + case 1: /* Boot partition 1 is used for booting */ + part = 1; + break; + case 2: /* Boot partition 2 is used for booting */ + part = 2; + break; + case 7: /* User area is used for booting */ + part = 0; + break; + default: /* Other values are reserved / unsupported */ + printf("Error - This eMMC device has configured Reserved boot option\n"); + printf("Hint: Use 'mmc partconf' command to choose boot partition\n"); + return -ENODEV; + } + } #ifdef CONFIG_BLK err = blk_dselect_hwpart(blk_desc, part); -- 2.20.1