From patchwork Mon Jun 29 11:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Brozovic X-Patchwork-Id: 1318835 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=rxm74B8m; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 49wPzg6yXVz9sRk for ; Mon, 29 Jun 2020 21:15:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E29258004A; Mon, 29 Jun 2020 13:15:12 +0200 (CEST) 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="rxm74B8m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D56BE8003B; Mon, 29 Jun 2020 13:15:10 +0200 (CEST) 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-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (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 78C528003B for ; Mon, 29 Jun 2020 13:15:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=fbrozovic@gmail.com Received: by mail-ed1-x544.google.com with SMTP id d16so5834293edz.12 for ; Mon, 29 Jun 2020 04:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F1PBAG8gCb+lPdpz9RIo0P+wDWL/mxJYSEKewtj7kZM=; b=rxm74B8mYoG+C8JhcrKULT6pBrIdnVelSfnKbf1kV+Un4OF0lEGsYKBahha83oCTgE ce+QBlybU/t17AJs1PxeDREV86YdwZLiRh9qUGJ5mhNuS9YH4ZzhKUy7XOADRu8kz9ir 6kbM9PK0kvNwBXMwRi2/l4kyUD+5jx9+h2fLVMgshMOT6GcXYa/qqc24vBlneAQXii/M YYsO+RcidYcfNxwGQvvh5jTEtrpV3kqg0YA0p72PFPNUbkuOUJNu79VlAE4KUrhux7e5 25pm7NmiC1xINwaaoR6P3mjCSObdOtZwh5AE0hrguhOK+J20eNO2EZZfirDJDnKNpapp Kq5A== 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=F1PBAG8gCb+lPdpz9RIo0P+wDWL/mxJYSEKewtj7kZM=; b=HfjH4i8uPcI3CCPIX7KzOnxw3gZQMYt9j6tiPqzpx80gclcCFCj31onDSVp6NfWvNw oYWnZ+NLMuF+VkD1MF5YwJ7PTweXqUZsGpQu4nbPyoy9YDnfu4m3VLKLH5nF2FzJHckw vtrDJQxDrRBj+HcsdTZYUC6XputQbMKNla7VuD3qfRjzowCi0PVRykP8guJCip+nEUFR OULvLZk6JptYeBqX+QjRB6r6NHyu8OZMrPg2dlsDD9EYOLPyg+P9Fga24V5iZbS29zOo RCvhlelrMffNnqMa+8HPGUEZL34wpVshvUiJyYlNbZSqJgMaim0P2JNyEHp3qir2Ex9c K/Sw== X-Gm-Message-State: AOAM5302EuLJftIXMGz8Wv1MsayyhuRityu53TtAJxwvjcjJrw2KFEvO H7yVym6kSdtQagOHZag2E3Q= X-Google-Smtp-Source: ABdhPJx+cBXru4prE7aZaSaHtIlGAfAn+EnDB3Z5ApnlyHNNAvV72qMgvquZJsbZ+0c5BtA2NcK5bA== X-Received: by 2002:aa7:d70b:: with SMTP id t11mr8564176edq.256.1593429306903; Mon, 29 Jun 2020 04:15:06 -0700 (PDT) Received: from neon.int.seal.ch (47.9.63.188.dynamic.wline.res.cust.swisscom.ch. [188.63.9.47]) by smtp.gmail.com with ESMTPSA id a37sm18017750edf.86.2020.06.29.04.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 04:15:06 -0700 (PDT) From: Filip Brozovic To: Cc: Filip Brozovic , u-boot@lists.denx.de Subject: [PATCH] fastboot: Support defining raw partitions without a partition table Date: Mon, 29 Jun 2020 13:14:37 +0200 Message-Id: <20200629111437.106839-1-fbrozovic@gmail.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean Add support for defining raw fastboot partitions in eMMC by specifying the offset and size in an environment variable. Optionally, the eMMC hardware partition number may also be specified. This makes it possible to e.g. update only part of the eMMC boot partition, instead of having to write the entire partition. Signed-off-by: Filip Brozovic --- doc/android/fastboot.rst | 19 ++++++++++ drivers/fastboot/fb_mmc.c | 75 ++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst index de3f6c37d7..2877c3cbaa 100644 --- a/doc/android/fastboot.rst +++ b/doc/android/fastboot.rst @@ -85,6 +85,25 @@ for example:: fastboot_partition_alias_boot=LNX +Raw partition descriptors +^^^^^^^^^^^^^^^^^^^^^^^^^ + +In cases where no partition table is present, a raw partition descriptor can be +defined, specifying the offset, size, and optionally the MMC hardware partition +number for a given partition name. + +This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a +specific offset in the eMMC boot partition, without having to update the entire +boot partition. + +To define a raw partition descriptor, add an environment variable similar to:: + + fastboot_raw_partition_= [mmcpart ] + +for example:: + + fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1 + Variable overrides ^^^^^^^^^^^^^^^^^^ diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index b2f8932e1c..ae8e8e512f 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -50,6 +50,48 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc, return ret; } +static int raw_part_get_info_by_name(struct blk_desc *dev_desc, + const char *name, struct disk_partition *info, int *mmcpart) +{ + /* strlen("fastboot_raw_partition_") + PART_NAME_LEN + 1 */ + char env_desc_name[23 + PART_NAME_LEN + 1]; + char *raw_part_desc; + const char *argv[2]; + const char **parg = argv; + + /* check for raw partition descriptor */ + strcpy(env_desc_name, "fastboot_raw_partition_"); + strncat(env_desc_name, name, PART_NAME_LEN); + raw_part_desc = strdup(env_get(env_desc_name)); + if (raw_part_desc == NULL) + return -ENODEV; + + /* + * parse partition descriptor + * + * [mmcpart ] + */ + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { + *parg = strsep(&raw_part_desc, " "); + if (*parg == NULL) { + pr_err("Invalid number of arguments.\n"); + return -ENODEV; + } + } + + info->start = simple_strtoul(argv[0], NULL, 0); + info->size = simple_strtoul(argv[1], NULL, 0); + info->blksz = dev_desc->blksz; + strncpy((char *)info->name, name, PART_NAME_LEN); + + if (raw_part_desc) { + if (strcmp(strsep(&raw_part_desc, " "), "mmcpart") == 0) + *mmcpart = simple_strtoul(raw_part_desc, NULL, 0); + } + + return 0; +} + /** * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE * @@ -376,7 +418,8 @@ int fastboot_mmc_get_part_info(const char *part_name, struct blk_desc **dev_desc, struct disk_partition *part_info, char *response) { - int r; + int r = 0; + int mmcpart; *dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!*dev_desc) { @@ -388,10 +431,12 @@ int fastboot_mmc_get_part_info(const char *part_name, return -ENOENT; } - r = part_get_info_by_name_or_alias(*dev_desc, part_name, part_info); - if (r < 0) { - fastboot_fail("partition not found", response); - return r; + if (raw_part_get_info_by_name(*dev_desc, part_name, part_info, &mmcpart) < 0) { + r = part_get_info_by_name_or_alias(*dev_desc, part_name, part_info); + if (r < 0) { + fastboot_fail("partition not found", response); + return r; + } } return r; @@ -410,6 +455,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, { struct blk_desc *dev_desc; struct disk_partition info; + int mmcpart = 0; dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { @@ -482,7 +528,13 @@ 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 (raw_part_get_info_by_name(dev_desc, cmd, &info, &mmcpart) == 0) { + if (blk_dselect_hwpart(dev_desc, mmcpart)) { + pr_err("Failed to select hwpart\n"); + fastboot_fail("Failed to select hwpart", 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; @@ -524,11 +576,11 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, */ void fastboot_mmc_erase(const char *cmd, char *response) { - int ret; struct blk_desc *dev_desc; struct disk_partition info; lbaint_t blks, blks_start, blks_size, grp_size; struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); + int mmcpart = 0; if (mmc == NULL) { pr_err("invalid mmc device\n"); @@ -562,8 +614,13 @@ void fastboot_mmc_erase(const char *cmd, char *response) } #endif - ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info); - if (ret < 0) { + if (raw_part_get_info_by_name(dev_desc, cmd, &info, &mmcpart) == 0) { + if (blk_dselect_hwpart(dev_desc, mmcpart)) { + pr_err("Failed to select hwpart\n"); + fastboot_fail("Failed to select hwpart", 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;