Commit 0b1aa772 authored by Yann Gautier's avatar Yann Gautier
Browse files

stm32mp: split stm32mp_io_setup function


A new static function boot_mmc is created to simplify code maintenance
of stm32mp_io_setup.

Change-Id: I5c416e567e7e174fb1c2b435925a983c9c55fc40
Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
parent 0e985d70
Showing with 89 additions and 86 deletions
+89 -86
...@@ -162,122 +162,125 @@ static void print_boot_device(boot_api_context_t *boot_context) ...@@ -162,122 +162,125 @@ static void print_boot_device(boot_api_context_t *boot_context)
} }
} }
void stm32mp_io_setup(void) static void boot_mmc(enum mmc_device_type mmc_dev_type,
uint16_t boot_interface_instance)
{ {
int io_result __unused; int io_result __unused;
uint8_t idx; uint8_t idx;
struct stm32image_part_info *part; struct stm32image_part_info *part;
struct stm32_sdmmc2_params params; struct stm32_sdmmc2_params params;
struct mmc_device_info device_info; struct mmc_device_info device_info;
uintptr_t mmc_default_instance;
const partition_entry_t *entry; const partition_entry_t *entry;
boot_api_context_t *boot_context =
(boot_api_context_t *)stm32mp_get_boot_ctx_address();
print_boot_device(boot_context); zeromem(&device_info, sizeof(struct mmc_device_info));
zeromem(&params, sizeof(struct stm32_sdmmc2_params));
if ((boot_context->boot_partition_used_toboot == 1U) || device_info.mmc_dev_type = mmc_dev_type;
(boot_context->boot_partition_used_toboot == 2U)) {
INFO("Boot used partition fsbl%d\n", switch (boot_interface_instance) {
boot_context->boot_partition_used_toboot); case 1:
params.reg_base = STM32MP_SDMMC1_BASE;
break;
case 2:
params.reg_base = STM32MP_SDMMC2_BASE;
break;
case 3:
params.reg_base = STM32MP_SDMMC3_BASE;
break;
default:
WARN("SDMMC instance not found, using default\n");
if (mmc_dev_type == MMC_IS_SD) {
params.reg_base = STM32MP_SDMMC1_BASE;
} else {
params.reg_base = STM32MP_SDMMC2_BASE;
}
break;
} }
io_result = register_io_dev_dummy(&dummy_dev_con); params.device_info = &device_info;
assert(io_result == 0); if (stm32_sdmmc2_mmc_init(&params) != 0) {
ERROR("SDMMC%u init failed\n", boot_interface_instance);
panic();
}
io_result = io_dev_open(dummy_dev_con, dummy_dev_spec, /* Open MMC as a block device to read GPT table */
&dummy_dev_handle); io_result = register_io_dev_block(&mmc_dev_con);
if (io_result != 0) {
panic();
}
io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
&storage_dev_handle);
assert(io_result == 0); assert(io_result == 0);
switch (boot_context->boot_interface_selected) { partition_init(GPT_IMAGE_ID);
case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
dmbsy();
zeromem(&device_info, sizeof(struct mmc_device_info)); io_result = io_dev_close(storage_dev_handle);
zeromem(&params, sizeof(struct stm32_sdmmc2_params)); assert(io_result == 0);
if (boot_context->boot_interface_selected == stm32image_dev_info_spec.device_size =
BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC) { stm32_sdmmc2_mmc_get_device_size();
device_info.mmc_dev_type = MMC_IS_EMMC;
mmc_default_instance = STM32MP_SDMMC2_BASE;
} else {
device_info.mmc_dev_type = MMC_IS_SD;
mmc_default_instance = STM32MP_SDMMC1_BASE;
}
switch (boot_context->boot_interface_instance) { for (idx = 0U; idx < IMG_IDX_NUM; idx++) {
case 1: part = &stm32image_dev_info_spec.part_info[idx];
params.reg_base = STM32MP_SDMMC1_BASE; entry = get_partition_entry(part->name);
break; if (entry == NULL) {
case 2: ERROR("Partition %s not found\n", part->name);
params.reg_base = STM32MP_SDMMC2_BASE;
break;
case 3:
params.reg_base = STM32MP_SDMMC3_BASE;
break;
default:
WARN("SDMMC instance not found, using default\n");
params.reg_base = mmc_default_instance;
break;
}
params.device_info = &device_info;
if (stm32_sdmmc2_mmc_init(&params) != 0) {
ERROR("SDMMC%u init failed\n",
boot_context->boot_interface_instance);
panic(); panic();
} }
/* Open MMC as a block device to read GPT table */ part->part_offset = entry->start;
io_result = register_io_dev_block(&mmc_dev_con); part->bkp_offset = 0U;
if (io_result != 0) { }
panic();
}
io_result = io_dev_open(mmc_dev_con, /*
(uintptr_t)&mmc_block_dev_spec, * Re-open MMC with io_mmc, for better perfs compared to
&storage_dev_handle); * io_block.
assert(io_result == 0); */
io_result = register_io_dev_mmc(&mmc_dev_con);
assert(io_result == 0);
partition_init(GPT_IMAGE_ID); io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle);
assert(io_result == 0);
io_result = io_dev_close(storage_dev_handle); io_result = register_io_dev_stm32image(&stm32image_dev_con);
assert(io_result == 0); assert(io_result == 0);
stm32image_dev_info_spec.device_size = io_result = io_dev_open(stm32image_dev_con,
stm32_sdmmc2_mmc_get_device_size(); (uintptr_t)&stm32image_dev_info_spec,
&image_dev_handle);
assert(io_result == 0);
}
for (idx = 0U; idx < IMG_IDX_NUM; idx++) { void stm32mp_io_setup(void)
part = &stm32image_dev_info_spec.part_info[idx]; {
entry = get_partition_entry(part->name); int io_result __unused;
if (entry == NULL) { boot_api_context_t *boot_context =
ERROR("Partition %s not found\n", (boot_api_context_t *)stm32mp_get_boot_ctx_address();
part->name);
panic();
}
part->part_offset = entry->start; print_boot_device(boot_context);
part->bkp_offset = 0U;
}
/* if ((boot_context->boot_partition_used_toboot == 1U) ||
* Re-open MMC with io_mmc, for better perfs compared to (boot_context->boot_partition_used_toboot == 2U)) {
* io_block. INFO("Boot used partition fsbl%d\n",
*/ boot_context->boot_partition_used_toboot);
io_result = register_io_dev_mmc(&mmc_dev_con); }
assert(io_result == 0);
io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle); io_result = register_io_dev_dummy(&dummy_dev_con);
assert(io_result == 0); assert(io_result == 0);
io_result = register_io_dev_stm32image(&stm32image_dev_con); io_result = io_dev_open(dummy_dev_con, dummy_dev_spec,
assert(io_result == 0); &dummy_dev_handle);
assert(io_result == 0);
io_result = io_dev_open(stm32image_dev_con, switch (boot_context->boot_interface_selected) {
(uintptr_t)&stm32image_dev_info_spec, case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
&image_dev_handle); dmbsy();
assert(io_result == 0); boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
break;
case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
dmbsy();
boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
break; break;
default: default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment