From patchwork Tue Jul 11 05:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Chen X-Patchwork-Id: 107480 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp699833qge; Wed, 12 Jul 2017 04:44:43 -0700 (PDT) X-Received: by 10.80.137.216 with SMTP id h24mr5815710edh.153.1499859883643; Wed, 12 Jul 2017 04:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499859883; cv=none; d=google.com; s=arc-20160816; b=ys94FZf2FIdqf3Vk1Q2xKYqW2JzmqZGNa7lzVC5pHiCQkTsI871Q/tyH7HVNucogoR 6uLF+Akm1hCyHlA3tba84mdJcvP4rULpCON3Y1OSaPXO/3mq3WPhe5ml5l1PNUI+70uh uZvSapWWdIc4w0M9WuLKI1eQ9rFOlXejzbAifU7kyR4fWDaeyIfk8c8TIa0aP9j5qV2U 1bzzD/XYPucYTIuiX/B+WOSOl25V/2+aC351syWyV1DT08SPY6SInXru+liRigZO34YS tGzlvLhX/4R0sSIwy4zgHnyIvbtct13r25uwMOqadR+Kop/cjISXoAdGbHWs6phCNm3E h7zA== 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=Hc/L0ss4qD8xbDK/Bx7nbhDm3I93iclGQo68Vd+3iBA=; b=E1376oMbmtczwZ/ha1XzRqgqSVQa7ihvAz2zUtOEnmUeSadN2Tt5T/MqdqD1bzM4UZ 58ztJ5q5IqWy1a112ltorI1NjR65qSp8Ylsb4EcHZQvVfTdsR3njXyuCwqYyGQTchJK0 JxySYhTZAfmx0n2NnTB6mxpe5+Ko3AxNDbi2EmikeSh4+rF8PDc/DgZeEKXthsBGfgby zGyCyAfr3YEDzZlG/lhsterfdF85L45RyiRuqskLlk49UTMz27CgdT1rjNtmaBkmM8ha Z5jO9GabbfnBkc61LFW6stQMkOaDhWJXfipw1nrkB9e8KYuyTF6+rmUl19f2u5mcfY/b QYHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=PfdHT0kH; 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 b25si1867629eda.91.2017.07.12.04.44.43; Wed, 12 Jul 2017 04:44:43 -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 header.b=PfdHT0kH; 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 3D387C21DC7; Wed, 12 Jul 2017 11:39:11 +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_H3, RCVD_IN_MSPIKE_WL, 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 B8981C21F7F; Wed, 12 Jul 2017 11:38:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D82DCC21C4C; Tue, 11 Jul 2017 05:56:25 +0000 (UTC) Received: from mail-pg0-f41.google.com (mail-pg0-f41.google.com [74.125.83.41]) by lists.denx.de (Postfix) with ESMTPS id 45291C21C4C for ; Tue, 11 Jul 2017 05:56:25 +0000 (UTC) Received: by mail-pg0-f41.google.com with SMTP id k14so61227253pgr.0 for ; Mon, 10 Jul 2017 22:56:25 -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=Log+o7EjvXLFID9+ITFcBfG41RVQcgK1w/tTqE5N1yw=; b=PfdHT0kHAtcF4OIphgmJ4vglfD6WxlEKDmMG5Gatdz3xQGS+V8D6z0mFsyOfzrDnTM wuJ1VEMbkWWGClgDktUae/bEIRMxwMZJB1DWC+YMMo5MFwdSazYfh4Lg8ENvMIMVTvY4 LLLJ1U3G+dzzxszHsJbvU1DQAe4RFQl5EnAdw= 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=Log+o7EjvXLFID9+ITFcBfG41RVQcgK1w/tTqE5N1yw=; b=RcxzXU9DTbhrcRDUHcXxgHlh9CK4N91UWLlZrwyCdpGOOfqPtlG7kuVF2h88yi7Wnf 89Pbc+DKd+1RsDN6Ditsvg7g/O3yN7MZwP1Mvmc7VH5XteP6sz1tTqOC4cvCtlFSU8pu 7J2NAHKZNCw3xzCphODNaYihmuHb8Mf9HX6J/vzCj8l0eyeAMTL2DLWaN271TWl9C9rm RA0iPW419TNhd6+vuP1RX5K0uD1zy0DVEUU/InyLOHLL7k7TITsr6ifcrxScVWVE35gy q5ijfFNOkV8EhcK9R6wcTHaV8ui+ZnEXasz+0mztmb3+kut8gEkgJAaGirunyprs9Ves YF1g== X-Gm-Message-State: AIVw111ZnOjkv+spbxtcTL5vBlPtwMLK6rA8IeyxoM2d6H8W4n5klB7T 9TVKNmLdppYEEuLhimffSw== X-Received: by 10.99.101.135 with SMTP id z129mr18346409pgb.66.1499752583840; Mon, 10 Jul 2017 22:56:23 -0700 (PDT) Received: from localhost.localdomain (c110-21-50-193.carlnfd1.nsw.optusnet.com.au. [110.21.50.193]) by smtp.gmail.com with ESMTPSA id 75sm30305866pfk.84.2017.07.10.22.56.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jul 2017 22:56:23 -0700 (PDT) From: Bin Chen To: u-boot@lists.denx.de Date: Tue, 11 Jul 2017 15:56:04 +1000 Message-Id: <1499752564-10488-2-git-send-email-bin.chen@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499752564-10488-1-git-send-email-bin.chen@linaro.org> References: <1499752564-10488-1-git-send-email-bin.chen@linaro.org> X-Mailman-Approved-At: Wed, 12 Jul 2017 11:38:13 +0000 Cc: rob.herring@linaro.org, daniel.thompson@linaro.org, john.stultz@linaro.org, elder@linaro.org, jorge.ramirez-ortiz@linaro.org Subject: [U-Boot] [PATCH 2/2] [rfc] support booting arm64 android image 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" It's my understanding that we are supposed to use booti, instead of bootm, for arm64 image. But booti lacks of android image support. Bootm has the andriod image support but lack of the arm64 image handling. So, what is suppose the right way of booting an android arm64 image? or, should we create a separate command? This patch is an invitation for that discussion. It *hacked* the booti command and it aslo assume the dtb is in the second area of android boot image. It also has other belives like u-boot should be in control of where to put the kernnel/ramdisk/dtb images so it ignores the value specified in the android images. Signed-off-by: Bin Chen --- cmd/booti.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/cmd/booti.c b/cmd/booti.c index da6fb01..8fab96c 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -9,8 +9,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -130,7 +132,7 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } -int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +int do_booti_a(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int ret; @@ -159,6 +161,82 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return ret; } +int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct andr_img_hdr *hdr; + ulong kernel_addr = 0; + ulong kernel_len = 0; + ulong ramdisk_addr = 0; + ulong ramdisk_len = 0; + ulong fdt_addr = 0; + ulong fdt_len = 0; + ulong ramdisk_addr_env = 0; + ulong fdt_addr_env = 0; + + if (argc == 4) { + debug("normal %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]); + return do_booti_a(cmdtp, flag, argc, argv); + } + + debug("boot android arm64 bootimage\n"); + hdr = (struct andr_img_hdr *)simple_strtoul(argv[1], NULL, 16); + if (android_image_check_header(hdr)) { + printf("invalid android image\n"); + return -1; + } + + android_image_get_kernel(hdr, false, &kernel_addr, &kernel_len); + android_image_get_ramdisk(hdr, &ramdisk_addr, &ramdisk_len); + android_image_get_second(hdr, &fdt_addr, &fdt_len); + + if (fdt_check_header((void*)fdt_addr)) { + printf(" error: invalid fdt\n"); + return -1; + } + + /* relocate ramdisk and fdt to the address defined by the environment variable. + * that means we'll ignore the load address of ramdisk and dtb defined in the + * abootimg, since it make more sense letting u-boot handling where to put what. + * kernel relocation will be handled in booti_setup + */ + ramdisk_addr_env = getenv_ulong("ramdisk_addr_r", 16, 0);; + fdt_addr_env = getenv_ulong("fdt_addr_r", 16, 0); + + if (!ramdisk_addr_env) { + printf(" error: didn't define ramdisk_addr_r\n"); + return -1; + } + memmove((void *)ramdisk_addr_env, (void *)ramdisk_addr, ramdisk_len); + + if (!fdt_addr_env) { + printf(" error: didn't define fdt_addr_r\n"); + return -1; + } + memmove((void *)fdt_addr_env, (void *)fdt_addr, fdt_len); + + const int max_length = 40; + const int new_argc = 4; + char *new_argv[new_argc]; + + for (int i = 0; i < new_argc; i++) { + new_argv[i] = (char*) malloc(max_length); + } + + strcpy(new_argv[0], "booti"); + snprintf(new_argv[1], max_length, "0x%lx", kernel_addr); + snprintf(new_argv[2], max_length, "0x%lx:%ld", ramdisk_addr_env,ramdisk_len); + snprintf(new_argv[3], max_length, "0x%lx", fdt_addr_env); + + debug("android: %s %s %s %s\n", new_argv[0], new_argv[1], new_argv[2], new_argv[3]); + + int ret = do_booti_a(cmdtp, flag, new_argc, new_argv); + + for (int i = 0; i < new_argc; i++) { + free(new_argv[i]); + } + + return ret; +} #ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] = "[addr [initrd[:size]] [fdt]]\n"