[U-Boot] [PATCH 0/3] omap: Provide fastboot variables for fastboot.sh

fastboot.sh is a script used for flashing Android images for TI boards (and can be found in corresponding AOSP sources). This script relies on some fastboot variables, which can be accessed with "fastboot getvar" command.
This patch series exports those variables, which fastboot.sh script relies on. The list of added variables: - "cpu": CPU type (string, like "J6") - "secure": CPU security index (string, like "GP") - "board_rev": board revision (string, like "A.30") - "userdata_size": size of userdata partition (number, in KiB)
Variables are enabled for AM57x EVM and DRA7 EVM boards, which are mainly supported TI boards, capable of Android running.
Sam Protsenko (3): omap: Add routine for setting fastboot variables arm: am57xx: Set fastboot variables in environment arm: dra7: Set fastboot variables in environment
arch/arm/include/asm/omap_common.h | 2 + arch/arm/mach-omap2/utils.c | 134 +++++++++++++++++++++++++++++++++++++ board/ti/am57xx/board.c | 1 + board/ti/dra7xx/evm.c | 1 + 4 files changed, 138 insertions(+)

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 --- arch/arm/include/asm/omap_common.h | 2 + arch/arm/mach-omap2/utils.c | 134 +++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+)
diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h index c1a70b15d0..cede2f7b28 100644 --- a/arch/arm/include/asm/omap_common.h +++ b/arch/arm/include/asm/omap_common.h @@ -643,6 +643,8 @@ void omap_die_id_get_board_serial(struct tag_serialnr *serialnr); void omap_die_id_usbethaddr(void); void omap_die_id_display(void);
+void omap_set_fastboot_vars(void); + void recalibrate_iodelay(void);
void omap_smc1(u32 service, u32 val); diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c index 2d03ebfbd3..0689c879b0 100644 --- a/arch/arm/mach-omap2/utils.c +++ b/arch/arm/mach-omap2/utils.c @@ -6,6 +6,16 @@ */ #include <common.h> #include <asm/arch/sys_proto.h> + +/* Device type bits in CONTROL_STATUS register */ +#define DEVICETYPE_OFFSET 6 +#define DEVICETYPE_MASK (0x7 << DEVICETYPE_OFFSET) +#define OMAP_TYPE_TEST 0x0 +#define OMAP_TYPE_EMU 0x1 +#define OMAP_TYPE_SEC 0x2 +#define OMAP_TYPE_GP 0x3 +#define OMAP_TYPE_BAD 0x4 + static void do_cancel_out(u32 *num, u32 *den, u32 factor) { while (1) { @@ -18,6 +28,122 @@ static void do_cancel_out(u32 *num, u32 *den, u32 factor) } }
+static const char *omap_get_cpu_type(void) +{ + u32 type; + + type = readl((*ctrl)->control_status); + type &= DEVICETYPE_MASK; + type >>= DEVICETYPE_OFFSET; + + switch (type) { + case OMAP_TYPE_EMU: + return "EMU"; + case OMAP_TYPE_SEC: + return "HS"; + case OMAP_TYPE_GP: + return "GP"; + default: + return NULL; + } +} + +static void omap_set_fastboot_cpu(void) +{ + u32 cpu_rev; + char *cpu; + + cpu_rev = omap_revision(); + + switch (cpu_rev) { + case DRA752_ES1_0: + case DRA752_ES1_1: + case DRA752_ES2_0: + cpu = "J6"; + break; + case DRA722_ES1_0: + case DRA722_ES2_0: + cpu = "J6ECO"; + break; + default: + cpu = NULL; + printf("Warning: fastboot.cpu: unknown cpu type %u\n", cpu_rev); + } + + setenv("fastboot.cpu", cpu); +} + +static void omap_set_fastboot_secure(void) +{ + const char *secure; + + secure = omap_get_cpu_type(); + if (secure == NULL) + printf("Warning: fastboot.secure: unknown CPU type\n"); + + setenv("fastboot.secure", secure); +} + +static void omap_set_fastboot_board_rev(void) +{ + const char *board_rev; + + board_rev = getenv("board_rev"); + if (board_rev == NULL) + printf("Warning: fastboot.board_rev: unknown board revision\n"); + + setenv("fastboot.board_rev", board_rev); +} + +#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV +static u32 omap_mmc_get_part_size(const char *part) +{ + int res; + struct blk_desc *dev_desc; + disk_partition_t 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"); + return 0; + } + + res = part_get_info_by_name(dev_desc, part, &info); + if (res < 0) { + error("cannot find partition: '%s'\n", part); + return 0; + } + + /* Calculate size in bytes */ + sz = (info.size * (u64)info.blksz); + /* to KiB */ + sz >>= 10; + + return (u32)sz; +} + +static void omap_set_fastboot_userdata_size(void) +{ + char buf[16]; + 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); + } + + setenv("fastboot.userdata_size", buf); +} +#else +static inline void omap_set_fastboot_userdata_size(void) +{ +} +#endif + /* * Cancel out the denominator and numerator of a fraction * to get smaller numerator and denominator. @@ -111,3 +237,11 @@ void omap_die_id_display(void) printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2], die_id[1], die_id[0]); } + +void omap_set_fastboot_vars(void) +{ + omap_set_fastboot_cpu(); + omap_set_fastboot_secure(); + omap_set_fastboot_board_rev(); + omap_set_fastboot_userdata_size(); +}

On Thursday 18 May 2017 06:31 PM, Sam Protsenko wrote:
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
arch/arm/include/asm/omap_common.h | 2 + arch/arm/mach-omap2/utils.c | 134 +++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+)
diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h index c1a70b15d0..cede2f7b28 100644 --- a/arch/arm/include/asm/omap_common.h +++ b/arch/arm/include/asm/omap_common.h @@ -643,6 +643,8 @@ void omap_die_id_get_board_serial(struct tag_serialnr *serialnr); void omap_die_id_usbethaddr(void); void omap_die_id_display(void);
+void omap_set_fastboot_vars(void);
void recalibrate_iodelay(void);
void omap_smc1(u32 service, u32 val); diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c index 2d03ebfbd3..0689c879b0 100644 --- a/arch/arm/mach-omap2/utils.c +++ b/arch/arm/mach-omap2/utils.c @@ -6,6 +6,16 @@ */ #include <common.h> #include <asm/arch/sys_proto.h>
+/* Device type bits in CONTROL_STATUS register */ +#define DEVICETYPE_OFFSET 6 +#define DEVICETYPE_MASK (0x7 << DEVICETYPE_OFFSET) +#define OMAP_TYPE_TEST 0x0 +#define OMAP_TYPE_EMU 0x1 +#define OMAP_TYPE_SEC 0x2 +#define OMAP_TYPE_GP 0x3 +#define OMAP_TYPE_BAD 0x4
static void do_cancel_out(u32 *num, u32 *den, u32 factor) { while (1) { @@ -18,6 +28,122 @@ static void do_cancel_out(u32 *num, u32 *den, u32 factor) } }
+static const char *omap_get_cpu_type(void) +{
- u32 type;
- type = readl((*ctrl)->control_status);
- type &= DEVICETYPE_MASK;
- type >>= DEVICETYPE_OFFSET;
- switch (type) {
- case OMAP_TYPE_EMU:
return "EMU";
- case OMAP_TYPE_SEC:
return "HS";
- case OMAP_TYPE_GP:
return "GP";
- default:
return NULL;
- }
+}
use get_device_type() and drop this function.
Thanks and regards, Lokesh

On 19 May 2017 at 05:03, Lokesh Vutla lokeshvutla@ti.com wrote:
On Thursday 18 May 2017 06:31 PM, Sam Protsenko wrote:
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
arch/arm/include/asm/omap_common.h | 2 + arch/arm/mach-omap2/utils.c | 134 +++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+)
diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h index c1a70b15d0..cede2f7b28 100644 --- a/arch/arm/include/asm/omap_common.h +++ b/arch/arm/include/asm/omap_common.h @@ -643,6 +643,8 @@ void omap_die_id_get_board_serial(struct tag_serialnr *serialnr); void omap_die_id_usbethaddr(void); void omap_die_id_display(void);
+void omap_set_fastboot_vars(void);
void recalibrate_iodelay(void);
void omap_smc1(u32 service, u32 val); diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c index 2d03ebfbd3..0689c879b0 100644 --- a/arch/arm/mach-omap2/utils.c +++ b/arch/arm/mach-omap2/utils.c @@ -6,6 +6,16 @@ */ #include <common.h> #include <asm/arch/sys_proto.h>
+/* Device type bits in CONTROL_STATUS register */ +#define DEVICETYPE_OFFSET 6 +#define DEVICETYPE_MASK (0x7 << DEVICETYPE_OFFSET) +#define OMAP_TYPE_TEST 0x0 +#define OMAP_TYPE_EMU 0x1 +#define OMAP_TYPE_SEC 0x2 +#define OMAP_TYPE_GP 0x3 +#define OMAP_TYPE_BAD 0x4
static void do_cancel_out(u32 *num, u32 *den, u32 factor) { while (1) { @@ -18,6 +28,122 @@ static void do_cancel_out(u32 *num, u32 *den, u32 factor) } }
+static const char *omap_get_cpu_type(void) +{
u32 type;
type = readl((*ctrl)->control_status);
type &= DEVICETYPE_MASK;
type >>= DEVICETYPE_OFFSET;
switch (type) {
case OMAP_TYPE_EMU:
return "EMU";
case OMAP_TYPE_SEC:
return "HS";
case OMAP_TYPE_GP:
return "GP";
default:
return NULL;
}
+}
use get_device_type() and drop this function.
Thanks for suggestion. Fixed that in v2 series. Please review.
Thanks and regards, Lokesh

One can obtain those variables using next commands:
$ fastboot getvar cpu $ fastboot getvar secure $ fastboot getvar board_rev $ fastboot getvar userdata_size
Those variables are needed for fastboot.sh script.
Signed-off-by: Sam Protsenko semen.protsenko@linaro.org --- board/ti/am57xx/board.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 3be697a6ea..c8ebcdbcc8 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -573,6 +573,7 @@ int board_late_init(void) val);
omap_die_id_serial(); + omap_set_fastboot_vars();
am57x_idk_lcd_detect();

On Thursday 18 May 2017 06:31 PM, Sam Protsenko wrote:
One can obtain those variables using next commands:
$ fastboot getvar cpu $ fastboot getvar secure $ fastboot getvar board_rev $ fastboot getvar userdata_size
Those variables are needed for fastboot.sh script.
Signed-off-by: Sam Protsenko semen.protsenko@linaro.org
board/ti/am57xx/board.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 3be697a6ea..c8ebcdbcc8 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -573,6 +573,7 @@ int board_late_init(void) val);
omap_die_id_serial();
- omap_set_fastboot_vars();
Any chance that we can guard this function with CONFIG_*_FASTBOOT?
Thanks and regards, Lokesh

On 19 May 2017 at 05:06, Lokesh Vutla lokeshvutla@ti.com wrote:
On Thursday 18 May 2017 06:31 PM, Sam Protsenko wrote:
One can obtain those variables using next commands:
$ fastboot getvar cpu $ fastboot getvar secure $ fastboot getvar board_rev $ fastboot getvar userdata_size
Those variables are needed for fastboot.sh script.
Signed-off-by: Sam Protsenko semen.protsenko@linaro.org
board/ti/am57xx/board.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 3be697a6ea..c8ebcdbcc8 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -573,6 +573,7 @@ int board_late_init(void) val);
omap_die_id_serial();
omap_set_fastboot_vars();
Any chance that we can guard this function with CONFIG_*_FASTBOOT?
Done. Just sent v2, please review.
Thanks.
Thanks and regards, Lokesh

One can obtain those variables using next commands:
$ fastboot getvar cpu $ fastboot getvar secure $ fastboot getvar board_rev $ fastboot getvar userdata_size
Those variables are needed for fastboot.sh script.
Signed-off-by: Sam Protsenko semen.protsenko@linaro.org --- board/ti/dra7xx/evm.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c index 8c02addd08..7d36f03fa1 100644 --- a/board/ti/dra7xx/evm.c +++ b/board/ti/dra7xx/evm.c @@ -561,6 +561,7 @@ int board_late_init(void) setenv("boot_fit", "1");
omap_die_id_serial(); + omap_set_fastboot_vars(); #endif return 0; }
participants (2)
-
Lokesh Vutla
-
Sam Protsenko