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>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <part.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>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2018-02-27 21:45:03 +00:00
|
|
|
|
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:
|
2018-04-25 20:56:34 +00:00
|
|
|
case DRA762_ABZ_ES1_0:
|
|
|
|
case DRA762_ACD_ES1_0:
|
2017-10-13 03:47:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-29 15:30:42 +00:00
|
|
|
#ifdef CONFIG_FASTBOOT_FLASH_MMC
|
2017-05-22 16:16:40 +00:00
|
|
|
static u32 omap_mmc_get_part_size(const char *part)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct blk_desc *dev_desc;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2017-05-22 16:16:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-07-16 11:34:44 +00:00
|
|
|
res = part_get_info_by_name(dev_desc, part, &info);
|
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)
|
|
|
|
{
|
|
|
|
}
|
2018-05-29 15:30:42 +00:00
|
|
|
#endif /* CONFIG_FASTBOOT_FLASH_MMC */
|
2019-07-25 17:11:53 +00:00
|
|
|
|
|
|
|
static void omap_set_fastboot_product(void)
|
|
|
|
{
|
|
|
|
const char *board_name;
|
|
|
|
|
|
|
|
board_name = env_get("board_name");
|
|
|
|
if (board_name == NULL)
|
|
|
|
printf("Warning: fastboot.product: unknown board\n");
|
|
|
|
|
|
|
|
env_set("fastboot.product", board_name);
|
|
|
|
}
|
|
|
|
|
2017-05-22 16:16:40 +00:00
|
|
|
void omap_set_fastboot_vars(void)
|
|
|
|
{
|
|
|
|
omap_set_fastboot_cpu();
|
|
|
|
omap_set_fastboot_secure();
|
|
|
|
omap_set_fastboot_board_rev();
|
|
|
|
omap_set_fastboot_userdata_size();
|
2019-07-25 17:11:53 +00:00
|
|
|
omap_set_fastboot_product();
|
2017-05-22 16:16:40 +00:00
|
|
|
}
|
|
|
|
#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
|
|
|
}
|