2015-09-21 15:27:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-02-16 08:08:39 +00:00
|
|
|
#include <mmc.h>
|
2015-09-21 15:27:39 +00:00
|
|
|
#include <spl.h>
|
2016-02-16 08:08:40 +00:00
|
|
|
#include <linux/err.h>
|
2016-01-08 16:51:13 +00:00
|
|
|
|
|
|
|
#include "../sbc/sbc-regs.h"
|
|
|
|
#include "../soc-info.h"
|
|
|
|
#include "boot-device.h"
|
2015-09-21 15:27:39 +00:00
|
|
|
|
2016-02-02 12:11:31 +00:00
|
|
|
u32 spl_boot_device_raw(void)
|
2015-09-21 15:27:39 +00:00
|
|
|
{
|
|
|
|
if (boot_is_swapped())
|
|
|
|
return BOOT_DEVICE_NOR;
|
|
|
|
|
|
|
|
switch (uniphier_get_soc_type()) {
|
2016-03-18 07:41:43 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_SLD3)
|
|
|
|
case SOC_UNIPHIER_SLD3:
|
2016-03-30 11:17:02 +00:00
|
|
|
return uniphier_sld3_boot_device();
|
2015-09-21 15:27:39 +00:00
|
|
|
#endif
|
2016-03-18 07:41:43 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD4) || defined(CONFIG_ARCH_UNIPHIER_PRO4) || \
|
|
|
|
defined(CONFIG_ARCH_UNIPHIER_SLD8)
|
|
|
|
case SOC_UNIPHIER_LD4:
|
|
|
|
case SOC_UNIPHIER_PRO4:
|
|
|
|
case SOC_UNIPHIER_SLD8:
|
2016-03-30 11:17:02 +00:00
|
|
|
return uniphier_ld4_boot_device();
|
2015-09-21 15:27:40 +00:00
|
|
|
#endif
|
2016-03-18 07:41:43 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
|
|
|
|
case SOC_UNIPHIER_PRO5:
|
2016-03-30 11:17:02 +00:00
|
|
|
return uniphier_pro5_boot_device();
|
2015-09-21 15:27:41 +00:00
|
|
|
#endif
|
2016-03-18 07:41:43 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
|
|
|
|
case SOC_UNIPHIER_PXS2:
|
|
|
|
case SOC_UNIPHIER_LD6B:
|
2016-03-30 11:17:02 +00:00
|
|
|
return uniphier_pxs2_boot_device();
|
2016-04-21 05:43:18 +00:00
|
|
|
#endif
|
2016-05-24 12:14:01 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
|
|
|
|
case SOC_UNIPHIER_LD11:
|
2016-04-21 05:43:18 +00:00
|
|
|
case SOC_UNIPHIER_LD20:
|
|
|
|
return uniphier_ld20_boot_device();
|
2015-09-21 15:27:39 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return BOOT_DEVICE_NONE;
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 12:11:31 +00:00
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
2016-06-04 13:39:08 +00:00
|
|
|
u32 mode;
|
2016-02-02 12:11:31 +00:00
|
|
|
|
2016-06-04 13:39:08 +00:00
|
|
|
mode = spl_boot_device_raw();
|
2016-02-02 12:11:31 +00:00
|
|
|
|
2016-06-04 13:39:08 +00:00
|
|
|
switch (uniphier_get_soc_type()) {
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
|
|
|
|
case SOC_UNIPHIER_PXS2:
|
|
|
|
case SOC_UNIPHIER_LD6B:
|
|
|
|
if (mode == BOOT_DEVICE_USB)
|
|
|
|
mode = BOOT_DEVICE_NOR;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
|
|
|
|
case SOC_UNIPHIER_LD11:
|
|
|
|
case SOC_UNIPHIER_LD20:
|
|
|
|
if (mode == BOOT_DEVICE_MMC1 || mode == BOOT_DEVICE_USB)
|
|
|
|
mode = BOOT_DEVICE_BOARD;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mode;
|
2016-02-02 12:11:31 +00:00
|
|
|
}
|
2016-02-16 08:08:39 +00:00
|
|
|
|
2016-05-14 21:42:07 +00:00
|
|
|
u32 spl_boot_mode(const u32 boot_device)
|
2016-02-16 08:08:39 +00:00
|
|
|
{
|
|
|
|
struct mmc *mmc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
|
|
|
|
*
|
|
|
|
* The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of
|
|
|
|
* Extended CSD register; when switching to the Boot Partition 1, the
|
|
|
|
* Boot ROM should issue the SWITCH command (CMD6) with Set Bits for
|
|
|
|
* the Access Bits, but in fact it uses Write Byte for the Access Bits.
|
|
|
|
* As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG
|
|
|
|
* is lost. This bug was fixed for PH1-Pro5 and later SoCs.
|
|
|
|
*
|
|
|
|
* Fixup mmc->part_config here because it is used to determine the
|
|
|
|
* partition which the U-Boot image is read from.
|
|
|
|
*/
|
|
|
|
mmc = find_mmc_device(0);
|
|
|
|
mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK);
|
|
|
|
mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE;
|
|
|
|
|
|
|
|
return MMCSD_MODE_EMMCBOOT;
|
|
|
|
}
|
2016-02-16 08:08:40 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
|
|
|
|
static int find_first_mmc_device(void)
|
|
|
|
{
|
|
|
|
struct mmc *mmc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; (mmc = find_mmc_device(i)); i++) {
|
|
|
|
if (!mmc_init(mmc) && IS_MMC(mmc))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2016-02-16 08:08:42 +00:00
|
|
|
int mmc_get_env_dev(void)
|
|
|
|
{
|
|
|
|
return find_first_mmc_device();
|
|
|
|
}
|
|
|
|
|
2016-02-16 08:08:40 +00:00
|
|
|
static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
int dev;
|
|
|
|
|
|
|
|
dev = find_first_mmc_device();
|
|
|
|
if (dev < 0)
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
setenv_ulong("mmc_first_dev", dev);
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
mmcsetn, 1, 1, do_mmcsetn,
|
2016-05-04 08:47:31 +00:00
|
|
|
"Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
|
2016-02-16 08:08:40 +00:00
|
|
|
""
|
|
|
|
);
|
|
|
|
#endif
|