1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2011 Linaro Limited
4 * Aneesh V <aneesh@ti.com>
7 #include <environment.h>
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();
32 case DRA762_ABZ_ES1_0:
33 case DRA762_ACD_ES1_0:
48 printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
51 env_set("fastboot.cpu", cpu);
54 static void omap_set_fastboot_secure(void)
57 u32 dev = get_device_type();
71 printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
74 env_set("fastboot.secure", secure);
77 static void omap_set_fastboot_board_rev(void)
79 const char *board_rev;
81 board_rev = env_get("board_rev");
82 if (board_rev == NULL)
83 printf("Warning: fastboot.board_rev: unknown board revision\n");
85 env_set("fastboot.board_rev", board_rev);
88 #ifdef CONFIG_FASTBOOT_FLASH_MMC
89 static u32 omap_mmc_get_part_size(const char *part)
92 struct blk_desc *dev_desc;
93 disk_partition_t info;
96 dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
97 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
98 pr_err("invalid mmc device\n");
102 /* Check only for EFI (GPT) partition table */
103 res = part_get_info_by_name_type(dev_desc, part, &info, PART_TYPE_EFI);
107 /* Calculate size in bytes */
108 sz = (info.size * (u64)info.blksz);
115 static void omap_set_fastboot_userdata_size(void)
120 sz_kb = omap_mmc_get_part_size("userdata");
122 return; /* probably it's not Android partition table */
124 sprintf(buf, "%u", sz_kb);
125 env_set("fastboot.userdata_size", buf);
128 static inline void omap_set_fastboot_userdata_size(void)
131 #endif /* CONFIG_FASTBOOT_FLASH_MMC */
132 void omap_set_fastboot_vars(void)
134 omap_set_fastboot_cpu();
135 omap_set_fastboot_secure();
136 omap_set_fastboot_board_rev();
137 omap_set_fastboot_userdata_size();
139 #endif /* CONFIG_FASTBOOT_FLASH */
142 * Cancel out the denominator and numerator of a fraction
143 * to get smaller numerator and denominator.
145 void cancel_out(u32 *num, u32 *den, u32 den_limit)
147 do_cancel_out(num, den, 2);
148 do_cancel_out(num, den, 3);
149 do_cancel_out(num, den, 5);
150 do_cancel_out(num, den, 7);
151 do_cancel_out(num, den, 11);
152 do_cancel_out(num, den, 13);
153 do_cancel_out(num, den, 17);
154 while ((*den) > den_limit) {
157 * Round up the denominator so that the final fraction
158 * (num/den) is always <= the desired value
160 *den = (*den + 1) / 2;
164 __weak void omap_die_id(unsigned int *die_id)
166 die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
169 void omap_die_id_serial(void)
171 unsigned int die_id[4] = { 0 };
172 char serial_string[17] = { 0 };
174 omap_die_id((unsigned int *)&die_id);
176 if (!env_get("serial#")) {
177 snprintf(serial_string, sizeof(serial_string),
178 "%08x%08x", die_id[0], die_id[3]);
180 env_set("serial#", serial_string);
184 void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
187 unsigned long long serial;
189 serial_string = env_get("serial#");
192 serial = simple_strtoull(serial_string, NULL, 16);
194 serialnr->high = (unsigned int) (serial >> 32);
195 serialnr->low = (unsigned int) (serial & 0xffffffff);
202 void omap_die_id_usbethaddr(void)
204 unsigned int die_id[4] = { 0 };
205 unsigned char mac[6] = { 0 };
207 omap_die_id((unsigned int *)&die_id);
209 if (!env_get("usbethaddr")) {
211 * Create a fake MAC address from the processor ID code.
212 * First byte is 0x02 to signify locally administered.
215 mac[1] = die_id[3] & 0xff;
216 mac[2] = die_id[2] & 0xff;
217 mac[3] = die_id[1] & 0xff;
218 mac[4] = die_id[0] & 0xff;
219 mac[5] = (die_id[0] >> 8) & 0xff;
221 eth_env_set_enetaddr("usbethaddr", mac);
223 if (!env_get("ethaddr"))
224 eth_env_set_enetaddr("ethaddr", mac);
228 void omap_die_id_display(void)
230 unsigned int die_id[4] = { 0 };
234 printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
235 die_id[1], die_id[0]);