Commit fa24eca1f20a037d2dcbd1eae7ac8b2ecb1b0423

Authored by Semen Protsenko
Committed by Tom Rini
1 parent cdde7de036

omap: Add routine for setting fastboot variables

This patch reuses new option, which allows us to expose variables
from environment to "fastboot getvar" command. Those variables must be
of "fastboot.%s" format.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

Showing 2 changed files with 121 additions and 0 deletions Side-by-side Diff

arch/arm/include/asm/omap_common.h
... ... @@ -655,6 +655,12 @@
655 655 void omap_die_id_usbethaddr(void);
656 656 void omap_die_id_display(void);
657 657  
  658 +#ifdef CONFIG_FASTBOOT_FLASH
  659 +void omap_set_fastboot_vars(void);
  660 +#else
  661 +static inline void omap_set_fastboot_vars(void) { }
  662 +#endif
  663 +
658 664 void recalibrate_iodelay(void);
659 665  
660 666 void omap_smc1(u32 service, u32 val);
arch/arm/mach-omap2/utils.c
... ... @@ -19,6 +19,121 @@
19 19 }
20 20 }
21 21  
  22 +#ifdef CONFIG_FASTBOOT_FLASH
  23 +static void omap_set_fastboot_cpu(void)
  24 +{
  25 + char *cpu;
  26 + u32 cpu_rev = omap_revision();
  27 +
  28 + switch (cpu_rev) {
  29 + case DRA752_ES1_0:
  30 + case DRA752_ES1_1:
  31 + case DRA752_ES2_0:
  32 + cpu = "DRA752";
  33 + break;
  34 + case DRA722_ES1_0:
  35 + case DRA722_ES2_0:
  36 + cpu = "DRA722";
  37 + break;
  38 + default:
  39 + cpu = NULL;
  40 + printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev);
  41 + }
  42 +
  43 + setenv("fastboot.cpu", cpu);
  44 +}
  45 +
  46 +static void omap_set_fastboot_secure(void)
  47 +{
  48 + const char *secure;
  49 + u32 dev = get_device_type();
  50 +
  51 + switch (dev) {
  52 + case EMU_DEVICE:
  53 + secure = "EMU";
  54 + break;
  55 + case HS_DEVICE:
  56 + secure = "HS";
  57 + break;
  58 + case GP_DEVICE:
  59 + secure = "GP";
  60 + break;
  61 + default:
  62 + secure = NULL;
  63 + printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev);
  64 + }
  65 +
  66 + setenv("fastboot.secure", secure);
  67 +}
  68 +
  69 +static void omap_set_fastboot_board_rev(void)
  70 +{
  71 + const char *board_rev;
  72 +
  73 + board_rev = getenv("board_rev");
  74 + if (board_rev == NULL)
  75 + printf("Warning: fastboot.board_rev: unknown board revision\n");
  76 +
  77 + setenv("fastboot.board_rev", board_rev);
  78 +}
  79 +
  80 +#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
  81 +static u32 omap_mmc_get_part_size(const char *part)
  82 +{
  83 + int res;
  84 + struct blk_desc *dev_desc;
  85 + disk_partition_t info;
  86 + u64 sz = 0;
  87 +
  88 + dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
  89 + if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
  90 + error("invalid mmc device\n");
  91 + return 0;
  92 + }
  93 +
  94 + res = part_get_info_by_name(dev_desc, part, &info);
  95 + if (res < 0) {
  96 + error("cannot find partition: '%s'\n", part);
  97 + return 0;
  98 + }
  99 +
  100 + /* Calculate size in bytes */
  101 + sz = (info.size * (u64)info.blksz);
  102 + /* to KiB */
  103 + sz >>= 10;
  104 +
  105 + return (u32)sz;
  106 +}
  107 +
  108 +static void omap_set_fastboot_userdata_size(void)
  109 +{
  110 + char buf[16];
  111 + u32 sz_kb;
  112 +
  113 + sz_kb = omap_mmc_get_part_size("userdata");
  114 + if (sz_kb == 0) {
  115 + buf[0] = '\0';
  116 + printf("Warning: fastboot.userdata_size: unable to calc\n");
  117 + } else {
  118 + sprintf(buf, "%u", sz_kb);
  119 + }
  120 +
  121 + setenv("fastboot.userdata_size", buf);
  122 +}
  123 +#else
  124 +static inline void omap_set_fastboot_userdata_size(void)
  125 +{
  126 +}
  127 +#endif /* CONFIG_FASTBOOT_FLASH_MMC_DEV */
  128 +void omap_set_fastboot_vars(void)
  129 +{
  130 + omap_set_fastboot_cpu();
  131 + omap_set_fastboot_secure();
  132 + omap_set_fastboot_board_rev();
  133 + omap_set_fastboot_userdata_size();
  134 +}
  135 +#endif /* CONFIG_FASTBOOT_FLASH */
  136 +
22 137 /*
23 138 * Cancel out the denominator and numerator of a fraction
24 139 * to get smaller numerator and denominator.