Skip to content

Commit 7988949

Browse files
committed
Add option to select MMC hardware partition.
Signed-off-by: Zixun LI <[email protected]>
1 parent e05486a commit 7988949

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

driver/Config.in.nvm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ config FATFS
116116
depends on SDCARD
117117
default y if SDCARD
118118

119+
choice
120+
prompt "MMC partition number"
121+
depends on SDCARD
122+
default MMC_PART_0
123+
help
124+
MMC hardware partition device number on the platform where the
125+
image is stored. Note that this is not related to any software
126+
defined partition table but instead if we are in the user area, which is
127+
partition 0 or the first boot partition, which is 1 or some other defined
128+
partition.
129+
130+
config MMC_PART_0
131+
bool "User area"
132+
133+
config MMC_PART_1
134+
bool "Boot partition 1"
135+
136+
config MMC_PART_2
137+
bool "Boot partition 2"
138+
139+
config MMC_PART_CUR
140+
bool "Current booting partition"
141+
142+
endchoice
143+
119144
endmenu
120145

121146
if DATAFLASH

driver/mci_media.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ static int mmc_cmd_send_ext_csd(struct sd_card *sdcard, char *ext_csd)
605605
#define MMC_EXT_CSD_ACCESS_CLEAR_BITS 0x02
606606
#define MMC_EXT_CSD_ACCESS_WRITE_BYTE 0x03
607607

608+
#define EXT_CSD_BYTE_BOOT_CONFIG 179
608609
#define EXT_CSD_BYTE_BUS_WIDTH 183
609610
#define EXT_CSD_BYTE_HS_TIMING 185
610611
#define EXT_CSD_BYTE_POWER_CLASS 187
@@ -666,6 +667,9 @@ static int mmc_card_identify(struct sd_card *sdcard)
666667
if (sdcard->ddr_support)
667668
dbg_printf("MMC: Dual Data Rate supported\n");
668669

670+
sdcard->boot_partition = (ext_csd[EXT_CSD_BYTE_BOOT_CONFIG] >> 3) & 0x07;
671+
dbg_printf("MMC: Current boot partition: %d\n", sdcard->boot_partition);
672+
669673
return 0;
670674
}
671675

@@ -843,6 +847,30 @@ static int mmc_detect_buswidth(struct sd_card *sdcard)
843847

844848
}
845849

850+
#if defined(CONFIG_MMC_PART_1) || defined(CONFIG_MMC_PART_2) || defined(CONFIG_MMC_PART_CUR)
851+
static int mmc_partition_select(struct sd_card *sdcard, unsigned int partition)
852+
{
853+
int ret;
854+
ret = mmc_cmd_switch_fun(sdcard,
855+
MMC_EXT_CSD_ACCESS_CLEAR_BITS,
856+
EXT_CSD_BYTE_BOOT_CONFIG,
857+
0x07);
858+
if (ret)
859+
return ret;
860+
861+
ret = mmc_cmd_switch_fun(sdcard,
862+
MMC_EXT_CSD_ACCESS_SET_BITS,
863+
EXT_CSD_BYTE_BOOT_CONFIG,
864+
partition & 0x07);
865+
if (ret)
866+
return ret;
867+
868+
dbg_info("MMC: partition %d selected\n", partition & 0x07);
869+
870+
return 0;
871+
}
872+
#endif
873+
846874
/*-----------------------------------------------------------------*/
847875

848876
/*
@@ -1094,6 +1122,25 @@ static int mmc_initialization(struct sd_card *sdcard)
10941122
console_printf("MMC: DDR mode could not be enabled: %d\n", ret);
10951123
}
10961124

1125+
#ifdef CONFIG_MMC_PART_1
1126+
ret = mmc_partition_select(sdcard, 1);
1127+
if (ret) {
1128+
console_printf("MMC: Select boot partition 1 failed !\n");
1129+
return ret;
1130+
}
1131+
#elif CONFIG_MMC_PART_2
1132+
ret = mmc_partition_select(sdcard, 2);
1133+
if (ret) {
1134+
console_printf("MMC: Select boot partition 2 failed !\n");
1135+
return ret;
1136+
}
1137+
#elif CONFIG_MMC_PART_CUR
1138+
ret = mmc_partition_select(sdcard, sdcard->boot_partition);
1139+
if (ret) {
1140+
console_printf("MMC: Select current boot partition failed !\n");
1141+
return ret;
1142+
}
1143+
#endif
10971144
return 0;
10981145
}
10991146

include/mci_media.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct sd_card {
177177
unsigned int ddr_support; /* is this card a DDR according to CARDTYPE */
178178
unsigned int read_bl_len;
179179
unsigned int configured_bus_w; /* bus width which we configured */
180+
unsigned int boot_partition; /* MMC boot partition */
180181

181182
struct sd_host *host;
182183

0 commit comments

Comments
 (0)