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 969F4C433F5 for ; Mon, 25 Apr 2022 13:59:35 +0000 (UTC) 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) 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-Google-Smtp-Source: ABdhPJxrhjKMs3RmqQxP//5d8Rm8pQzkB3cSGkTzslcajD9YwZ2hROTFyETQf2O+pLnywnmUsqlmQQ== 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 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)" 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; -- 2.35.1