diff --git a/driver/Config.in.nvm b/driver/Config.in.nvm index 5fa474b8..ffc7d70a 100644 --- a/driver/Config.in.nvm +++ b/driver/Config.in.nvm @@ -116,6 +116,31 @@ config FATFS depends on SDCARD default y if SDCARD +choice + prompt "MMC partition number" + depends on SDCARD + default MMC_PART_0 + help + MMC hardware partition device number on the platform where the + image is stored. Note that this is not related to any software + defined partition table but instead if we are in the user area, which is + partition 0 or the first boot partition, which is 1 or some other defined + partition. + + config MMC_PART_0 + bool "User area" + + config MMC_PART_1 + bool "Boot partition 1" + + config MMC_PART_2 + bool "Boot partition 1" + + config MMC_PART_CUR + bool "Current booting partition" + +endchoice + endmenu if DATAFLASH diff --git a/driver/mci_media.c b/driver/mci_media.c index 2aa1c6f7..0b006208 100644 --- a/driver/mci_media.c +++ b/driver/mci_media.c @@ -605,6 +605,7 @@ static int mmc_cmd_send_ext_csd(struct sd_card *sdcard, char *ext_csd) #define MMC_EXT_CSD_ACCESS_CLEAR_BITS 0x02 #define MMC_EXT_CSD_ACCESS_WRITE_BYTE 0x03 +#define EXT_CSD_BYTE_BOOT_CONFIG 179 #define EXT_CSD_BYTE_BUS_WIDTH 183 #define EXT_CSD_BYTE_HS_TIMING 185 #define EXT_CSD_BYTE_POWER_CLASS 187 @@ -666,6 +667,9 @@ static int mmc_card_identify(struct sd_card *sdcard) if (sdcard->ddr_support) dbg_printf("MMC: Dual Data Rate supported\n"); + sdcard->boot_partition = (ext_csd[EXT_CSD_BYTE_BOOT_CONFIG] > 3) & 0x07; + dbg_printf("MMC: Current boot partition: %d\n", sdcard->boot_partition); + return 0; } @@ -843,6 +847,30 @@ static int mmc_detect_buswidth(struct sd_card *sdcard) } +#if defined(CONFIG_MMC_PART_1) || defined(CONFIG_MMC_PART_2) || defined(CONFIG_MMC_PART_CUR) +static int mmc_partition_select(struct sd_card *sdcard, unsigned int partition) +{ + int ret; + ret = mmc_cmd_switch_fun(sdcard, + MMC_EXT_CSD_ACCESS_CLEAR_BITS, + EXT_CSD_BYTE_BOOT_CONFIG, + 0x07); + if (ret) + return ret; + + ret = mmc_cmd_switch_fun(sdcard, + MMC_EXT_CSD_ACCESS_SET_BITS, + EXT_CSD_BYTE_BOOT_CONFIG, + partition & 0x07); + if (ret) + return ret; + + dbg_info("MMC: partition %d selected\n", partition & 0x07); + + return 0; +} +#endif + /*-----------------------------------------------------------------*/ /* @@ -1094,6 +1122,25 @@ static int mmc_initialization(struct sd_card *sdcard) console_printf("MMC: DDR mode could not be enabled: %d\n", ret); } +#ifdef CONFIG_MMC_PART_1 + ret = mmc_partition_select(sdcard, 1); + if (ret) { + console_printf("MMC: Select boot partition 1 failed !\n"); + return ret; + } +#elif CONFIG_MMC_PART_2 + ret = mmc_partition_select(sdcard, 2); + if (ret) { + console_printf("MMC: Select boot partition 2 failed !\n"); + return ret; + } +#elif CONFIG_MMC_PART_CUR + ret = mmc_partition_select(sdcard, sdcard->boot_partition); + if (ret) { + console_printf("MMC: Select current boot partition failed !\n"); + return ret; + } +#endif return 0; } diff --git a/include/mci_media.h b/include/mci_media.h index 23af1751..470d4a8c 100644 --- a/include/mci_media.h +++ b/include/mci_media.h @@ -177,6 +177,7 @@ struct sd_card { unsigned int ddr_support; /* is this card a DDR according to CARDTYPE */ unsigned int read_bl_len; unsigned int configured_bus_w; /* bus width which we configured */ + unsigned int boot_partition; /* MMC boot partition */ struct sd_host *host;