2 * Copyright 2011 Linaro Limited
3 * Aneesh V <aneesh@ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/sys_proto.h>
10 #include <asm/omap_common.h>
12 static void do_cancel_out(u32 *num, u32 *den, u32 factor)
15 if (((*num)/factor*factor == (*num)) &&
16 ((*den)/factor*factor == (*den))) {
24 #ifdef CONFIG_FASTBOOT_FLASH
25 static void omap_set_fastboot_cpu(void)
28 u32 cpu_rev = omap_revision();
46 printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
49 env_set("fastboot.cpu", cpu);
52 static void omap_set_fastboot_secure(void)
55 u32 dev = get_device_type();
69 printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
72 env_set("fastboot.secure", secure);
75 static void omap_set_fastboot_board_rev(void)
77 const char *board_rev;
79 board_rev = env_get("board_rev");
80 if (board_rev == NULL)
81 printf("Warning: fastboot.board_rev: unknown board revision\n");
83 env_set("fastboot.board_rev", board_rev);
86 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
87 static u32 omap_mmc_get_part_size(const char *part)
90 struct blk_desc *dev_desc;
91 disk_partition_t info;
94 dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
95 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
96 pr_err("invalid mmc device\n");
100 /* Check only for EFI (GPT) partition table */
101 res = part_get_info_by_name_type(dev_desc, part, &info, PART_TYPE_EFI);
105 /* Calculate size in bytes */
106 sz = (info.size * (u64)info.blksz);
113 static void omap_set_fastboot_userdata_size(void)
118 sz_kb = omap_mmc_get_part_size("userdata");
120 return; /* probably it's not Android partition table */
122 sprintf(buf, "%u", sz_kb);
123 env_set("fastboot.userdata_size", buf);
126 static inline void omap_set_fastboot_userdata_size(void)
129 #endif /* CONFIG_FASTBOOT_FLASH_MMC_DEV */
130 void omap_set_fastboot_vars(void)
132 omap_set_fastboot_cpu();
133 omap_set_fastboot_secure();
134 omap_set_fastboot_board_rev();
135 omap_set_fastboot_userdata_size();
137 #endif /* CONFIG_FASTBOOT_FLASH */
140 * Cancel out the denominator and numerator of a fraction
141 * to get smaller numerator and denominator.
143 void cancel_out(u32 *num, u32 *den, u32 den_limit)
145 do_cancel_out(num, den, 2);
146 do_cancel_out(num, den, 3);
147 do_cancel_out(num, den, 5);
148 do_cancel_out(num, den, 7);
149 do_cancel_out(num, den, 11);
150 do_cancel_out(num, den, 13);
151 do_cancel_out(num, den, 17);
152 while ((*den) > den_limit) {
155 * Round up the denominator so that the final fraction
156 * (num/den) is always <= the desired value
158 *den = (*den + 1) / 2;
162 __weak void omap_die_id(unsigned int *die_id)
164 die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
167 void omap_die_id_serial(void)
169 unsigned int die_id[4] = { 0 };
170 char serial_string[17] = { 0 };
172 omap_die_id((unsigned int *)&die_id);
174 if (!env_get("serial#")) {
175 snprintf(serial_string, sizeof(serial_string),
176 "%08x%08x", die_id[0], die_id[3]);
178 env_set("serial#", serial_string);
182 void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
185 unsigned long long serial;
187 serial_string = env_get("serial#");
190 serial = simple_strtoull(serial_string, NULL, 16);
192 serialnr->high = (unsigned int) (serial >> 32);
193 serialnr->low = (unsigned int) (serial & 0xffffffff);
200 void omap_die_id_usbethaddr(void)
202 unsigned int die_id[4] = { 0 };
203 unsigned char mac[6] = { 0 };
205 omap_die_id((unsigned int *)&die_id);
207 if (!env_get("usbethaddr")) {
209 * Create a fake MAC address from the processor ID code.
210 * First byte is 0x02 to signify locally administered.
213 mac[1] = die_id[3] & 0xff;
214 mac[2] = die_id[2] & 0xff;
215 mac[3] = die_id[1] & 0xff;
216 mac[4] = die_id[0] & 0xff;
217 mac[5] = (die_id[0] >> 8) & 0xff;
219 eth_env_set_enetaddr("usbethaddr", mac);
221 if (!env_get("ethaddr"))
222 eth_env_set_enetaddr("ethaddr", mac);
226 void omap_die_id_display(void)
228 unsigned int die_id[4] = { 0 };
232 printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
233 die_id[1], die_id[0]);