From patchwork Mon Apr 25 13:59:02 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: 565707 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp2724049map; Mon, 25 Apr 2022 06:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwviiqQwSlkpXz7t5KusHK4kWhsSzbnXF77Wpafkic/vX4NtxxNtqUbWNBbBwZGHVk2F6JO X-Received: by 2002:a17:906:dc8d:b0:6f2:b3b1:3dc9 with SMTP id cs13-20020a170906dc8d00b006f2b3b13dc9mr12890380ejc.148.1650895175059; Mon, 25 Apr 2022 06:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650895175; cv=none; d=google.com; s=arc-20160816; b=g+8amDgi5bdR4spBerS4HqmIFc/FeC0QrrnYSo4dl5cVXg6lQZ27UcF3K/Jk60ARwA HWqRzrIbwo+ghB5IBSMDxotI3cLRUuf7babN07jowEL2A76XsjsS7YAavlmQZX7MmAwK 36fO+J90yFu0uDFbEBo0OlMcwifx3GE2PSuuZlzusteLVWHMOs4k053CQy9AOqe5N6A+ tcXlDjwvTkCLHvr7xMk5wwwl2fRBxL9SR1QgE5xRfLY40PpgvdE1VKbDR3CTmhLTy6xs 2/vVlxsD5Kv4zaDAUn27ylB0p+DanQFBSZgk0wViFT476GKilt9CUa9eqJTw8j/1aSeJ gnYA== 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=bM2/tCYZOySQ2L8dJ5KLoZ8pJWMYda4IsoD+qngUGaE=; b=lk1pJjNtkxIroRBiOGrTpa/WoymzXJ6657dpKNebddxLkpC0eI0ULkVnOMXgMfgib2 PkHg4S2VbI9iiR+64pDKL4R3aCALCmPebvYr/ULDCv30xJOCukmBlFMzHeFN7aWfnt8+ 4NEFfqHTCCZxw0kj0ux017T8+CnTl/5FnVdz2yIWvbqxnvWfR1hsu7hUwjLoOIKL+OY2 GPkqB1sPD6wTN0q1yX17pYbQ/TXWd7coIYQC9uUaAyPZiJK0H1arhYOyoc7Wu4SnM3ra cQxQ+jpNWPDgs+Vo91aCr8L3k0+ffuHJU6OIvn5tM10vzWQgtFLzIvvcIpWDVu5/cGEZ B4pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kJnkUytx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id ho10-20020a1709070e8a00b006f361f9f173si10699859ejc.164.2022.04.25.06.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 06:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kJnkUytx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 672D683E33; Mon, 25 Apr 2022 15:59:33 +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="kJnkUytx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1881B83D53; Mon, 25 Apr 2022 15:59:19 +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.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=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 B5D6883BBF for ; Mon, 25 Apr 2022 15:59:14 +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=grandpaul@gmail.com Received: by mail-pl1-x635.google.com with SMTP id d15so27215550pll.10 for ; Mon, 25 Apr 2022 06:59:14 -0700 (PDT) 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=bM2/tCYZOySQ2L8dJ5KLoZ8pJWMYda4IsoD+qngUGaE=; b=kJnkUytxskK2kTEhjZJX2qx8QM0sWhBlF61YjK9QG7oM6pMkBrcucupiYOQOmW7YPN 26H/YcpV41trk7ZqScRYmNqc08puaqfJ9dZhfszDUqqtvHzKUY1IMbYDFSceOGbi+Z5W SWG59alI0wzl0rqWRdKT94+6Oh/6RYdnZquYqBx2qmPO9UCpilHlri8UvJgLlcCmnDb8 sziEvwmj5mYtpRxg1+YCWKsNPMYpR41vmAwxR3h2L+hgFJ7QNfHYGTXO5E2ZrMVuT2U4 L509xv02DgQ8sRTmFIUGA0Qf8cFVl+CAsEfyAwxzEmzDolY+4yazx1VcDK6lxG0dgOub P2Jw== 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=bM2/tCYZOySQ2L8dJ5KLoZ8pJWMYda4IsoD+qngUGaE=; b=cLKMd2v9oqPQ6CLh0rca6421uoGf+AZ7PHqoR8Ji6oaD1pguarHSlYU7bl9csVDctm 4ztRCHOlUStp/GkbVEWEfmCq2SWSo9zhRUoGZ/WSf1vIJ9RR/6iCCuLwGGG3HV2BXtJz 7VjO0J72fl28fX5Oh80NvzP6mBZ/ewHrthmhV1TCX5gKb9fKN4iicp55e/EOY5rYfsa5 A6V1ei7Drgn/Klyl322Ow4AeGfSSqPGKzLSOBSUtzvm+lPAPPYcYmOikl7Lnu3R49wX0 UHQYGBc0QhUZQcq2ISYtrNQSRrVe56e+z2rxiVsGMgqOxJ3+3GOXgElH1fzgma+AW0HE KVeA== X-Gm-Message-State: AOAM531LExwNzA4YfObKRNWVWKG733zPJDrVXle+H6HMAd8Jkwq4vwMw rOTdbhuZ3xU7OZ216m4L5q+HetJAJXc= X-Received: by 2002:a17:90a:aa98:b0:1b8:5adb:e35f with SMTP id l24-20020a17090aaa9800b001b85adbe35fmr21175130pjq.192.1650895152765; Mon, 25 Apr 2022 06:59:12 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id q13-20020a17090a2e0d00b001cd4989feebsm15843454pjd.55.2022.04.25.06.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 06:59:12 -0700 (PDT) From: Ying-Chun Liu To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Peng Fan , Jaehoon Chung Subject: [PATCH 1/2] drivers: mmc: write protect single boot area Date: Mon, 25 Apr 2022 21:59:02 +0800 Message-Id: <20220425135903.271098-2-grandpaul@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220425135903.271098-1-grandpaul@gmail.com> References: <20220425135903.271098-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)" Add features to write protect single boot area rather than all boot areas. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Peng Fan Cc: Jaehoon Chung --- drivers/mmc/mmc.c | 27 +++++++++++++++++++++++++++ include/mmc.h | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index f6ccd837aa..53f931e993 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -860,6 +860,33 @@ int mmc_boot_wp(struct mmc *mmc) return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 1); } +int mmc_boot_wp_single_partition(struct mmc *mmc, int partition) +{ + u8 value; + int ret; + + value = EXT_CSD_BOOT_WP_B_PWR_WP_EN; + + if (partition == 0) { + value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL; + ret = mmc_switch(mmc, + EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BOOT_WP, + value); + } else if (partition == 1) { + value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL; + value |= EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL; + ret = mmc_switch(mmc, + EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BOOT_WP, + value); + } else { + ret = mmc_boot_wp(mmc); + } + + return ret; +} + #if !CONFIG_IS_ENABLED(MMC_TINY) static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode, bool hsdowngrade) diff --git a/include/mmc.h b/include/mmc.h index 6bdcce881d..a1b3c49af4 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -308,6 +308,10 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx) #define EXT_CSD_HS_CTRL_REL (1 << 0) /* host controlled WR_REL_SET */ +#define EXT_CSD_BOOT_WP_B_SEC_WP_SEL (0x80) /* enable partition selector */ +#define EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL (0x02) /* partition selector to protect */ +#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) /* power-on write-protect */ + #define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */ #define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */ @@ -980,6 +984,18 @@ int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd); */ int mmc_boot_wp(struct mmc *mmc); +/** + * mmc_boot_wp_single_partition() - set write protection to a boot partition. + * + * This function sets a single boot partition to protect and leave the + * other partition writable. + * + * @param mmc the mmc device. + * @param partition 0 - first boot partition, 1 - second boot partition. + * @return 0 for success + */ +int mmc_boot_wp_single_partition(struct mmc *mmc, int partition); + static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data) { return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;