From patchwork Wed Feb 17 16:35:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: grygorii tertychnyi X-Patchwork-Id: 1441281 X-Patchwork-Delegate: van.freenix@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Cc1mUVni; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dgk3q1CmCz9sSC for ; Thu, 18 Feb 2021 03:35:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 992A482483; Wed, 17 Feb 2021 17:35:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="Cc1mUVni"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1104382385; Wed, 17 Feb 2021 17:35:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 2C7C982385 for ; Wed, 17 Feb 2021 17:35:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grembeter@gmail.com Received: by mail-wr1-x42e.google.com with SMTP id t15so17992262wrx.13 for ; Wed, 17 Feb 2021 08:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iXmLKkuQ9071Ma8ArRxfe7ZuKun9cYaDIm5r8+eeCEY=; b=Cc1mUVniwA36aciSHT8SoPJdlVsbOFqpqPJcok36YTPVupGL12peb+blK/FqcXlfOv 5QZZrhSkY7o99s5UnwHmDhBNSGuAqzdqGfUK+m2AWl4lI8EA3t7CRvaG0dOpsPZMbO7r PkLPQmy+ctDtIBwrMe2cYSL7KwQWLB/yXk9cFmk//PFCssW+ZOyR4XbSAnLQTR4Qmd8o /RqJEclxksp9ke5C6dO0eM597QzHrqfEt8qauV0xBvmYwxSPSDGLobw443Yoin1sZqcY BWIv3gnLdtvTMGTojlukl+G/yy+ygkFRcpDIyjYQfmBrGF17eksLAqSR/fx4uXrGPv7u vWAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iXmLKkuQ9071Ma8ArRxfe7ZuKun9cYaDIm5r8+eeCEY=; b=NGUW6r5Habub/h5eg2PnSiFLroGvGJBJlmxe4QsQF6EwWnLjgAGroKhVGiAIrBs6VC 07k8DcGfl3VuzsO7IaGr/U/VMZTwKlCx4BCPI1cEeMApWRPpODDJGayuk/SHeIf4eN0D S+fJ3mFmdrGk0GKAuVSCu2Z03+tQPlep2fMV9W2CWYElssNvIw/SKS57X3hY2jkD0hlX mjPoCm8RwJ0/f4mcOeFUQ+S/8fJMgOji2U6HSauFb0HDbTeizod/OB+VEfebIkxhRDGI JQUSCipdVm1RRbz45+Q8vKI5e7KxcETzWT03pL2i5IQKBapdS8c8aTvQ2bFJulCNMOHK 7dPg== X-Gm-Message-State: AOAM530yrq6r4mUcebPa6jsjsE2PG6u61SfHcFdMAjHWupGMktJ6enNW aRGb8yH1MsMeU+o8fLNtE5InbwjCjyXcIw== X-Google-Smtp-Source: ABdhPJzjTs95/rqIWcZMvA4bS7PMz9Qaqf51NE2CHyrfb2xXpcw5D450Dt5uSmX+N9UDjNtzaPlF0w== X-Received: by 2002:adf:efc9:: with SMTP id i9mr59074wrp.177.1613579731526; Wed, 17 Feb 2021 08:35:31 -0800 (PST) Received: from AHERLNXTGRY01.lgs-net.com ([193.8.40.126]) by smtp.gmail.com with ESMTPSA id b13sm4521742wrs.35.2021.02.17.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 08:35:31 -0800 (PST) From: grygorii tertychnyi To: u-boot@lists.denx.de Cc: Jaehoon Chung , grygorii tertychnyi , Grygorii Tertychnyi Subject: [PATCH v2] cmd: mmc: add mmc bootpart-check Date: Wed, 17 Feb 2021 17:35:16 +0100 Message-Id: <20210217163516.2183810-1-grembeter@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210212103214.14495-1-grembeter@gmail.com> References: <20210212103214.14495-1-grembeter@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This patch allows to check the current boot partition. It is useful when you use two different sets of (bootloader, kernel) images and want to boot the corresponding kernel image in boot script. E.g.: if mmc bootpart-check ${mmcdev} 1; then echo "booted from eMMC boot0 partition" ...load kernel image1 elif mmc bootpart-check ${mmcdev} 2; then echo "booted from eMMC boot1 partition" ...load kernel image2 fi Signed-off-by: Grygorii Tertychnyi --- v2: - renamed the command, it is "bootpart-check" now - added <> to mandatory arguments help string - added more details to commit message cmd/mmc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cmd/mmc.c b/cmd/mmc.c index 1529a3e05ddd..3332dee4b130 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -771,6 +771,41 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag, return CMD_RET_SUCCESS; } +static int do_mmc_boot_check(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + int dev; + struct mmc *mmc; + u8 part_args, part_emmc; + + if (argc != 3) + return CMD_RET_USAGE; + + dev = simple_strtoul(argv[1], NULL, 10); + + mmc = init_mmc_device(dev, false); + if (!mmc) + return CMD_RET_FAILURE; + + if (IS_SD(mmc)) { + printf("It is not an eMMC device\n"); + return CMD_RET_FAILURE; + } + + if (mmc->part_config == MMCPART_NOAVAILABLE) { + printf("No part_config info for ver. 0x%x\n", mmc->version); + return CMD_RET_FAILURE; + } + + part_emmc = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); + part_args = simple_strtoul(argv[2], NULL, 10); + + if (part_emmc == part_args) + return CMD_RET_SUCCESS; + else + return CMD_RET_FAILURE; +} + static int mmc_partconf_print(struct mmc *mmc) { u8 ack, access, part; @@ -952,6 +987,7 @@ static struct cmd_tbl cmd_mmc[] = { #endif #ifdef CONFIG_SUPPORT_EMMC_BOOT U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""), + U_BOOT_CMD_MKENT(bootpart-check, 3, 0, do_mmc_boot_check, "", ""), U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""), U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""), U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""), @@ -1019,6 +1055,9 @@ U_BOOT_CMD( #ifdef CONFIG_SUPPORT_EMMC_BOOT "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" " - Set the BOOT_BUS_WIDTH field of the specified device\n" + "mmc bootpart-check \n" + " - Return success if the given boot_partition value matches BOOT_PARTITION_ENABLE\n" + " bit field of the specified device\n" "mmc bootpart-resize \n" " - Change sizes of boot and RPMB partitions of specified device\n" "mmc partconf dev [boot_ack boot_partition partition_access]\n"