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: 1621957 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kJnkUytx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kn6890hxRz9s0B for ; Mon, 25 Apr 2022 23:59:37 +1000 (AEST) 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-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 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; From patchwork Mon Apr 25 13:59:03 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: 1621958 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=M/nk1X+x; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kn68T2wDgz9s0B for ; Mon, 25 Apr 2022 23:59:53 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 793DE83EA0; Mon, 25 Apr 2022 15:59:39 +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="M/nk1X+x"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8270783C62; Mon, 25 Apr 2022 15:59:23 +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-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 1BBE183953 for ; Mon, 25 Apr 2022 15:59:17 +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-x632.google.com with SMTP id s17so27252920plg.9 for ; Mon, 25 Apr 2022 06:59:17 -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=cv2j9FK2ZRE2zXKhiEG34+Eixsk1+M2hs8yRWDHGnLI=; b=M/nk1X+xvCNEf8m7GEREcT8mTZUtZaLmgV3MpDJrWpPlSjwC73uhJsERC71XAeNPph zJytUoA85W0jZY/tNqD7O0sNKNqJM7btWzYXoAeA0QY94/bRHJaoH51QcsplfrJnCreV f+Uuek4JK1WxRM1z6G+Kz7SsA4zL6n/L9zLm77w+oQroldHR3M4vFfCEOXZ+K8+D4Ilp fEWVrF0CLUW2g/KnyjiyfDKNPW+ArwWDsuxxrDQ1JzrQxHt/alq2pgQ932/V0vvffhy5 l05KkLPNITkpDjnctoVsV1mWB7wnYMpSEZVzXk8n49W9yuVFsKdRHrZ7UmV4P8fciIMC OXyw== 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=cv2j9FK2ZRE2zXKhiEG34+Eixsk1+M2hs8yRWDHGnLI=; b=qonweFytkyvWBBWty8grXW7Wm8kvwMrMT2H6gyIlkhNYsUNXMIend4btI4noytRFIA Ru3B5InHIR9f94fZPy7M2M6RsACBBa6qMSDGc+bUV1q99EHx7lU/RY8gi/u1iVT0+g6Y HW7vsqDCAgcWrnay+230TNqcw1rC6TFgS/+H3T1sqpMy9mcmsN+Nacd2hm2kPrL8TJr5 u5RwNiDsc9ak4NeRIMjXZxlQ7emO9wb9RdzUPGjQAa2DQ5pRgZMdLqY99dmkuvP1a96C vsVAl55JsffwipzPTsj/x0ZCwPWkQGH4OLeYz/5ZrTDW0o/r7orBJV6jjMvHLKCvP71v KIOw== X-Gm-Message-State: AOAM531RqEVT+XgtKk3chk22qhkuW9p8Fkv6lW+qkiZJhPTYG4nif/u6 49uMRavfct5Q+2i12l/s7Yhr3OE3i30= X-Google-Smtp-Source: ABdhPJyPKQD3P6x2+jRvnTBVFXU8GEv7Tjcu1RB927XLHGQVh1dd9DuWcNLm9o7HaolDonNxj/exqA== X-Received: by 2002:a17:903:2ca:b0:156:f1cc:7cb6 with SMTP id s10-20020a17090302ca00b00156f1cc7cb6mr18530505plk.174.1650895155191; Mon, 25 Apr 2022 06:59:15 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id b2-20020a056a000a8200b004f1111c66afsm12856627pfl.148.2022.04.25.06.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 06:59:14 -0700 (PDT) From: Ying-Chun Liu To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Peng Fan , Jaehoon Chung Subject: [PATCH 2/2] cmd: mmc: allow to write protect single boot partition Date: Mon, 25 Apr 2022 21:59:03 +0800 Message-Id: <20220425135903.271098-3-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 arguments for mmc wp to assign which boot partition to protect. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Peng Fan Cc: Jaehoon Chung --- cmd/mmc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/mmc.c b/cmd/mmc.c index 7464f8d00c..7f3e5da6cd 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -1046,6 +1046,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag, { int err; struct mmc *mmc; + int part; mmc = init_mmc_device(curr_device, false); if (!mmc) @@ -1054,7 +1055,14 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag, printf("It is not an eMMC device\n"); return CMD_RET_FAILURE; } - err = mmc_boot_wp(mmc); + + if (argc == 2) { + part = dectoul(argv[1], NULL); + err = mmc_boot_wp_single_partition(mmc, part); + } else { + err = mmc_boot_wp(mmc); + } + if (err) return CMD_RET_FAILURE; printf("boot areas protected\n"); @@ -1064,7 +1072,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag, static struct cmd_tbl cmd_mmc[] = { U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""), U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), - U_BOOT_CMD_MKENT(wp, 1, 0, do_mmc_boot_wp, "", ""), + U_BOOT_CMD_MKENT(wp, 2, 0, do_mmc_boot_wp, "", ""), #if CONFIG_IS_ENABLED(MMC_WRITE) U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), @@ -1138,7 +1146,11 @@ U_BOOT_CMD( " [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n" " UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n" "mmc list - lists available devices\n" - "mmc wp - power on write protect boot partitions\n" + "mmc wp [PART] - power on write protect boot partitions\n" + " arguments:\n" + " PART - [0|1]\n" + " : 0 - first boot partition, 1 - second boot partition\n" + " if not assigned, write protect all boot partitions\n" #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) "mmc hwpartition - does hardware partitioning\n" " arguments (sizes in 512-byte blocks):\n"