From patchwork Tue Jul 11 05:56:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Chen X-Patchwork-Id: 107479 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp695744qge; Wed, 12 Jul 2017 04:40:21 -0700 (PDT) X-Received: by 10.80.154.131 with SMTP id p3mr5842975edb.181.1499859621292; Wed, 12 Jul 2017 04:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499859621; cv=none; d=google.com; s=arc-20160816; b=GlrzFJYN9EA0tCJ33iZocciBqAl5AN3ZksoKQlukCyJYBxAsGz6tOMCLgTfXZoeWte 7M+vSunFreKda8evIFtnMXvdghBXg9qyIIzYfL7nleB0vwB7D4ggtOOCpDBhh3vfpPmV /LIqwb1G3iIijZ5Vv26tWAaMqxmSq8GhXBH7+6x2dFAZWJFyKXC1TUoglCaxi0gGTKed 2r1XGfmdTYAJrdh1Ca+lRWJRV00DT0GZwrxQNWaXFBDSvCIMj0rJhbRqOI55dEjEEWef Di8U4p2KPCBfZCsiNWoR270TnNzkGT2vVljkDhX3PqDvFuayABIJS2WmRTo/tXks+3bD mtEQ== 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:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=y30+UczLyyGW/zHElh1TJDH1ej1SptFb1Ej4qfoPOQ0=; b=V73Os8xsH2oBO9yueF0ihE+BqK4WeEIhujT4zSWUzLF+rqFK8aaLgvkclLMI6UBH4n fSOnMKivQhjBrfymdgGc1Abacnu25uScJ0aJG5FEGxIW2CDMuLuTtZi0JqyPbErEfb1J A7zU+wTq5gLB9sAJkTtDeu5U+1qfRgzmgobuCVPOB77OcVSTEFbuEnyz3Z2zOXm95Zms dvuFPa6dy059qw9UCREFn0UaQEpH8Nf8hrhoigwfsI0z6cIwz+zFEG3tMsoYz0rcWRo+ HTA7y8Db0O8s+ZAZvhrHG4wwZgT8aJ5q1tzOoGyD+lW8q96wCvxtuAPXG9JXIFB+f8L2 ydEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=N0791qev; 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 a90si1248162edf.164.2017.07.12.04.40.21; Wed, 12 Jul 2017 04:40:21 -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=N0791qev; 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 A5B98C21DED; Wed, 12 Jul 2017 11:38:52 +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 A5798C21F28; Wed, 12 Jul 2017 11:38:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8DA7CC21C61; Tue, 11 Jul 2017 05:56:21 +0000 (UTC) Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) by lists.denx.de (Postfix) with ESMTPS id 71883C21C4C for ; Tue, 11 Jul 2017 05:56:20 +0000 (UTC) Received: by mail-pg0-f48.google.com with SMTP id j186so60953702pge.2 for ; Mon, 10 Jul 2017 22:56:20 -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; bh=hKZvB8kXWqlekexeYbAc3ljNBbavF/ptr4uO3h0EBns=; b=N0791qev8SBjxaCuUVVaYeV85d/IFjHv+H2nF7NxBQmes2auYC7+F1wqeHrmlsBLWN sWGnC/b4bZIBWhg9kdqhe0p36XBBSnQX/dEbJNMKjHxSXJscuzNM0mUYuYX3ztPLoMQo FzOLBT9ttoTg/maSxpm/dyQc/w6q9gt0fPuNo= 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; bh=hKZvB8kXWqlekexeYbAc3ljNBbavF/ptr4uO3h0EBns=; b=GVpP4jglwOZMLpK+XfAzOrk9XOuOulUqxTzbyTqZ5lYZcy53Pr9CS87yFfFnbcUuWx 21FAXW4sZfdBxFqQ5O6PozINzxL7kkaP9R404VJ3Ex14B5H9Vah8ADTitu0MnKfxABY8 IaVxZCNCraqf1tNTOUlxaYxQauKhJoWJex8MeIhKixDsWa0xt4NQllqZhtNog/ZoVtCa TFLu7Emwugd3s1kPfNgK9hR/ddaSoA1as98mKI2vVxte0azEzaNOE7Evd4cytpK5+rKA eIX22m7uxJQHcJojkHqBnln1n7fEcVWDkwh0HOGwVJKEbqGQepdwyf9lpAAb1mV+0SER aNng== X-Gm-Message-State: AIVw112RTnrIOM7AhPuqrWtB2BtDXYgYQKjnF2g5lkPG8kth0uDjLD9k cHsoxTY4k0EhSvUBv880EA== X-Received: by 10.98.66.198 with SMTP id h67mr843185pfd.2.1499752578714; Mon, 10 Jul 2017 22:56:18 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jul 2017 22:56:17 -0700 (PDT) From: Bin Chen To: u-boot@lists.denx.de Date: Tue, 11 Jul 2017 15:56:03 +1000 Message-Id: <1499752564-10488-1-git-send-email-bin.chen@linaro.org> X-Mailer: git-send-email 1.9.1 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 1/2] [rfc] parse the second area of 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" The second area of android image was intended to put a 2nd stage bootloader but in practice were rarely used (in my knowledge). An proposal was made to the AOSP to (re)use the second area as the dtb[1], This patch itself doesn't depend on that proposal being accepted but it won't be that helpful as well if that proposal won't be accepted. But don't do any harm as well. [1] https://android-review.googlesource.com/#/c/417447/ Signed-off-by: Bin Chen Reviewed-by: Tom Rini --- common/image-android.c | 19 +++++++++++++++++++ include/image.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/common/image-android.c b/common/image-android.c index ee03b96..7daa5fa 100644 --- a/common/image-android.c +++ b/common/image-android.c @@ -146,6 +146,25 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr, return 0; } +int android_image_get_second(const struct andr_img_hdr *hdr, + ulong *second_data, ulong *second_len) +{ + if (!hdr->second_size) { + *second_data = *second_len = 0; + return -1; + } + + *second_data = (unsigned long)hdr; + *second_data += hdr->page_size; + *second_data += ALIGN(hdr->kernel_size, hdr->page_size); + *second_data += ALIGN(hdr->ramdisk_size, hdr->page_size); + + printf("second address is 0x%lx\n",*second_data); + + *second_len = hdr->second_size; + return 0; +} + #if !defined(CONFIG_SPL_BUILD) /** * android_print_contents - prints out the contents of the Android format image diff --git a/include/image.h b/include/image.h index 3f26f9b..8264c52 100644 --- a/include/image.h +++ b/include/image.h @@ -1237,6 +1237,8 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, ulong *os_data, ulong *os_len); int android_image_get_ramdisk(const struct andr_img_hdr *hdr, ulong *rd_data, ulong *rd_len); +int android_image_get_second(const struct andr_img_hdr *hdr, + ulong *second_data, ulong *second_len); ulong android_image_get_end(const struct andr_img_hdr *hdr); ulong android_image_get_kload(const struct andr_img_hdr *hdr); void android_print_contents(const struct andr_img_hdr *hdr); 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"