From patchwork Wed Aug 2 14:03:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 109220 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp2820610qge; Wed, 2 Aug 2017 07:04:00 -0700 (PDT) X-Received: by 10.84.215.211 with SMTP id g19mr24756508plj.438.1501682640209; Wed, 02 Aug 2017 07:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501682640; cv=none; d=google.com; s=arc-20160816; b=YR1AgAWSLoXYU3e2sPKzlWOjSWYzCBdbrViD4ck1+ARZ1cGYG1k0ml2cHb/eIY3J1T 6MHaKzbbgSb7nXCVxVx2uyVswrMRXsfDcUvlkTpvsidzAau0394oaCF/ZQhkoUqnj6li fPopX+Oek7uodaMWqaKcRevDM+ERFtmzrKi6hsysaMr/9MG6UKGEm5ahQhXmY/QWztQH 3opFJQgJdZ84MjX9nQ5o74zl0eHwrk+7C8J7Ty7vqIMy1+9iknEeZ7BYtdFzZJNXJsp3 qwm32Z/Q4lDdkmqW5CTBdxaBa4UtYE7qzZ7IyxYPa4LmrAyUvtoAizK9t8QPnc0LD3JG pQCw== 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:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=XnTHrd3xV0oW7T0ajbMC5s7FdbLoNRpmnclz3h2WqhM=; b=PZjZ/AwxgcA/JjfTQOI6jMsQfoQyfkiNbiZcb944R4z2QTTzCPD8bvnKoNL40XezbR Y2PLLaDjI8nLSVUDT2+7PRZloGNqPuYHazTLUCsWJLUQHGdYz41lLys1eDfxseB/lo8Q MILRWEcf7M3mnnPPhecumx+CaD+YcWUlNe1ayqRYo9+eSmaPHIkLd2x5bJLBI561wJm7 AFvfQhT8j3+2VmSKHHc8ATbm1eGORehXa/yhH5icvvR/lCKSfSGHWNQKoXrQ+XV9SVV+ HSsjLYtNcv4z5XYPRaT7P4BtIIKd9sJUsoc5c42v6ftyM7JxtfKicABq1z/cWZAUVkot UdXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=ilppm+4X; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 64si4894953pga.430.2017.08.02.07.03.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Aug 2017 07:04:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=ilppm+4X; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2F3B421DF9676; Wed, 2 Aug 2017 07:01:49 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x22b.google.com (mail-pg0-x22b.google.com [IPv6:2607:f8b0:400e:c05::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D3E5121DF9662 for ; Wed, 2 Aug 2017 07:01:47 -0700 (PDT) Received: by mail-pg0-x22b.google.com with SMTP id v189so21576221pgd.2 for ; Wed, 02 Aug 2017 07:03:58 -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=OzZbQzqy9XOy4hScnBnczPeimrbxcUw2uV7ZVDGm2D0=; b=ilppm+4XkypslQL/35SPIbHa/W0Fo3Thg3kXWxsg/XtXVpKunJcsMDHHlxIOrgWaX2 lUJQtsFrXQcYd3quyaQkCQQMJAsHSewNYzxzFYStgeW6i6fVXl0uaJH5qJMm6R1+iyt6 TXh2mJhN4PCVafgRo49ImaSw2aluUBuRNmaLU= 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=OzZbQzqy9XOy4hScnBnczPeimrbxcUw2uV7ZVDGm2D0=; b=TPx9N+6nQEm3DmPKtJVZCLRcFpSy2VtObdGjabBZOO2r77+sYpEh8RHNuQyPHeOf96 M+jvHfPOJQ21rhiS/sdbv9F2RlOwK7+lmCmbA8LxjnHwy6i8H55zCcGJ2zD/6a7UQtRR wwmITa+w2tsimX92q5Ci2o8eW5GCNxC17vlxqJPXtU6v9j8+G1jrsVvpAgRHUYyXlfKd mqvafUR/5YWy4jBRKWgwGIX2jso5yp61so5bN9gfNAeEiQ9JYp4FLY58pqchdgGxQLlB aRwMjxvgwG84nOEfmoytbsNXyE7S/NqeicXNcszAwhZmEcVu6fqrFDB98dXBgTfMUDT7 V1sw== X-Gm-Message-State: AIVw112dTfblIPI+E1FbGjeHwrzBZqP5fji/RW01dK6Z8Q2tyYEgbsQZ ZVcgEQ+n4t92UoJ8 X-Received: by 10.84.248.78 with SMTP id e14mr24833145pln.459.1501682637988; Wed, 02 Aug 2017 07:03:57 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.63]) by smtp.gmail.com with ESMTPSA id r25sm10554851pgu.7.2017.08.02.07.03.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Aug 2017 07:03:57 -0700 (PDT) From: Jun Nie To: haojian.zhuang@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org, linaro-uefi@lists.linaro.org Date: Wed, 2 Aug 2017 22:03:40 +0800 Message-Id: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v5 1/3] EmbeddedPkg/AndroidFastboot: split android boot header X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jason.liu@linaro.org, shawn.guo@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Split android boot header definition to share code among different applications and libraries. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie --- .../Application/AndroidFastboot/AndroidBootImg.c | 35 ++----------- .../AndroidFastboot/AndroidFastbootApp.h | 1 + .../AndroidFastboot/Arm/BootAndroidBootImg.c | 2 +- EmbeddedPkg/Include/Library/AndroidBootImgLib.h | 58 ++++++++++++++++++++++ 4 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 EmbeddedPkg/Include/Library/AndroidBootImgLib.h -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c index f3e770b..2f7f093 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c @@ -14,32 +14,6 @@ #include "AndroidFastbootApp.h" -#define BOOT_MAGIC "ANDROID!" -#define BOOT_MAGIC_LENGTH sizeof (BOOT_MAGIC) - 1 - -// Check Val (unsigned) is a power of 2 (has only one bit set) -#define IS_POWER_OF_2(Val) (Val != 0 && ((Val & (Val - 1)) == 0)) - -// No documentation for this really - sizes of fields has been determined -// empirically. -#pragma pack(1) -typedef struct { - CHAR8 BootMagic[BOOT_MAGIC_LENGTH]; - UINT32 KernelSize; - UINT32 KernelAddress; - UINT32 RamdiskSize; - UINT32 RamdiskAddress; - UINT32 SecondStageBootloaderSize; - UINT32 SecondStageBootloaderAddress; - UINT32 KernelTaggsAddress; - UINT32 PageSize; - UINT32 Reserved[2]; - CHAR8 ProductName[16]; - CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE]; - UINT32 Id[32]; -} ANDROID_BOOTIMG_HEADER; -#pragma pack() - // Find the kernel and ramdisk in an Android boot.img. // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have the // right magic value), @@ -64,7 +38,8 @@ ParseAndroidBootImg ( Header = (ANDROID_BOOTIMG_HEADER *) BootImg; - if (AsciiStrnCmp (Header->BootMagic, BOOT_MAGIC, BOOT_MAGIC_LENGTH) != 0) { + if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, + ANDROID_BOOT_MAGIC_LENGTH) != 0) { return EFI_INVALID_PARAMETER; } @@ -72,7 +47,7 @@ ParseAndroidBootImg ( return EFI_NOT_FOUND; } - ASSERT (IS_POWER_OF_2 (Header->PageSize)); + ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); *KernelSize = Header->KernelSize; *Kernel = BootImgBytePtr + Header->PageSize; @@ -84,8 +59,8 @@ ParseAndroidBootImg ( + ALIGN_VALUE (Header->KernelSize, Header->PageSize)); } - AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, - BOOTIMG_KERNEL_ARGS_SIZE); + AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, + ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); return EFI_SUCCESS; } diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h index f62660f..e4c5aa3 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h @@ -15,6 +15,7 @@ #ifndef __ANDROID_FASTBOOT_APP_H__ #define __ANDROID_FASTBOOT_APP_H__ +#include #include #include #include diff --git a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c index f446cce..1d9024b 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c +++ b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c @@ -112,7 +112,7 @@ BootAndroidBootImg ( ) { EFI_STATUS Status; - CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE]; + CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE]; VOID *Kernel; UINTN KernelSize; VOID *Ramdisk; diff --git a/EmbeddedPkg/Include/Library/AndroidBootImgLib.h b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h new file mode 100644 index 0000000..06da751 --- /dev/null +++ b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h @@ -0,0 +1,58 @@ +/** @file + + Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2017, Linaro. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __ABOOTIMG_H__ +#define __ABOOTIMG_H__ + +#include +#include +#include + +#include +#include + +#define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE 512 + +#define ANDROID_BOOT_MAGIC "ANDROID!" +#define ANDROID_BOOT_MAGIC_LENGTH (sizeof (ANDROID_BOOT_MAGIC) - 1) + +// No documentation for this really - sizes of fields has been determined +// empirically. +#pragma pack(1) +/* https://android.googlesource.com/platform/system/core/+/master/mkbootimg/bootimg.h */ +typedef struct { + UINT8 BootMagic[ANDROID_BOOT_MAGIC_LENGTH]; + UINT32 KernelSize; + UINT32 KernelAddress; + UINT32 RamdiskSize; + UINT32 RamdiskAddress; + UINT32 SecondStageBootloaderSize; + UINT32 SecondStageBootloaderAddress; + UINT32 KernelTaggsAddress; + UINT32 PageSize; + UINT32 Reserved[2]; + CHAR8 ProductName[16]; + CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE]; + UINT32 Id[32]; +} ANDROID_BOOTIMG_HEADER; +#pragma pack () + +/* Check Val (unsigned) is a power of 2 (has only one bit set) */ +#define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0)) +/* Android boot image page size is not specified, but it should be power of 2 + * and larger than boot header */ +#define IS_VALID_ANDROID_PAGE_SIZE(Val) \ + (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER))) +#endif /* __ABOOTIMG_H__ */ From patchwork Wed Aug 2 14:03:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 109221 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp2820797qge; Wed, 2 Aug 2017 07:04:07 -0700 (PDT) X-Received: by 10.84.131.71 with SMTP id 65mr24964332pld.35.1501682647380; Wed, 02 Aug 2017 07:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501682647; cv=none; d=google.com; s=arc-20160816; b=rPio+LaHhJatljWX+aWC5XSPzgY5v4GQTj6OVs0tQ/hXdZ7nymn6qva97uHIG7FMZI a7RSHTBVox1XY6VGm60P00SLa+miS+8RzGmUqGXp0QhxCf5awJsFvezNvtu08XJMfRcc UEODuWMyKbVZvfcOmbiMhmh+fLsm67VB0NJzuQtm2Gl5Wx6A9+oXiJxb1uScBzS7n7jL J5YHEur82PJtY7EHZ72y+vJTD4eRu3VdYgi/D9cuZXSjBRg9pVxoZwgloDoXfDCxuL1+ D5TsmqUlCTML/ipWduMprz72xXx30ZIy+VSPOeAyYcPH0GCRgAOfzdajiZMmJHzMOGtV KkxQ== 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:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=+Wt56bEyE99kNMBda4ezLl/mmOodN4bxcd5thHsldeo=; b=Y2100Z/4kfXB9FraMzjx8HrD35IwZwAe4kjCBhZvP6gma5veuC45pMJC65az8+wBpT LqmyWuGXJDrxU38eHu1EqveGUiNJcJbkzbEQ8S/3OvPC8n7fRHSKUz9c5vc4hFThlhAb Pd3pl7hcYzj4R8fZziSrBdxMxAkn12yJgThmqAK77Bpu2sarxNnTj+GpXKqDI4nBaTtd LPBtIP0lqdDcOKRh4NLLzCplwNDrj41cA5w6QKcdu4nLzvHe1GsleiSEgFzwQaHAq9Cw xsQdBU7SnjTGvxeOKM3iJ14vxXUA2W+1bR+84ml45aXj7tNJMCTMeyFR1DFxh7T1DQpg GCCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=O/g5Ldsj; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id b23si14465779pfk.679.2017.08.02.07.04.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Aug 2017 07:04:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=O/g5Ldsj; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6AD3B21DF967D; Wed, 2 Aug 2017 07:01:56 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x236.google.com (mail-pg0-x236.google.com [IPv6:2607:f8b0:400e:c05::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2165A21DF9662 for ; Wed, 2 Aug 2017 07:01:55 -0700 (PDT) Received: by mail-pg0-x236.google.com with SMTP id l64so21521720pge.5 for ; Wed, 02 Aug 2017 07:04:05 -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=FwT32m6VR0GnWSSyzOIXyvvZ8Y/qa+rcNfyh85gjNu0=; b=O/g5Ldsjzq9Slw8t/eSDCo9VvS1amK8zItHus0UBtifgQUtzxYk9wsoffXA2XRFdKf P+zQn3PwEPv5z8j/ZMd/36jXTO8nb9/K9Wc5RzxTtKBiNUE5SPAHcRkDTPwsY0GU0yfX p+6NkEk0mCOYqtZSItwkIneBfgb90+3PGapOY= 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=FwT32m6VR0GnWSSyzOIXyvvZ8Y/qa+rcNfyh85gjNu0=; b=a4ku+dUTnvFJiMJ8W3dnBnqh9atoTJr7DR++wL6W8C/xWQMY1Lew4aSk6Hgj/iBSFL qOvjpHCyBPsFCBRDzL5UJLe1QCe75bgH8Uk7+ffvqLS5MAu64Dyvktlhz36VycTAc0po ZSFS4MHbcUI0m9+BMIOJ9NL4VxIfjlx6C6ESCQnWx9P6QyXwj0KK5xhjCGTlF4LkJVX2 +Ihhevv6DG77wRXEtxb6X2kWfdJLi+DR/x9O7kGV6+qxD3dsTUDew11OWAuppU0wrt29 mKbpbK5YTe95+oZ1JR+i7aPlzPKIaJEsD+q6vSnlt98AYWtAW+A3MeT36H2wovr4jiXf nXKw== X-Gm-Message-State: AIVw113cbvUF3RC4MCxjPS0n4ZCkhrsQlzPEUvEXYICEPgTG8nUN5GN5 SV4JChG5XEbEF2QW X-Received: by 10.84.160.198 with SMTP id v6mr17150387plg.312.1501682645215; Wed, 02 Aug 2017 07:04:05 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.63]) by smtp.gmail.com with ESMTPSA id r25sm10554851pgu.7.2017.08.02.07.03.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Aug 2017 07:04:04 -0700 (PDT) From: Jun Nie To: haojian.zhuang@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org, linaro-uefi@lists.linaro.org Date: Wed, 2 Aug 2017 22:03:41 +0800 Message-Id: <1501682622-8223-2-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> References: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> Subject: [edk2] [PATCH v5 2/3] EmbeddedPkg/AndroidBoot: boot android kernel from storage X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jason.liu@linaro.org, shawn.guo@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Add an android kernel loader that could load kernel from storage device. This android boot image BDS add addtitional cmdline/dtb/ramfs support besides kernel that is introduced by Android boot header. This patch is derived from Haojian's code as below link. https://patches.linaro.org/patch/94683/ Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie --- .../Application/AndroidBoot/AndroidBootApp.c | 140 ++++++ .../Application/AndroidBoot/AndroidBootApp.inf | 64 +++ EmbeddedPkg/Include/Library/AndroidBootImgLib.h | 13 + EmbeddedPkg/Include/Protocol/AndroidBootImg.h | 47 ++ .../Library/AndroidBootImgLib/AndroidBootImgLib.c | 471 +++++++++++++++++++++ .../AndroidBootImgLib/AndroidBootImgLib.inf | 48 +++ 6 files changed, 783 insertions(+) create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf create mode 100644 EmbeddedPkg/Include/Protocol/AndroidBootImg.h create mode 100644 EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c create mode 100644 EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c new file mode 100644 index 0000000..977167d --- /dev/null +++ b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c @@ -0,0 +1,140 @@ +/** @file + + Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2017, Linaro. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* Validate the node is media hard drive type */ +EFI_STATUS +ValidateAndroidMediaDevicePath ( + IN EFI_DEVICE_PATH *DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Node, *NextNode; + + NextNode = DevicePath; + while (NextNode != NULL) { + Node = NextNode; + if (IS_DEVICE_PATH_NODE (Node, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP)) { + return EFI_SUCCESS; + } + NextNode = NextDevicePathNode (Node); + } + return EFI_INVALID_PARAMETER; +} + +EFI_STATUS +EFIAPI +AndroidBootAppEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + CHAR16 *BootPathStr; + EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol; + EFI_DEVICE_PATH *DevicePath; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + UINT32 MediaId, BlockSize; + VOID *Buffer; + EFI_HANDLE Handle; + UINTN BootImgSize; + + BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath); + ASSERT (BootPathStr != NULL); + Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, + (VOID **)&EfiDevicePathFromTextProtocol); + ASSERT_EFI_ERROR(Status); + DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr); + ASSERT (DevicePath != NULL); + + Status = ValidateAndroidMediaDevicePath (DevicePath); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, + &DevicePath, &Handle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gBS->OpenProtocol ( + Handle, + &gEfiBlockIoProtocolGuid, + (VOID **) &BlockIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get BlockIo: %r\n", Status)); + return Status; + } + + MediaId = BlockIo->Media->MediaId; + BlockSize = BlockIo->Media->BlockSize; + Buffer = AllocatePages (EFI_SIZE_TO_PAGES (sizeof(ANDROID_BOOTIMG_HEADER))); + if (Buffer == NULL) { + return EFI_BUFFER_TOO_SMALL; + } + /* Load header of boot.img */ + Status = BlockIo->ReadBlocks ( + BlockIo, + MediaId, + 0, + BlockSize, + Buffer + ); + Status = AndroidBootImgGetImgSize (Buffer, &BootImgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status)); + return Status; + } + BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize); + FreePages (Buffer, EFI_SIZE_TO_PAGES (sizeof(ANDROID_BOOTIMG_HEADER))); + + /* Both PartitionStart and PartitionSize are counted as block size. */ + Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BootImgSize)); + if (Buffer == NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + /* Load header of boot.img */ + Status = BlockIo->ReadBlocks ( + BlockIo, + MediaId, + 0, + BootImgSize, + Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to read blocks: %r\n", Status)); + goto EXIT; + } + + Status = AndroidBootImgBoot (Buffer, BootImgSize); + +EXIT: + return Status; +} diff --git a/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf new file mode 100644 index 0000000..f1ee0bd --- /dev/null +++ b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf @@ -0,0 +1,64 @@ +#/** @file +# +# Copyright (c) 2013-2015, ARM Ltd. All rights reserved.
+# Copyright (c) 2017, Linaro. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = AndroidBootApp + FILE_GUID = 3a738b36-b9c5-4763-abbd-6cbd4b25f9ff + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = AndroidBootAppEntryPoint + +[Sources.common] + AndroidBootApp.c + +[LibraryClasses] + AndroidBootImgLib + BaseLib + BaseMemoryLib + BdsLib + DebugLib + DevicePathLib + DxeServicesTableLib + FdtLib + MemoryAllocationLib + PcdLib + PrintLib + UefiApplicationEntryPoint + UefiBootServicesTableLib + UefiLib + UefiRuntimeServicesTableLib + +[Protocols] + gAndroidFastbootPlatformProtocolGuid + gEfiBlockIoProtocolGuid + gEfiDevicePathFromTextProtocolGuid + gEfiSimpleTextOutProtocolGuid + gEfiSimpleTextInProtocolGuid + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[Packages.ARM, Packages.AARCH64] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[Guids] + gFdtTableGuid + +[Pcd] + gEmbeddedTokenSpaceGuid.PcdAndroidBootDevicePath diff --git a/EmbeddedPkg/Include/Library/AndroidBootImgLib.h b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h index 06da751..331caa5 100644 --- a/EmbeddedPkg/Include/Library/AndroidBootImgLib.h +++ b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h @@ -55,4 +55,17 @@ typedef struct { * and larger than boot header */ #define IS_VALID_ANDROID_PAGE_SIZE(Val) \ (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER))) + +EFI_STATUS +AndroidBootImgGetImgSize ( + IN VOID *BootImg, + OUT UINTN *ImgSize + ); + +EFI_STATUS +AndroidBootImgBoot ( + IN VOID *Buffer, + IN UINTN BufferSize + ); + #endif /* __ABOOTIMG_H__ */ diff --git a/EmbeddedPkg/Include/Protocol/AndroidBootImg.h b/EmbeddedPkg/Include/Protocol/AndroidBootImg.h new file mode 100644 index 0000000..1c458d0 --- /dev/null +++ b/EmbeddedPkg/Include/Protocol/AndroidBootImg.h @@ -0,0 +1,47 @@ +/** @file + + Copyright (c) 2017, Linaro. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __ANDROID_BOOTIMG_PROTOCOL_H__ +#define __ANDROID_BOOTIMG_PROTOCOL_H__ + +// +// Protocol interface structure +// +typedef struct _ANDROID_BOOTIMG_PROTOCOL ANDROID_BOOTIMG_PROTOCOL; + +// +// Function Prototypes +// +typedef +EFI_STATUS +(EFIAPI *ANDROID_BOOTIMG_APPEND_KERNEL_ARGS) ( + IN CHAR16 *Args, + IN UINTN Size + ); + +typedef +EFI_STATUS +(EFIAPI *ANDROID_BOOTIMG_UPDATE_DTB) ( + IN EFI_PHYSICAL_ADDRESS OrigDtbBase; + OUT EFI_PHYSICAL_ADDRESS *NewDtbBase; + ); + +struct _ANDROID_BOOTIMG_PROTOCOL { + ANDROID_BOOTIMG_APPEND_KERNEL_ARGS AppendArgs; + ANDROID_BOOTIMG_UPDATE_DTB UpdateDtb; +}; + +extern EFI_GUID gAndroidBootImgProtocolGuid; + +#endif /* __ANDROID_BOOTIMG_PROTOCOL_H__ */ diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c new file mode 100644 index 0000000..da5b5d2 --- /dev/null +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -0,0 +1,471 @@ +/** @file + + Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2017, Linaro. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define FDT_ADDITIONAL_ENTRIES_SIZE 0x400 + +typedef struct { + MEMMAP_DEVICE_PATH Node1; + EFI_DEVICE_PATH_PROTOCOL End; +} MEMORY_DEVICE_PATH; + +STATIC ANDROID_BOOTIMG_PROTOCOL *mAndroidBootImg; + +STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplate = +{ + { + { + HARDWARE_DEVICE_PATH, + HW_MEMMAP_DP, + { + (UINT8)(sizeof (MEMMAP_DEVICE_PATH)), + (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8), + }, + }, // Header + 0, // StartingAddress (set at runtime) + 0 // EndingAddress (set at runtime) + }, // Node1 + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } + } // End +}; + +EFI_STATUS +AndroidBootImgGetImgSize ( + IN VOID *BootImg, + OUT UINTN *ImgSize + ) +{ + ANDROID_BOOTIMG_HEADER *Header; + + Header = (ANDROID_BOOTIMG_HEADER *) BootImg; + + if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, + ANDROID_BOOT_MAGIC_LENGTH) != 0) { + return EFI_INVALID_PARAMETER; + } + + /* The page size is not specified, but it should be power of 2 at least */ + ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); + + /* Get real size of abootimg */ + *ImgSize = ALIGN_VALUE (Header->KernelSize, Header->PageSize) + + ALIGN_VALUE (Header->RamdiskSize, Header->PageSize) + + ALIGN_VALUE (Header->SecondStageBootloaderSize, Header->PageSize) + + Header->PageSize; + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgGetKernelInfo ( + IN VOID *BootImg, + OUT VOID **Kernel, + OUT UINTN *KernelSize + ) +{ + ANDROID_BOOTIMG_HEADER *Header; + + Header = (ANDROID_BOOTIMG_HEADER *) BootImg; + + if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, + ANDROID_BOOT_MAGIC_LENGTH) != 0) { + return EFI_INVALID_PARAMETER; + } + + if (Header->KernelSize == 0) { + return EFI_NOT_FOUND; + } + + ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); + + *KernelSize = Header->KernelSize; + *Kernel = BootImg + Header->PageSize; + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgGetRamdiskInfo ( + IN VOID *BootImg, + OUT VOID **Ramdisk, + OUT UINTN *RamdiskSize + ) +{ + ANDROID_BOOTIMG_HEADER *Header; + UINT8 *BootImgBytePtr; + + // Cast to UINT8 so we can do pointer arithmetic + BootImgBytePtr = (UINT8 *) BootImg; + + Header = (ANDROID_BOOTIMG_HEADER *) BootImg; + + if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, + ANDROID_BOOT_MAGIC_LENGTH) != 0) { + return EFI_INVALID_PARAMETER; + } + + ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); + + *RamdiskSize = Header->RamdiskSize; + + if (Header->RamdiskSize != 0) { + *Ramdisk = (VOID *) (BootImgBytePtr + + Header->PageSize + + ALIGN_VALUE (Header->KernelSize, Header->PageSize)); + } + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgGetSecondBootLoaderInfo ( + IN VOID *BootImg, + OUT VOID **Second, + OUT UINTN *SecondSize + ) +{ + ANDROID_BOOTIMG_HEADER *Header; + UINT8 *BootImgBytePtr; + + // Cast to UINT8 so we can do pointer arithmetic + BootImgBytePtr = (UINT8 *) BootImg; + + Header = (ANDROID_BOOTIMG_HEADER *) BootImg; + + if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, + ANDROID_BOOT_MAGIC_LENGTH) != 0) { + return EFI_INVALID_PARAMETER; + } + + ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); + + *SecondSize = Header->SecondStageBootloaderSize; + + if (Header->SecondStageBootloaderSize != 0) { + *Second = (VOID *) (BootImgBytePtr + + Header->PageSize + + ALIGN_VALUE (Header->KernelSize, Header->PageSize) + + ALIGN_VALUE (Header->RamdiskSize, Header->PageSize)); + } + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgGetKernelArgs ( + IN VOID *BootImg, + OUT CHAR8 *KernelArgs + ) +{ + ANDROID_BOOTIMG_HEADER *Header; + + Header = (ANDROID_BOOTIMG_HEADER *) BootImg; + AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, + ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); + + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgGetFdt ( + IN VOID *BootImg, + IN VOID **FdtBase + ) +{ + UINTN SecondLoaderSize; + EFI_STATUS Status; + + /* Check whether FDT is located in second boot region as some vendor do so, + * because second loader is never used as far as I know. */ + Status = AndroidBootImgGetSecondBootLoaderInfo ( + BootImg, + FdtBase, + &SecondLoaderSize + ); + return Status; +} + +EFI_STATUS +AndroidBootImgUpdateArgs ( + IN VOID *BootImg, + OUT VOID *KernelArgs + ) +{ + CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE]; + EFI_STATUS Status; + + // Get kernel arguments from Android boot image + Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs); + if (EFI_ERROR (Status)) { + return Status; + } + AsciiStrToUnicodeStrS (ImageKernelArgs, KernelArgs, + ANDROID_BOOTIMG_KERNEL_ARGS_SIZE >> 1); + // Append platform kernel arguments + if(mAndroidBootImg->AppendArgs) { + Status = mAndroidBootImg->AppendArgs (KernelArgs, + ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); + } + return Status; +} + +EFI_STATUS +AndroidBootImgLocateFdt ( + IN VOID *BootImg, + IN VOID **FdtBase + ) +{ + INTN Err; + EFI_STATUS Status; + + Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, FdtBase); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + Status = AndroidBootImgGetFdt (BootImg, FdtBase); + if (EFI_ERROR (Status)) { + return Status; + } + Err = fdt_check_header (*FdtBase); + if (Err != 0) { + DEBUG ((DEBUG_ERROR, "ERROR: Device Tree header not valid (Err:%d)\n", + Err)); + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} + +INTN +AndroidBootImgGetChosenNode ( + IN EFI_PHYSICAL_ADDRESS UpdatedFdtBase + ) +{ + IN INTN ChosenNode; + + ChosenNode = fdt_subnode_offset ((CONST VOID *)UpdatedFdtBase, 0, "chosen"); + if (ChosenNode < 0) { + ChosenNode = fdt_add_subnode((VOID *)UpdatedFdtBase, 0, "chosen"); + if (ChosenNode < 0) { + DEBUG ((DEBUG_ERROR, "Fail to find fdt node chosen!\n")); + return 0; + } + } + return ChosenNode; +} + +EFI_STATUS +AndroidBootImgSetProperty64 ( + IN EFI_PHYSICAL_ADDRESS UpdatedFdtBase, + IN INTN ChosenNode, + IN CHAR8 *PropertyName, + IN UINT64 Val + ) +{ + INTN Err; + struct fdt_property *Property; + int Len; + + Property = fdt_get_property_w((VOID *)UpdatedFdtBase, ChosenNode, + PropertyName, &Len); + if (NULL == Property && Len == -FDT_ERR_NOTFOUND) { + Val = cpu_to_fdt64(Val); + Err = fdt_appendprop ((VOID *)UpdatedFdtBase, ChosenNode, + PropertyName, &Val, sizeof (UINT64)); + if (Err) { + DEBUG ((DEBUG_ERROR, "fdt_appendprop() fail: %a\n", fdt_strerror (Err))); + return EFI_INVALID_PARAMETER; + } + } else if (Property != NULL) { + Err = fdt_setprop_u64((VOID *)UpdatedFdtBase, ChosenNode, + PropertyName, Val); + if (Err) { + DEBUG ((DEBUG_ERROR, "fdt_setprop_u64() fail: %a\n", fdt_strerror (Err))); + return EFI_INVALID_PARAMETER; + } + } else { + DEBUG ((DEBUG_ERROR, "Failed to set fdt Property %a\n", PropertyName)); + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} + +EFI_STATUS +AndroidBootImgUpdateFdt ( + IN VOID *BootImg, + IN VOID *FdtBase, + IN VOID *RamdiskData, + IN UINTN RamdiskSize + ) +{ + INTN ChosenNode, Err, NewFdtSize; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS UpdatedFdtBase, NewFdtBase; + + NewFdtSize = (UINTN)fdt_totalsize (FdtBase) + + FDT_ADDITIONAL_ENTRIES_SIZE; + Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, + EFI_SIZE_TO_PAGES (NewFdtSize), &UpdatedFdtBase); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Warning: Failed to reallocate FDT, err %d.\n", + Status)); + return Status; + } + + // Load the Original FDT tree into the new region + Err = fdt_open_into(FdtBase, (VOID*)UpdatedFdtBase, NewFdtSize); + if (Err) { + DEBUG ((DEBUG_ERROR, "fdt_open_into(): %a\n", fdt_strerror (Err))); + Status = EFI_INVALID_PARAMETER; + goto Fdt_Exit; + } + + ChosenNode = AndroidBootImgGetChosenNode(UpdatedFdtBase); + if (!ChosenNode) { + goto Fdt_Exit; + } + + Status = AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, + "linux,initrd-start", + (UINT64)RamdiskData); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } + + Status = AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, + "linux,initrd-end", + (UINT64)(RamdiskData + RamdiskSize)); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } + + if (mAndroidBootImg->UpdateDtb) { + Status = mAndroidBootImg->UpdateDtb (UpdatedFdtBase, &NewFdtBase); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } + } + + Status = gBS->InstallConfigurationTable ( + &gFdtTableGuid, + (VOID *)(UINTN)NewFdtBase + ); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + +Fdt_Exit: + gBS->FreePages (UpdatedFdtBase, EFI_SIZE_TO_PAGES (NewFdtSize)); + return Status; +} + +EFI_STATUS +AndroidBootImgBoot ( + IN VOID *Buffer, + IN UINTN BufferSize + ) +{ + EFI_STATUS Status; + VOID *Kernel; + UINTN KernelSize; + MEMORY_DEVICE_PATH KernelDevicePath; + EFI_HANDLE ImageHandle; + VOID *NewKernelArg; + EFI_LOADED_IMAGE_PROTOCOL *ImageInfo; + VOID *RamdiskData; + UINTN RamdiskSize; + IN VOID *FdtBase; + + Status = gBS->LocateProtocol (&gAndroidBootImgProtocolGuid, NULL, + (VOID **) &mAndroidBootImg); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = AndroidBootImgGetKernelInfo ( + Buffer, + &Kernel, + &KernelSize + ); + if (EFI_ERROR (Status)) { + return Status; + } + + NewKernelArg = AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); + if (NewKernelArg == NULL) { + DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n")); + return EFI_OUT_OF_RESOURCES; + } + + Status = AndroidBootImgUpdateArgs (Buffer, NewKernelArg); + if (EFI_ERROR (Status)) { + FreePool (NewKernelArg); + return Status; + } + + Status = AndroidBootImgGetRamdiskInfo ( + Buffer, + &RamdiskData, + &RamdiskSize + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = AndroidBootImgLocateFdt (Buffer, &FdtBase); + if (EFI_ERROR (Status)) { + FreePool (NewKernelArg); + return Status; + } + + Status = AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, RamdiskSize); + if (EFI_ERROR (Status)) { + FreePool (NewKernelArg); + return Status; + } + + KernelDevicePath = mMemoryDevicePathTemplate; + + KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel; + KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + + KernelSize; + + Status = gBS->LoadImage (TRUE, gImageHandle, + (EFI_DEVICE_PATH *)&KernelDevicePath, + (VOID*)(UINTN)Kernel, KernelSize, &ImageHandle); + + // Set kernel arguments + Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, + (VOID **) &ImageInfo); + ImageInfo->LoadOptions = NewKernelArg; + ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16); + + // Before calling the image, enable the Watchdog Timer for the 5 Minute period + gBS->SetWatchdogTimer (5 * 60, 0x10000, 0, NULL); + // Start the image + Status = gBS->StartImage (ImageHandle, NULL, NULL); + // Clear the Watchdog Timer if the image returns + gBS->SetWatchdogTimer (0, 0x10000, 0, NULL); + return EFI_SUCCESS; +} diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf new file mode 100644 index 0000000..c92bac0 --- /dev/null +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf @@ -0,0 +1,48 @@ +#/** @file +# +# Copyright (c) 2013-2015, ARM Ltd. All rights reserved.
+# Copyright (c) 2017, Linaro. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = AndroidBootImgLib + FILE_GUID = ed3b8739-6fa7-4cb1-8aeb-2496f8fcaefa + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = AndroidBootImgLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + AndroidBootImgLib.c + +[LibraryClasses] + DebugLib + FdtLib + PrintLib + UefiBootServicesTableLib + UefiLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + +[Protocols] + gAndroidBootImgProtocolGuid + +[Guids] + gFdtTableGuid From patchwork Wed Aug 2 14:03:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 109222 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp2820945qge; Wed, 2 Aug 2017 07:04:13 -0700 (PDT) X-Received: by 10.99.176.71 with SMTP id z7mr22167592pgo.78.1501682652691; Wed, 02 Aug 2017 07:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501682652; cv=none; d=google.com; s=arc-20160816; b=PIyaOIOkrA3qo/RfvFbrIB7oEpmGw88WTX9nthoETQyfIXOLBk4fpfL03FfcUzmx+y gEPB233HT6MjlMtSC3thvzWsIBNAuAGWmOIA1ZCm8yWLTwdAZP92BWwMAsn5VdxZpq68 LfizW6KkEda/7KJL8py1hJmLymzglj9Z10i8bX8j3xzxXGjbEN5ZDL7RjmINnY5xErpj zUCZMJQ7JFeoYOhzdktDMPCrArxGRSw6kJsjCGLo1Dswc5vUf2Yxsd3luyh55nQUVLOF Oz7jq9vxD/lVc9FN/q8flm0z4XdpBax4k0eS0eDmQwI1zdAZ8n1bi7WB3F0ZZ8k/cXmD Kysg== 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:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=9+QVhKSlYTiOwPqHWPpzdnFiaCx9S8f9A0Cea5UR6Eg=; b=esNAggYDNSReubi7sMMyjfZXPGnpOqmw42ys5Fw5zAp1o68MqJu0xy4k/rV/gaVu/O 1wHrh0wq3rBxa4idZQG2pKtQGKD4M+yM/u6kfyXdTjL889eSQ+YHpq4PA4QUP6gKPZ5x tXuA8zBVd7rpE3UAcxX3Hud71aA5VxJ6v/47CtO69Oguu8AP8hNaObAP/UlyYhRb5LxM hV11DDmYulpU8o//l6dN8g+OLP1ZLJfTF1L4OUyQGio6oO0l9yRCsW9yXk92rm43e1HA XCFfHYDZSoftpu+kr0npeRGH59aUCvB7guNzXTb6lJQ+UxF9fDueABR9pIJpZ5x76Y8Y Ukjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=gXjFMNiK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id v38si21356757plg.690.2017.08.02.07.04.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Aug 2017 07:04:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=gXjFMNiK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A909D21DF9684; Wed, 2 Aug 2017 07:02:01 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x236.google.com (mail-pg0-x236.google.com [IPv6:2607:f8b0:400e:c05::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3151921DF9662 for ; Wed, 2 Aug 2017 07:02:01 -0700 (PDT) Received: by mail-pg0-x236.google.com with SMTP id y129so21607358pgy.4 for ; Wed, 02 Aug 2017 07:04:11 -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=GzF6ogk5W3DtQwa5yVHSyJZvqA3X4cUIj8ERVNWG6p8=; b=gXjFMNiKXWNtCEpM5rk+gwfYhpp71BfldqWmh0zYjhx00E98H4Ym9o+BCV2TFgxlwQ tqXDjmGL5l6HEG+y8yXSjFMBlUiLcxXcD97xmn/w4a0bXq7y2FYrBjrhyJdpibTaDXVj Vw/U58c4ADlm9VAotg4xAyoYotft2I0rj/lD0= 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=GzF6ogk5W3DtQwa5yVHSyJZvqA3X4cUIj8ERVNWG6p8=; b=A7i6KbCnPuvEdqxzZ4qjWBsnsqQIaFx8ADJk5dcTQiyIr2zRQ5DEr5oPss4Wd3gEG4 t8kbvG+UaNh3GmsmRwLg3WM7JIOPlTELxidquvBGxgwGy7/At11wKHyMZMNi1uck1uFT FwUmEZMtWgWJcx/hWisGRt4/hqe6f8Jl6D6NNOz9PFGrK8fVijZ4BV58Aih7Jhibbd9g M3jINNLLRX96p1xzSNeox02xhVz6CeM/JzeJnDaBWCFFycCbbzVYyP4CNV7O6x6bglcA l95LTFWKmstJ4DlfZGdZyeLmGwHfS164b6TPN+C+mqQS/GB5XmOBeKt2Y+wFqrlef8m+ ik5A== X-Gm-Message-State: AIVw113MjjTkuFviY52oSFwq803pHUljVIVqhq22Qc7vaDmZPREH6GIs Ywq1Eca6Rd25xbEC X-Received: by 10.84.211.151 with SMTP id c23mr24820382pli.372.1501682651513; Wed, 02 Aug 2017 07:04:11 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.63]) by smtp.gmail.com with ESMTPSA id r25sm10554851pgu.7.2017.08.02.07.04.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Aug 2017 07:04:11 -0700 (PDT) From: Jun Nie To: haojian.zhuang@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org, linaro-uefi@lists.linaro.org Date: Wed, 2 Aug 2017 22:03:42 +0800 Message-Id: <1501682622-8223-3-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> References: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> Subject: [edk2] [PATCH v5 3/3] EmbeddedPkg: add Android boot build entry X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jason.liu@linaro.org, shawn.guo@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The device path specifies where to load android boot image. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie --- EmbeddedPkg/EmbeddedPkg.dec | 2 ++ EmbeddedPkg/EmbeddedPkg.dsc | 2 ++ 2 files changed, 4 insertions(+) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index 4cd528a..8ad2a84 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -80,6 +80,7 @@ gAndroidFastbootPlatformProtocolGuid = { 0x524685a0, 0x89a0, 0x11e3, {0x9d, 0x4d, 0xbf, 0xa9, 0xf6, 0xa4, 0x03, 0x08}} gUsbDeviceProtocolGuid = { 0x021bd2ca, 0x51d2, 0x11e3, {0x8e, 0x56, 0xb7, 0x54, 0x17, 0xc7, 0x0b, 0x44 }} gPlatformGpioProtocolGuid = { 0x52ce9845, 0x5af4, 0x43e2, {0xba, 0xfd, 0x23, 0x08, 0x12, 0x54, 0x7a, 0xc2 }} + gAndroidBootImgProtocolGuid = { 0x9859bb19, 0x407c, 0x4f8b, {0xbc, 0xe1, 0xf8, 0xda, 0x65, 0x65, 0xf4, 0xa5 }} [PcdsFeatureFlag.common] gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|FALSE|BOOLEAN|0x00000001 @@ -181,6 +182,7 @@ gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbProductId|0xbeef|UINT32|0x00000023 gEmbeddedTokenSpaceGuid.PcdAndroidFastbootTcpPort|1234|UINT32|0x00000024 + gEmbeddedTokenSpaceGuid.PcdAndroidBootDevicePath|L""|VOID*|0x00000057 [PcdsFixedAtBuild.ARM] gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32|UINT8|0x00000010 diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 16b368e..4a34e34 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -52,6 +52,7 @@ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + AndroidBootImgLib|EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf @@ -272,6 +273,7 @@ TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf } + EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf { # It depends on BdsLib that depends on TimerLib