2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-07-21 13:10:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Linaro Limited
|
|
|
|
* Aneesh V <aneesh@ti.com>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2018-04-01 09:22:38 +00:00
|
|
|
#include <environment.h>
|
2017-05-17 14:23:00 +00:00
|
|
|
#include <asm/setup.h>
|
2014-03-28 16:00:04 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2018-02-27 21:45:03 +00:00
|
|
|
#include <asm/omap_common.h>
|
|
|
|
|
2011-07-21 13:10:12 +00:00
|
|
|
static void do_cancel_out(u32 *num, u32 *den, u32 factor)
|
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
if (((*num)/factor*factor == (*num)) &&
|
|
|
|
((*den)/factor*factor == (*den))) {
|
|
|
|
(*num) /= factor;
|
|
|
|
(*den) /= factor;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 16:16:40 +00:00
|
|
|
#ifdef CONFIG_FASTBOOT_FLASH
|
|
|
|
static void omap_set_fastboot_cpu(void)
|
|
|
|
{
|
|
|
|
char *cpu;
|
|
|
|
u32 cpu_rev = omap_revision();
|
|
|
|
|
|
|
|
switch (cpu_rev) {
|
2017-10-13 03:47:05 +00:00
|
|
|
case DRA762_ES1_0:
|
|
|
|
cpu = "DRA762";
|
|
|
|
break;
|
2017-05-22 16:16:40 +00:00
|
|
|
case DRA752_ES1_0:
|
|
|
|
case DRA752_ES1_1:
|
|
|
|
case DRA752_ES2_0:
|
|
|
|
cpu = "DRA752";
|
|
|
|
break;
|
|
|
|
case DRA722_ES1_0:
|
|
|
|
case DRA722_ES2_0:
|
2017-10-13 03:47:04 +00:00
|
|
|
case DRA722_ES2_1:
|
2017-05-22 16:16:40 +00:00
|
|
|
cpu = "DRA722";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cpu = NULL;
|
|
|
|
printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fastboot.cpu", cpu);
|
2017-05-22 16:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_set_fastboot_secure(void)
|
|
|
|
{
|
|
|
|
const char *secure;
|
|
|
|
u32 dev = get_device_type();
|
|
|
|
|
|
|
|
switch (dev) {
|
|
|
|
case EMU_DEVICE:
|
|
|
|
secure = "EMU";
|
|
|
|
break;
|
|
|
|
case HS_DEVICE:
|
|
|
|
secure = "HS";
|
|
|
|
break;
|
|
|
|
case GP_DEVICE:
|
|
|
|
secure = "GP";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
secure = NULL;
|
|
|
|
printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fastboot.secure", secure);
|
2017-05-22 16:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_set_fastboot_board_rev(void)
|
|
|
|
{
|
|
|
|
const char *board_rev;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
board_rev = env_get("board_rev");
|
2017-05-22 16:16:40 +00:00
|
|
|
if (board_rev == NULL)
|
|
|
|
printf("Warning: fastboot.board_rev: unknown board revision\n");
|
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fastboot.board_rev", board_rev);
|
2017-05-22 16:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
|
|
|
|
static u32 omap_mmc_get_part_size(const char *part)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct blk_desc *dev_desc;
|
|
|
|
disk_partition_t info;
|
|
|
|
u64 sz = 0;
|
|
|
|
|
|
|
|
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
|
|
|
|
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("invalid mmc device\n");
|
2017-05-22 16:16:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-21 22:51:59 +00:00
|
|
|
/* Check only for EFI (GPT) partition table */
|
|
|
|
res = part_get_info_by_name_type(dev_desc, part, &info, PART_TYPE_EFI);
|
2017-09-21 20:01:00 +00:00
|
|
|
if (res < 0)
|
2017-05-22 16:16:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Calculate size in bytes */
|
|
|
|
sz = (info.size * (u64)info.blksz);
|
|
|
|
/* to KiB */
|
|
|
|
sz >>= 10;
|
|
|
|
|
|
|
|
return (u32)sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_set_fastboot_userdata_size(void)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
u32 sz_kb;
|
|
|
|
|
|
|
|
sz_kb = omap_mmc_get_part_size("userdata");
|
2017-09-21 20:01:00 +00:00
|
|
|
if (sz_kb == 0)
|
|
|
|
return; /* probably it's not Android partition table */
|
2017-05-22 16:16:40 +00:00
|
|
|
|
2017-09-21 20:01:00 +00:00
|
|
|
sprintf(buf, "%u", sz_kb);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fastboot.userdata_size", buf);
|
2017-05-22 16:16:40 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void omap_set_fastboot_userdata_size(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FASTBOOT_FLASH_MMC_DEV */
|
|
|
|
void omap_set_fastboot_vars(void)
|
|
|
|
{
|
|
|
|
omap_set_fastboot_cpu();
|
|
|
|
omap_set_fastboot_secure();
|
|
|
|
omap_set_fastboot_board_rev();
|
|
|
|
omap_set_fastboot_userdata_size();
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FASTBOOT_FLASH */
|
|
|
|
|
2011-07-21 13:10:12 +00:00
|
|
|
/*
|
|
|
|
* Cancel out the denominator and numerator of a fraction
|
|
|
|
* to get smaller numerator and denominator.
|
|
|
|
*/
|
|
|
|
void cancel_out(u32 *num, u32 *den, u32 den_limit)
|
|
|
|
{
|
|
|
|
do_cancel_out(num, den, 2);
|
|
|
|
do_cancel_out(num, den, 3);
|
|
|
|
do_cancel_out(num, den, 5);
|
|
|
|
do_cancel_out(num, den, 7);
|
|
|
|
do_cancel_out(num, den, 11);
|
|
|
|
do_cancel_out(num, den, 13);
|
|
|
|
do_cancel_out(num, den, 17);
|
|
|
|
while ((*den) > den_limit) {
|
|
|
|
*num /= 2;
|
|
|
|
/*
|
|
|
|
* Round up the denominator so that the final fraction
|
|
|
|
* (num/den) is always <= the desired value
|
|
|
|
*/
|
|
|
|
*den = (*den + 1) / 2;
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2015-08-27 17:37:08 +00:00
|
|
|
__weak void omap_die_id(unsigned int *die_id)
|
|
|
|
{
|
|
|
|
die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
|
|
|
|
}
|
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
void omap_die_id_serial(void)
|
2014-03-28 16:00:04 +00:00
|
|
|
{
|
2015-08-27 17:37:12 +00:00
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
char serial_string[17] = { 0 };
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
omap_die_id((unsigned int *)&die_id);
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("serial#")) {
|
2015-08-27 17:37:12 +00:00
|
|
|
snprintf(serial_string, sizeof(serial_string),
|
|
|
|
"%08x%08x", die_id[0], die_id[3]);
|
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("serial#", serial_string);
|
2014-03-28 16:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 22:34:51 +00:00
|
|
|
|
2015-08-27 17:37:14 +00:00
|
|
|
void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
|
|
|
|
{
|
|
|
|
char *serial_string;
|
|
|
|
unsigned long long serial;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
serial_string = env_get("serial#");
|
2015-08-27 17:37:14 +00:00
|
|
|
|
|
|
|
if (serial_string) {
|
|
|
|
serial = simple_strtoull(serial_string, NULL, 16);
|
|
|
|
|
|
|
|
serialnr->high = (unsigned int) (serial >> 32);
|
|
|
|
serialnr->low = (unsigned int) (serial & 0xffffffff);
|
|
|
|
} else {
|
|
|
|
serialnr->high = 0;
|
|
|
|
serialnr->low = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
void omap_die_id_usbethaddr(void)
|
2015-03-24 22:34:51 +00:00
|
|
|
{
|
2015-08-27 17:37:12 +00:00
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
unsigned char mac[6] = { 0 };
|
2015-03-24 22:34:51 +00:00
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
omap_die_id((unsigned int *)&die_id);
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("usbethaddr")) {
|
2015-08-27 17:37:12 +00:00
|
|
|
/*
|
|
|
|
* Create a fake MAC address from the processor ID code.
|
|
|
|
* First byte is 0x02 to signify locally administered.
|
|
|
|
*/
|
|
|
|
mac[0] = 0x02;
|
|
|
|
mac[1] = die_id[3] & 0xff;
|
|
|
|
mac[2] = die_id[2] & 0xff;
|
|
|
|
mac[3] = die_id[1] & 0xff;
|
|
|
|
mac[4] = die_id[0] & 0xff;
|
|
|
|
mac[5] = (die_id[0] >> 8) & 0xff;
|
|
|
|
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr("usbethaddr", mac);
|
2017-11-23 13:14:17 +00:00
|
|
|
|
|
|
|
if (!env_get("ethaddr"))
|
|
|
|
eth_env_set_enetaddr("ethaddr", mac);
|
2015-03-24 22:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 17:37:13 +00:00
|
|
|
|
|
|
|
void omap_die_id_display(void)
|
|
|
|
{
|
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
|
|
|
|
omap_die_id(die_id);
|
|
|
|
|
2016-06-02 09:43:16 +00:00
|
|
|
printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
|
|
|
|
die_id[1], die_id[0]);
|
2015-08-27 17:37:13 +00:00
|
|
|
}
|