X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=arch%2Farm%2Fmach-omap2%2Futils.c;h=0b0bf1837c9cb89ac074356f9c3e081b858a63ff;hb=00caae6d47645e68d6e5277aceb69592b49381a6;hp=2d03ebfbd3da42c2fca1c723fe71f943a5cc2de3;hpb=983e37007da506e8145f9b3a9e1dce5c11116fb0;p=u-boot diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c index 2d03ebfbd3..0b0bf1837c 100644 --- a/arch/arm/mach-omap2/utils.c +++ b/arch/arm/mach-omap2/utils.c @@ -5,6 +5,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include +#include #include static void do_cancel_out(u32 *num, u32 *den, u32 factor) { @@ -18,6 +19,121 @@ static void do_cancel_out(u32 *num, u32 *den, u32 factor) } } +#ifdef CONFIG_FASTBOOT_FLASH +static void omap_set_fastboot_cpu(void) +{ + char *cpu; + u32 cpu_rev = omap_revision(); + + switch (cpu_rev) { + case DRA752_ES1_0: + case DRA752_ES1_1: + case DRA752_ES2_0: + cpu = "DRA752"; + break; + case DRA722_ES1_0: + case DRA722_ES2_0: + cpu = "DRA722"; + break; + default: + cpu = NULL; + printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev); + } + + env_set("fastboot.cpu", cpu); +} + +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); + } + + env_set("fastboot.secure", secure); +} + +static void omap_set_fastboot_board_rev(void) +{ + const char *board_rev; + + board_rev = env_get("board_rev"); + if (board_rev == NULL) + printf("Warning: fastboot.board_rev: unknown board revision\n"); + + env_set("fastboot.board_rev", board_rev); +} + +#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) { + error("invalid mmc device\n"); + return 0; + } + + res = part_get_info_by_name(dev_desc, part, &info); + if (res < 0) { + error("cannot find partition: '%s'\n", part); + 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"); + if (sz_kb == 0) { + buf[0] = '\0'; + printf("Warning: fastboot.userdata_size: unable to calc\n"); + } else { + sprintf(buf, "%u", sz_kb); + } + + env_set("fastboot.userdata_size", buf); +} +#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 */ + /* * Cancel out the denominator and numerator of a fraction * to get smaller numerator and denominator. @@ -53,11 +169,11 @@ void omap_die_id_serial(void) omap_die_id((unsigned int *)&die_id); - if (!getenv("serial#")) { + if (!env_get("serial#")) { snprintf(serial_string, sizeof(serial_string), "%08x%08x", die_id[0], die_id[3]); - setenv("serial#", serial_string); + env_set("serial#", serial_string); } } @@ -66,7 +182,7 @@ void omap_die_id_get_board_serial(struct tag_serialnr *serialnr) char *serial_string; unsigned long long serial; - serial_string = getenv("serial#"); + serial_string = env_get("serial#"); if (serial_string) { serial = simple_strtoull(serial_string, NULL, 16); @@ -86,7 +202,7 @@ void omap_die_id_usbethaddr(void) omap_die_id((unsigned int *)&die_id); - if (!getenv("usbethaddr")) { + if (!env_get("usbethaddr")) { /* * Create a fake MAC address from the processor ID code. * First byte is 0x02 to signify locally administered. @@ -98,7 +214,7 @@ void omap_die_id_usbethaddr(void) mac[4] = die_id[0] & 0xff; mac[5] = (die_id[0] >> 8) & 0xff; - eth_setenv_enetaddr("usbethaddr", mac); + eth_env_set_enetaddr("usbethaddr", mac); } }