@@ -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
0 commit comments