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 41818C433F5 for ; Tue, 25 Jan 2022 13:56:15 +0000 (UTC) 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) 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-Google-Smtp-Source: ABdhPJxhuWjsE9+PMKNvgLhs+rXTofBmaZt4577HAr+C7NPj6AU6ReBbI0jTv6ohn6wdbCM3MJby/w== 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 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.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; -- 2.34.1