2 * Copyright 2011 Linaro Limited
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/sys_proto.h>
10 static void do_cancel_out(u32 *num, u32 *den, u32 factor)
13 if (((*num)/factor*factor == (*num)) &&
14 ((*den)/factor*factor == (*den))) {
22 #ifdef CONFIG_FASTBOOT_FLASH
23 static void omap_set_fastboot_cpu(void)
26 u32 cpu_rev = omap_revision();
40 printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
43 env_set("fastboot.cpu", cpu);
46 static void omap_set_fastboot_secure(void)
49 u32 dev = get_device_type();
63 printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
66 env_set("fastboot.secure", secure);
69 static void omap_set_fastboot_board_rev(void)
71 const char *board_rev;
73 board_rev = env_get("board_rev");
74 if (board_rev == NULL)
75 printf("Warning: fastboot.board_rev: unknown board revision\n");
77 env_set("fastboot.board_rev", board_rev);
80 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
81 static u32 omap_mmc_get_part_size(const char *part)
84 struct blk_desc *dev_desc;
85 disk_partition_t info;
88 dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
89 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
90 pr_err("invalid mmc device\n");
94 res = part_get_info_by_name(dev_desc, part, &info);
96 pr_err("cannot find partition: '%s'\n", part);
100 /* Calculate size in bytes */
101 sz = (info.size * (u64)info.blksz);
108 static void omap_set_fastboot_userdata_size(void)
113 sz_kb = omap_mmc_get_part_size("userdata");
116 printf("Warning: fastboot.userdata_size: unable to calc\n");
118 sprintf(buf, "%u", sz_kb);
121 env_set("fastboot.userdata_size", buf);
124 static inline void omap_set_fastboot_userdata_size(void)
127 #endif /* CONFIG_FASTBOOT_FLASH_MMC_DEV */
128 void omap_set_fastboot_vars(void)
130 omap_set_fastboot_cpu();
131 omap_set_fastboot_secure();
132 omap_set_fastboot_board_rev();
133 omap_set_fastboot_userdata_size();
135 #endif /* CONFIG_FASTBOOT_FLASH */
138 * Cancel out the denominator and numerator of a fraction
139 * to get smaller numerator and denominator.
141 void cancel_out(u32 *num, u32 *den, u32 den_limit)
143 do_cancel_out(num, den, 2);
144 do_cancel_out(num, den, 3);
145 do_cancel_out(num, den, 5);
146 do_cancel_out(num, den, 7);
147 do_cancel_out(num, den, 11);
148 do_cancel_out(num, den, 13);
149 do_cancel_out(num, den, 17);
150 while ((*den) > den_limit) {
153 * Round up the denominator so that the final fraction
154 * (num/den) is always <= the desired value
156 *den = (*den + 1) / 2;
160 __weak void omap_die_id(unsigned int *die_id)
162 die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
165 void omap_die_id_serial(void)
167 unsigned int die_id[4] = { 0 };
168 char serial_string[17] = { 0 };
170 omap_die_id((unsigned int *)&die_id);
172 if (!env_get("serial#")) {
173 snprintf(serial_string, sizeof(serial_string),
174 "%08x%08x", die_id[0], die_id[3]);
176 env_set("serial#", serial_string);
180 void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
183 unsigned long long serial;
185 serial_string = env_get("serial#");
188 serial = simple_strtoull(serial_string, NULL, 16);
190 serialnr->high = (unsigned int) (serial >> 32);
191 serialnr->low = (unsigned int) (serial & 0xffffffff);
198 void omap_die_id_usbethaddr(void)
200 unsigned int die_id[4] = { 0 };
201 unsigned char mac[6] = { 0 };
203 omap_die_id((unsigned int *)&die_id);
205 if (!env_get("usbethaddr")) {
207 * Create a fake MAC address from the processor ID code.
208 * First byte is 0x02 to signify locally administered.
211 mac[1] = die_id[3] & 0xff;
212 mac[2] = die_id[2] & 0xff;
213 mac[3] = die_id[1] & 0xff;
214 mac[4] = die_id[0] & 0xff;
215 mac[5] = (die_id[0] >> 8) & 0xff;
217 eth_env_set_enetaddr("usbethaddr", mac);
221 void omap_die_id_display(void)
223 unsigned int die_id[4] = { 0 };
227 printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
228 die_id[1], die_id[0]);