From patchwork Tue Jan 25 13:55:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ying-Chun Liu X-Patchwork-Id: 536487 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3731735imr; Tue, 25 Jan 2022 05:56:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzICztUFP/RXUtcvvW4ZwMl2N/m//YHTix3mXkUTJf6mCaqNKJbvKwHrfnXzCSB7Ut8LSDI X-Received: by 2002:a17:906:12c7:: with SMTP id l7mr16159715ejb.588.1643118975102; Tue, 25 Jan 2022 05:56:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643118975; cv=none; d=google.com; s=arc-20160816; b=dLCYSjLj3h8Y7cSbc5GMn9AT/GS1IL/oXddBzESX0zaWxpbD2rVrxI5flmJWPQHIbK 8EyZ0xuVqKqc6ttoAMwEz5IgXNhmVyf029/GswbrpHZnsPWn32KCVtD1maA2fIILYIvj PXvoWhThnKQ7BYaYdiLHPEHMv4rCYxbYATpkvygFZwMPPN5EkHz3l1JyntveUGVLBKIe xLhB48kYVYUvFT9fgyvEnaJoH9mZr22csHR4Yb0XzH/z/1wpEpI40ottFwSuN3beLN8M H0H6cAOWn1vWmmZwJ1J64QGqOrxNkA1GkdLU/IEdIEce28TihBIbas/DNQg9uAmJbJgK i//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C66mRCPQiu9EGvY4FgljJO69VY6TL9OlKOclYzBFlU0=; b=gKXyY+alKvY7TNI/kiBlqcty7WFrDBVFgzCK+ex928GzQN9druBYUoQZxYQLDFSBLR oxdUP2qRIWMuJG9pGDF7zOJA+2GOfMPojjujg1yJ/kdeEOcziRyWSh2cob+yAee7d9j6 G1ll8uadp1cyfN4ixmg+GSSdw2FwgaClqPds8Iw+Ff+9W6NbUaT2U/0pg4FGomqMsyvv PA7uC97Cqbsc/2QMi92MXr7VdmW8ThH8scM5MJIkd+6Cjdo5Yv4y5Ajo/57CIcwnTSOo oauhNrXKeQresssz51FYI5eSMEfwW9wS6W/+cL/xHPfy6tlALznAKHXnWLPbrma9gNZ0 x2cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=glCNgFsf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id g3si2320004edr.256.2022.01.25.05.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 05:56:15 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=glCNgFsf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 71294837C4; Tue, 25 Jan 2022 14:55:58 +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="glCNgFsf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ABC4E80F9E; Tue, 25 Jan 2022 14:55:55 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (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 68A47837C4 for ; Tue, 25 Jan 2022 14:55:51 +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=grandpaul@gmail.com Received: by mail-pj1-x102e.google.com with SMTP id r59so2195244pjg.4 for ; Tue, 25 Jan 2022 05:55:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C66mRCPQiu9EGvY4FgljJO69VY6TL9OlKOclYzBFlU0=; b=glCNgFsf82DjTmfjlngVgDmZQWpw4vXX1T8Hco6BypkWcC47uczZx4IFCxth+17b/A G+nqUnCf6vg6tSarNUFjXHrlCcYJYUo8wzyGghzvenpHy4iq7S5wKnyMn7BA8U1Nm6jV stVbxDeOnrgpMoc3u+/6bZ2TLeQbXXqjNUF6DE1Me/ClMTAu5ISCH+S49lBkgCFlA3KA Ud0Wvm/BrL7rGUjUwIHBDh5zXpqFGL2QzOEur0UCED2lAm3jPbNFlVX1yHxaI8gFOgNB O+Ee4CEdTmHbo+43vmcurW0UELz4WmlAyhZ1KRpw+SiW0LiJe3LGxh9goqxBcN3IIdDN XZbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C66mRCPQiu9EGvY4FgljJO69VY6TL9OlKOclYzBFlU0=; b=qM0RCA4qnf8cUBkVNGaKIr78O5It/GjiWgFlaMBcFulqGLcepb96rw01Wqb2wMgm+b rq9vg8j6YVvHtZlXE2OEBalFdXL+7AXC+q+ol0vEbSlAR3TuA1xGq8SigZdwQH1ukW9k O7YOstmHt16vcogz9HGGP5PrGgplYeEzyKcEcMk20kAKvzxZpx2Ei2619fccGZh88d5U I3+ZJiEA/E2ERVeowvERYcprwh5Azo4g+RuDtiEOwtW7CvAQxwsJuS2C8qP5/+e+24fE 3K+Sb0hFBUMms017CBG8NAGaPLse/Y1vthB6L9pUbHkvTIYgWhvk0Q47ZDDT7qw2XNfH eevA== X-Gm-Message-State: AOAM533Mlv0SGyRY3BsNiaFTYrNcvRwpLokE1cQRVBsN5j8C5UH11Ztb nRIpdCZvdZfpUkToH129jAK1UMqkqXM= X-Received: by 2002:a17:902:a502:b0:149:c5a5:5329 with SMTP id s2-20020a170902a50200b00149c5a55329mr18834771plq.164.1643118949496; Tue, 25 Jan 2022 05:55:49 -0800 (PST) Received: from localhost (host-111-184-129-17.dynamic.kbtelecom.net. [111.184.129.17]) by smtp.gmail.com with ESMTPSA id b6sm20657126pfl.126.2022.01.25.05.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 05:55:49 -0800 (PST) From: Ying-Chun Liu To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Lukasz Majewski Subject: [RFC 2/2] drivers: dfu: flash firmware to inactive boot area and active it Date: Tue, 25 Jan 2022 21:55:35 +0800 Message-Id: <20220125135535.224061-3-grandpaul@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125135535.224061-1-grandpaul@gmail.com> References: <20220125135535.224061-1-grandpaul@gmail.com> MIME-Version: 1.0 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 From: "Ying-Chun Liu (PaulLiu)" This commit implement flash to the inactive boot partition of eMMC when dfu_alt_info set mmcpart to "inactive". After flash to the inactive boot partition. It will switch the active partition to the one that just flashed. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Lukasz Majewski --- drivers/dfu/dfu_mmc.c | 32 +++++++++++++++++++++++++++++--- include/dfu.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 3dab5a5f63..3c1f2018d3 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -198,6 +198,7 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { int ret = -1; + struct mmc *mmc; switch (dfu->layout) { case DFU_RAW_ADDR: @@ -218,6 +219,17 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, dfu_get_layout(dfu->layout)); } + if (!ret && dfu->data.mmc.hw_partition_inactive) { + mmc = find_mmc_device(dfu->data.mmc.dev_num); + if (!mmc) { + pr_err("Device MMC %d - not found!", + dfu->data.mmc.dev_num); + return -ENODEV; + } + + mmc_set_part_conf(mmc, 0, dfu->data.mmc.hw_partition, 0); + } + return ret; } @@ -384,15 +396,29 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mmc.lba_start = second_arg; dfu->data.mmc.lba_size = third_arg; dfu->data.mmc.lba_blk_size = mmc->read_bl_len; + dfu->data.mmc.hw_partition_inactive = false; /* * Check for an extra entry at dfu_alt_info env variable * specifying the mmc HW defined partition number */ if (s) - if (!strcmp(strsep(&s, " "), "mmcpart")) - dfu->data.mmc.hw_partition = - simple_strtoul(s, NULL, 0); + if (!strcmp(strsep(&s, " "), "mmcpart")) { + if (!strcmp(s, "inactive")) { + u8 part_boot; + u8 part_target; + + part_boot = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); + part_target = 3 - part_boot; + dfu->data.mmc.hw_partition = + part_target; + dfu->data.mmc.hw_partition_inactive = + true; + } else { + dfu->data.mmc.hw_partition = + simple_strtoul(s, NULL, 0); + } + } } else if (!strcmp(entity_type, "part")) { struct disk_partition partinfo; diff --git a/include/dfu.h b/include/dfu.h index f6868982df..7fbcf03063 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -53,6 +53,7 @@ struct mmc_internal_data { /* eMMC HW partition access */ int hw_partition; + bool hw_partition_inactive; /* FAT/EXT */ unsigned int dev;