Skip to content

Commit

Permalink
Add option to select MMC hardware partition.
Browse files Browse the repository at this point in the history
Signed-off-by: Zixun LI <[email protected]>
  • Loading branch information
HiFiPhile committed May 4, 2023
1 parent e05486a commit 7c4fa5d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
25 changes: 25 additions & 0 deletions driver/Config.in.nvm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions driver/mci_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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

/*-----------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions include/mci_media.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7c4fa5d

Please sign in to comment.