Commit db025004 authored by Angus Ainslie's avatar Angus Ainslie
Browse files

Merge branch 'load-m4-from-hardware-boot-partition' into 'devkit-wip'

Load the M4 code from the same eMMC partition the SPL booted from

See merge request Librem5/uboot-imx!4
parents bb3861a8 35cce237
......@@ -273,6 +273,53 @@ void M4_load_firmware( enum fw_type type )
#endif
}
static struct mmc *prepare_mmc_boot_device(void)
{
struct mmc *mmc;
int err;
int boot_device;
int boot_mode;
__maybe_unused int part;
printf("Finding MMC device\n");
boot_device = spl_boot_device();
boot_mode = spl_boot_mode(boot_device);
err = spl_mmc_find_device(&mmc, boot_device);
if (err) {
printf("spl: mmc find device failed with error: %d\n", err);
return NULL;
}
err = mmc_init(mmc);
if (err) {
printf("spl: mmc init failed with error: %d\n", err);
return NULL;
}
/* Switch to the same partition as where the SPL is stored */
if (boot_mode == MMCSD_MODE_EMMCBOOT) {
int part;
part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
if (part == 7)
part = 0;
printf("spl: switching to mmc hwpartition %d\n", part);
if (CONFIG_IS_ENABLED(MMC_TINY)) {
err = mmc_switch_part(mmc, part);
} else {
err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
}
if (err) {
printf("spl: mmc partition switch failed\n");
return NULL;
}
}
return mmc;
}
void start_M4(void)
{
struct mmc *mmc;
......@@ -280,8 +327,7 @@ void start_M4(void)
void *vect_buffer = (void *)TCML_BASE;
void *buffer = (void *)OCRAM_BASE;
uint32_t status, reg, stack, pc;
int err, count;
int boot_device;
int count;
#if 0
/* use this wait to stop the code for the OpenOCD debugger */
volatile int i = 0;
......@@ -294,19 +340,10 @@ void start_M4(void)
printf("Setting up AIPS\n");
init_aips();
printf("Finding MMC device\n");
boot_device = spl_boot_device();
if(0 == (err = spl_mmc_find_device(&mmc, boot_device)))
{
mmc = prepare_mmc_boot_device();
if (!mmc)
return;
err = mmc_init(mmc);
if (err) {
printf("spl: mmc init failed with error: %d\n", err);
}
else
{
printf("Disabling Cortex M4 clock\n");
clock_enable(CCGR_M4, 0);
......@@ -345,20 +382,12 @@ void start_M4(void)
if(status == ST_READY) {
printf("Cortex M4 ready\n");
}
else
{
} else {
printf("Cortex M4 NOT ready\n");
}
}
}
else
{
printf("spl: mmc find device failed with error: %d\n", err);
}
}
#if defined(CONFIG_M4_LOAD_DDR_TRAINING)
void ddr_load_train_code(enum fw_type type)
{
struct mmc *mmc;
......@@ -366,23 +395,12 @@ void ddr_load_train_code(enum fw_type type)
void *vect_buffer = (void *)TCML_BASE;
void *buffer = (void *)OCRAM_BASE;
uint32_t status, reg, stack, pc;
int err, count;
int boot_device;
int count;
#if defined(CONFIG_M4_LOAD_DDR_TRAINING)
printf("Finding MMC device\n");
boot_device = spl_boot_device();
if(0 == (err = spl_mmc_find_device(&mmc, boot_device)))
{
mmc = prepare_mmc_boot_device();
if (!mmc)
return;
err = mmc_init(mmc);
if (err) {
printf("spl: mmc init failed with error: %d\n", err);
}
else
{
printf("Disabling Cortex M4 clock\n");
clock_enable(CCGR_M4, 0);
......@@ -429,15 +447,10 @@ void ddr_load_train_code(enum fw_type type)
//if( boot_M4() == ST_READY )
M4_load_firmware( type );
}
}
else
{
printf("spl: mmc find device failed with error: %d\n", err);
}
#else
}
#else /* !defined(CONFIG_M4_LOAD_DDR_TRAINING) */
void ddr_load_train_code(enum fw_type type)
{
old_ddr_load_train_code(type);
#endif
}
#endif
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