Revision | 19a29ff362d4cc9e7f420021de57e3193812d4c6 (tree) |
---|---|
Zeit | 2022-07-27 15:19:09 |
Autor | Ying-Chun Liu (PaulLiu) <paul.liu@lina...> |
Commiter | Jaehoon Chung |
drivers: mmc: write protect single boot area
Add features to write protect single boot area rather than all boot
areas.
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
@@ -863,6 +863,33 @@ int mmc_boot_wp(struct mmc *mmc) | ||
863 | 863 | return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 1); |
864 | 864 | } |
865 | 865 | |
866 | +int mmc_boot_wp_single_partition(struct mmc *mmc, int partition) | |
867 | +{ | |
868 | + u8 value; | |
869 | + int ret; | |
870 | + | |
871 | + value = EXT_CSD_BOOT_WP_B_PWR_WP_EN; | |
872 | + | |
873 | + if (partition == 0) { | |
874 | + value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL; | |
875 | + ret = mmc_switch(mmc, | |
876 | + EXT_CSD_CMD_SET_NORMAL, | |
877 | + EXT_CSD_BOOT_WP, | |
878 | + value); | |
879 | + } else if (partition == 1) { | |
880 | + value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL; | |
881 | + value |= EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL; | |
882 | + ret = mmc_switch(mmc, | |
883 | + EXT_CSD_CMD_SET_NORMAL, | |
884 | + EXT_CSD_BOOT_WP, | |
885 | + value); | |
886 | + } else { | |
887 | + ret = mmc_boot_wp(mmc); | |
888 | + } | |
889 | + | |
890 | + return ret; | |
891 | +} | |
892 | + | |
866 | 893 | #if !CONFIG_IS_ENABLED(MMC_TINY) |
867 | 894 | static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode, |
868 | 895 | bool hsdowngrade) |
@@ -308,6 +308,10 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx) | ||
308 | 308 | |
309 | 309 | #define EXT_CSD_HS_CTRL_REL (1 << 0) /* host controlled WR_REL_SET */ |
310 | 310 | |
311 | +#define EXT_CSD_BOOT_WP_B_SEC_WP_SEL (0x80) /* enable partition selector */ | |
312 | +#define EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL (0x02) /* partition selector to protect */ | |
313 | +#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) /* power-on write-protect */ | |
314 | + | |
311 | 315 | #define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */ |
312 | 316 | #define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */ |
313 | 317 |
@@ -991,6 +995,18 @@ int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd); | ||
991 | 995 | */ |
992 | 996 | int mmc_boot_wp(struct mmc *mmc); |
993 | 997 | |
998 | +/** | |
999 | + * mmc_boot_wp_single_partition() - set write protection to a boot partition. | |
1000 | + * | |
1001 | + * This function sets a single boot partition to protect and leave the | |
1002 | + * other partition writable. | |
1003 | + * | |
1004 | + * @param mmc the mmc device. | |
1005 | + * @param partition 0 - first boot partition, 1 - second boot partition. | |
1006 | + * @return 0 for success | |
1007 | + */ | |
1008 | +int mmc_boot_wp_single_partition(struct mmc *mmc, int partition); | |
1009 | + | |
994 | 1010 | static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data) |
995 | 1011 | { |
996 | 1012 | return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE; |