u-boot/board/amlogic/odroid-n2/odroid-n2.c
Marek Szyprowski aa3c7912cb board: amlogic: add MMC boot device detection for environment load
Detect eMMC or SD card boot on Odroid-C4/N2 and Khadas VIM3(l) boards and
report proper MMC device for the environment loading code. This allows to
automatically load and store environment variables on the FAT partition
or RAW offset of the MMC device without the need to use different
configurations on eMMC and SD card.

To use this feature with environment stored on FAT partition, one has to
specify an empty device part (i.e. ":1" for the first partition) in
CONFIG_ENV_FAT_DEVICE_AND_PART to let the code to set the device to the
value returned by mmc_get_env_dev() function.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2021-01-11 14:59:55 +01:00

62 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2020 BayLibre, SAS
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#include <common.h>
#include <dm.h>
#include <env.h>
#include <init.h>
#include <net.h>
#include <asm/io.h>
#include <asm/arch/boot.h>
#include <asm/arch/sm.h>
#include <asm/arch/eth.h>
#include <asm/arch/boot.h>
#define EFUSE_MAC_OFFSET 20
#define EFUSE_MAC_SIZE 12
#define MAC_ADDR_LEN 6
int mmc_get_env_dev(void)
{
if (meson_get_boot_device() == BOOT_DEVICE_EMMC)
return 1;
return 0;
}
int misc_init_r(void)
{
u8 mac_addr[MAC_ADDR_LEN];
char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
ssize_t len;
if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) &&
meson_get_soc_rev(tmp, sizeof(tmp)) > 0)
env_set("soc_rev", tmp);
meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
efuse_mac_addr, EFUSE_MAC_SIZE);
if (len != EFUSE_MAC_SIZE)
return 0;
/* MAC is stored in ASCII format, 1bytes = 2characters */
for (int i = 0; i < 6; i++) {
tmp[0] = efuse_mac_addr[i * 2];
tmp[1] = efuse_mac_addr[i * 2 + 1];
tmp[2] = '\0';
mac_addr[i] = simple_strtoul(tmp, NULL, 16);
}
if (is_valid_ethaddr(mac_addr))
eth_env_set_enetaddr("ethaddr", mac_addr);
else
meson_generate_serial_ethaddr();
}
return 0;
}