Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / arm / mach-omap2 / utils.c
index 1946641eb902af291e357c0a7fc3c1c3208fefdd..6e6791fc6595320c56ea745573c1e88c433d9aac 100644 (file)
@@ -1,12 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2011 Linaro Limited
  * Aneesh V <aneesh@ti.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
+#include <env.h>
+#include <part.h>
 #include <asm/setup.h>
 #include <asm/arch/sys_proto.h>
+#include <asm/omap_common.h>
+
 static void do_cancel_out(u32 *num, u32 *den, u32 factor)
 {
        while (1) {
@@ -26,6 +29,11 @@ static void omap_set_fastboot_cpu(void)
        u32 cpu_rev = omap_revision();
 
        switch (cpu_rev) {
+       case DRA762_ES1_0:
+       case DRA762_ABZ_ES1_0:
+       case DRA762_ACD_ES1_0:
+               cpu = "DRA762";
+               break;
        case DRA752_ES1_0:
        case DRA752_ES1_1:
        case DRA752_ES2_0:
@@ -33,6 +41,7 @@ static void omap_set_fastboot_cpu(void)
                break;
        case DRA722_ES1_0:
        case DRA722_ES2_0:
+       case DRA722_ES2_1:
                cpu = "DRA722";
                break;
        default:
@@ -40,7 +49,7 @@ static void omap_set_fastboot_cpu(void)
                printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
        }
 
-       setenv("fastboot.cpu", cpu);
+       env_set("fastboot.cpu", cpu);
 }
 
 static void omap_set_fastboot_secure(void)
@@ -63,39 +72,38 @@ static void omap_set_fastboot_secure(void)
                printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
        }
 
-       setenv("fastboot.secure", secure);
+       env_set("fastboot.secure", secure);
 }
 
 static void omap_set_fastboot_board_rev(void)
 {
        const char *board_rev;
 
-       board_rev = getenv("board_rev");
+       board_rev = env_get("board_rev");
        if (board_rev == NULL)
                printf("Warning: fastboot.board_rev: unknown board revision\n");
 
-       setenv("fastboot.board_rev", board_rev);
+       env_set("fastboot.board_rev", board_rev);
 }
 
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 static u32 omap_mmc_get_part_size(const char *part)
 {
        int res;
        struct blk_desc *dev_desc;
-       disk_partition_t info;
+       struct disk_partition 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");
+               pr_err("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);
+       /* Check only for EFI (GPT) partition table */
+       res = part_get_info_by_name_type(dev_desc, part, &info, PART_TYPE_EFI);
+       if (res < 0)
                return 0;
-       }
 
        /* Calculate size in bytes */
        sz = (info.size * (u64)info.blksz);
@@ -111,26 +119,36 @@ static void omap_set_fastboot_userdata_size(void)
        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);
-       }
+       if (sz_kb == 0)
+               return; /* probably it's not Android partition table */
 
-       setenv("fastboot.userdata_size", buf);
+       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 */
+#endif /* CONFIG_FASTBOOT_FLASH_MMC */
+
+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);
+}
+
 void omap_set_fastboot_vars(void)
 {
        omap_set_fastboot_cpu();
        omap_set_fastboot_secure();
        omap_set_fastboot_board_rev();
        omap_set_fastboot_userdata_size();
+       omap_set_fastboot_product();
 }
 #endif /* CONFIG_FASTBOOT_FLASH */
 
@@ -169,11 +187,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);
        }
 }
 
@@ -182,7 +200,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);
@@ -202,7 +220,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.
@@ -214,7 +232,10 @@ 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);
+
+               if (!env_get("ethaddr"))
+                       eth_env_set_enetaddr("ethaddr", mac);
        }
 }