From patchwork Thu May 18 13:01:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 100093 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp708441qge; Thu, 18 May 2017 06:01:44 -0700 (PDT) X-Received: by 10.80.195.195 with SMTP id i3mr3094903edf.83.1495112504814; Thu, 18 May 2017 06:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495112504; cv=none; d=google.com; s=arc-20160816; b=YJNRFPyVT7/o2MIQuyJxXl0qNF6PewC44bvtxccH7ZRaE3NkJdABKIiwRSy4/DPG// 5oHpE3Bd2BgR7M3TQDgf7ziZM09s/TIiE4o3J60WgzJHWlf3KQ9o9tS7fGgenUsmYSjh Imjza1HNSh25OlYuUlo9P69nUHH5RsECE1ShfSEK8tx2ZfyrGopE6gk58nA6/JH0GAIt Xa6Vwn8KpDswHpsacedgNxxtFYhHGk/TRVmSbCcqz9AMGqicBzA/i2/k0twl/Ej//lQG LiatbxQ8ESPG9todO6uuX7biQG2IK78QlcnpBRRND1dVvLPs1SEMAp4ZWytZ/n6X8BaX tYRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=zdW6lwzqwut6kspla+0GDqlnSExBzLUv2yC0pN3xJOs=; b=xY5BSY7d0HqYmsAOmV38xA91F9hlLm5rOvaw0G0ovwPr/nWE2xY6bXNn4gRvqaNn0W PP0m8nUoQVNbeAgTn8l/Y4CTRjd4Nl5Fg2P69zaV9CzUszhvMQTKK1cpir6xTiMHChLW 8NfUqDOOzHA3jmyjU3ulXqrVkm192bav5emmO9Ndpub6RoN3MD53Q6TyVO42h9rhO0Rn HkbEIrrGioZ0Na1VVv2U1O6QDrGDNn46XStQNUPf+oGzwWPHMpW+HhKN1Oe6jV5UMhH+ ZWINpuot3JMo/NLekIMJHKiDGccasteuiLjrPkj2x0oWS+JT1qofRUF72YpcJ/qAZ6OT sgyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id p51si5731893eda.61.2017.05.18.06.01.44; Thu, 18 May 2017 06:01:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 0E1AAC2249A; Thu, 18 May 2017 13:01:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 82979C22223; Thu, 18 May 2017 13:01:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B675AC21BE6; Thu, 18 May 2017 13:01:09 +0000 (UTC) Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) by lists.denx.de (Postfix) with ESMTPS id 3CEBFC21DAA for ; Thu, 18 May 2017 13:01:09 +0000 (UTC) Received: by mail-wr0-f181.google.com with SMTP id l9so33573607wre.1 for ; Thu, 18 May 2017 06:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oQvi5szXCO5MNYNgij+45TswYqFZvUTtVhb6WsIUbSA=; b=Yv945wp1FfVeNYu0eclHMDgSk9IjtmbMfD4pr5lzUuMn6TAoMSkxiSzelQH/UH4Kln H876W+2EWfVAyD+RdAWxeNpx0JF/vf4CZyqeTuMMZFO+Z9zktvZJejWtuj40EhdHIrUN 2fmXyhQ47hzGiSDMBA+Q7qSzcRhxR8/JSd+Pk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oQvi5szXCO5MNYNgij+45TswYqFZvUTtVhb6WsIUbSA=; b=mMs/xupFvlKdwU5nLeD1b8mA7x1/uRGLSz5cH5VUviVLZWaki6lflj3M1TnGyR5uBD 45ytz7QhM0vLojSaMN6bn4pI0CKTEpI6GMYNvAEgDYjnGAFNbuuUeKEdKepxhdCobuEW CZ6OiKA/w+5Wds1p66QUzp/DnLm0nqdwbFfbXBAy1v4A/xkGafynWzSP9ByZe1g9F6rv 3HJyp5JA8r0Dm8KTUyiIRGEatIbJ3YlZ8mk/2L34MfBMvgqDZzNGA1Yx0zKh5bX2B2Oc 1/F67+t2qC7v9mRw6eOwrvkNt3uQQXasKRK4xakqqTXsvhAstlqRMJjAN5qkPaSrvVqW 54Fg== X-Gm-Message-State: AODbwcBDOHpkCX3TQdTpoXLy9NYsKQVWsh7EVKvJpMc87EnW9hAvnexl 1CSSOqCXnfJhZu6845+6lA== X-Received: by 10.46.20.81 with SMTP id 17mr1239527lju.19.1495112468549; Thu, 18 May 2017 06:01:08 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id t4sm922153ljd.1.2017.05.18.06.01.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 May 2017 06:01:07 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Thu, 18 May 2017 16:01:00 +0300 Message-Id: <20170518130102.6820-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170518130102.6820-1-semen.protsenko@linaro.org> References: <20170518130102.6820-1-semen.protsenko@linaro.org> Cc: Praneeth Bajjuri , Tom Rini Subject: [U-Boot] [PATCH 1/3] omap: Add routine for setting fastboot variables X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- 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 #include + +/* 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(); +}