From patchwork Tue Jun 25 16:43:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Parent X-Patchwork-Id: 1122152 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="D3XXgKwH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45YBmz23J7z9s8m for ; Wed, 26 Jun 2019 02:43:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DE950C21DEC; Tue, 25 Jun 2019 16:43:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 867FAC21C3F; Tue, 25 Jun 2019 16:43:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8D0BBC21C4A; Tue, 25 Jun 2019 16:43:19 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by lists.denx.de (Postfix) with ESMTPS id 329D0C21C29 for ; Tue, 25 Jun 2019 16:43:19 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id f17so3671171wme.2 for ; Tue, 25 Jun 2019 09:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bGbjndr7VPNwMYm0nChbiEfO+szbjvxuFxl7rzRE1dI=; b=D3XXgKwHPRZNnJr+IUggmsuq3SvPZi/VDP3V01tnFXjPHg1sXzFZQ8WMlnNfnGX+1J uGzDDF28VYDxELuG7wz216woOqSElufrM+yupzaHia4eodZys+ugBWrHb+RDxoQtACXi DgeHzxHMocppIgvKn4XsWe2ebUcDxUb2TzBis7LMxq6JIc50Qhx6aTOILADUQwZ1PwM/ t9ds9y5hQH3JDbFj/MbC1rjUbdUbW0EPbmDpg7/b1IUBnv0fS9OSg5apy4IeydONmfqG +5hGS1GazJqaUP9W4OtgP4MM014Oq387U6gO4We9ZTc9ZEl67qjMtsuaOKeOMhG9J1r2 C7gQ== 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:mime-version :content-transfer-encoding; bh=bGbjndr7VPNwMYm0nChbiEfO+szbjvxuFxl7rzRE1dI=; b=VNxLqhmjUFVTa/Qc5mxwTDPtsH7z/cBw4q2wC0vEfviiSq+WsRXo+4lmQ60EFKcN+f 7MlvIBrrZHV53FUul05hbzNXsvXKv0OW7/fThBGyCRFDTr0ktwd7TBI6Yq6/EVT0/mXj P9DmFze4sQurJtYfdnbwZSEnZmb/kSZUTq+pR5YQ+eEHBGUPOmp5/dlWJTVt3SJdDimk cCLoElTKJ/uBEpUrx0t82PkWWIbNMCRdLbUxArxDnFP7Q9SCZVDg6fk1wIX3przILmpV zYD4LpwZ7ihDZzdjR71d4e8634WvyD78Rc4XMb+Sodoxrf7WwOmIRW/EADmLhoWqoP6W nBqg== X-Gm-Message-State: APjAAAUGyb7sW1qFfsiaE+Y91TmkG/0dDxNbe7h2og9SUSNTKC9mC6mM QO5EmM1E3Lljfp2FZPVTMSY0YZDuPEQ= X-Google-Smtp-Source: APXvYqwAoehG05ma7yeuUWzfU6KryRlqF00G7ICgtdfclK/6LugYiVWsR0hF/t9gTByCXGJ/nSPSgQ== X-Received: by 2002:a1c:b604:: with SMTP id g4mr20947147wmf.111.1561480998367; Tue, 25 Jun 2019 09:43:18 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:87cb:590:d1d9:3d78:6af:5274]) by smtp.gmail.com with ESMTPSA id y1sm2104006wma.32.2019.06.25.09.43.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 25 Jun 2019 09:43:17 -0700 (PDT) From: Fabien Parent To: u-boot@lists.denx.de, trini@konsulko.com Date: Tue, 25 Jun 2019 18:43:15 +0200 Message-Id: <20190625164315.2398-1-fparent@baylibre.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [U-Boot] [PATCH] fastboot: mmc: add support for flashing boot partitions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" MMC storage supports 4 hardware partitions: * User partition * 2 boot partitions * RPMB partition Flashing to the User partition is already supported, and this commit adds support for flashing to the 2 boot partitions. User can run the following commands to flash to the boot partitions: fastboot flash mmcboot0 myfile fastboot flash mmcboot1 myfile "mmcboot" is the default name of the partition and can be changed via a Kconfig option. Signed-off-by: Fabien Parent --- drivers/fastboot/Kconfig | 17 +++++++++++++++++ drivers/fastboot/fb_mmc.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index d63ecdd27e..f481d7596c 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -126,6 +126,23 @@ config FASTBOOT_MBR_NAME specified on the "fastboot flash" command line matches the value defined here. The default target name for updating MBR is "mbr". +config FASTBOOT_MMC_BOOT_PART_NAME + string "Target name for updating MMC's boot partitions" + depends on FASTBOOT_FLASH_MMC + default "mmcboot" + help + The fastboot "flash" command supports writing the downloaded + image to the MMC's boot partitions. + This occurs when the specified "partition name" on the + "fastboot flash" command line is starts with the value defined here, + and ends with '0' or '1' to specify which boot partition is being + targeted. + The default name for updating the boot partitions is "mmcboot". + For example the two partitions can be flashed using the following + commands if the default name is used: + - "fastboot flash mmcboot0 myfile", + - "fastboot flash mmcboot1 myfile". + config FASTBOOT_CMD_OEM_FORMAT bool "Enable the 'oem format' command" depends on FASTBOOT_FLASH_MMC && CMD_GPT diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 90ca81da9b..c2451200f7 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -46,6 +46,28 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc, return ret; } +static int part_get_mmc_boot_info(int hwpart, disk_partition_t *info) +{ + struct mmc *mmc; + int ret; + + mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); + if (!mmc) + return -EINVAL; + + ret = blk_select_hwpart_devnum(IF_TYPE_MMC, + CONFIG_FASTBOOT_FLASH_MMC_DEV, hwpart); + if (ret < 0) + return ret; + + memset(info, 0, sizeof(*info)); + info->start = 0; + info->size = mmc->capacity_boot; + info->blksz = mmc->write_bl_len; + + return 0; +} + /** * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE * @@ -394,7 +416,19 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, } #endif - if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { + if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT_PART_NAME "0") == 0) { + if (part_get_mmc_boot_info(1, &info) < 0) { + pr_err("cannot find partition: '%s'\n", cmd); + fastboot_fail("cannot find partition", response); + return; + } + } else if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT_PART_NAME "1") == 0) { + if (part_get_mmc_boot_info(2, &info) < 0) { + pr_err("cannot find partition: '%s'\n", cmd); + fastboot_fail("cannot find partition", response); + return; + } + } else if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { pr_err("cannot find partition: '%s'\n", cmd); fastboot_fail("cannot find partition", response); return;