From patchwork Wed Aug 9 10:39:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 109708 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp680351qge; Wed, 9 Aug 2017 03:39:42 -0700 (PDT) X-Received: by 10.98.9.19 with SMTP id e19mr7770936pfd.251.1502275182052; Wed, 09 Aug 2017 03:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502275182; cv=none; d=google.com; s=arc-20160816; b=qJmm2TkrLdTF3GFy6MSZw+2QLXMucKQ2nxpJuOCZtK+4wKw3V1847kWmgGuzL9a7N1 pe3guM/GbYdN0EdOJAu6UMfkRxhpV2+lsBLkMgqgcpSwy3ClnAi8lb3yIlUnx1GxI6ph Gm+TjWcezcSrZnf1Xzk79zgA8NGMLx5viYumCg3RnJd/+8Wyyad4LS7xBTnikyS1ntvR MESvclzDuV/M3vTjykuxK75GBiuyx4hf8HFqTi2yQbuK3qwlIFAzGx/h2QSwq8/CcAlY p4QfZP7Knvx8J8ZYxDbt8P7HVvAmDZ8yS4vpuM/egMrRIJatcKjc93CB/PyWUmwLnjsF qaQA== 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=jip+pn5N7MaaFUTfRlrcD28EhV/alWbyg1Fq7WlkzUoZYpAbqghKyMjtSDcNw6YJ6k boYe2/ZaW0pf8rPkDP1s9z+s/kNk3IMVcw3pEedX90tyeQ2u2bt4qP3DIY2VdK1T0BOZ ksRM/tw0Dvd043xfFLZYWKivm/WdmaV9PI2+OJnXrWkJtBxEMwDa4ZRykTKJQGR/lrrY +1O32qCvrl540NrZ2+iXq1B1gcd2DFzoqJcKlUO4v+yauKDK9jtWgJjWKBS/CO/BGKbI EPM4fwy1ghuJG5aZyqc/6G9OUL5fZ8/RN5/MGka3OO0p5h35soBu2Wx4CL/GMA5/voLz tqvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=H+wtuprc; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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. [198.145.21.10]) by mx.google.com with ESMTPS id n2si2694749pll.192.2017.08.09.03.39.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Aug 2017 03:39:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=H+wtuprc; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 D082621E1DB44; Wed, 9 Aug 2017 03:37:22 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x231.google.com (mail-pg0-x231.google.com [IPv6:2607:f8b0:400e:c05::231]) (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 CD78D21E11D94 for ; Wed, 9 Aug 2017 03:37:20 -0700 (PDT) Received: by mail-pg0-x231.google.com with SMTP id l64so26377034pge.5 for ; Wed, 09 Aug 2017 03:39:39 -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=H+wtuprcRckYt4m3gd1YCHEjc3O4D6WjXNsyw2PixeO0DlmrUuI+zuim20pNriBpEO 4REAVLVab8ggf5vq/aUoCxQm5w4mNx6/LZcNeGwI5E5+pxEvFVpQd6ftknVu+QT0bS3s lW+elOCixfQ6KzFpKiUOLheJKp3bjXHcSc6Fg= 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=YBtQOd/2YJ9XSQbOuSs2SpAeaGoll6O5UxV429+MxsOpj1eWs6x7Hu6/M3oeknBK4y CBtZx38o2/nPvefkPPXz5E9lAQUcZmSvkltOsl/sa2lLX4mWoIPTurzmBScSU+iH95Lo WR3OITcTYn7G41m57+f2A6GHIZfAml4R2CE44Z/GW087s9OKItBQsq8cw76/ZRFdNzKq zmt58uQ4bTzRzwZMBw28tvHN5bu4vCJB1yeybLFyYy0CNYuXKnj7nCmsPFwiO2uwuDp5 D2l6lBIK5IdCsGtEzeWEBtYXyzwJX05BEyJtIOwVqsSQVq+zrsPCeDFfKESgOU1G/vdz aHzA== X-Gm-Message-State: AHYfb5gfOdkkk0J8JJsAfTePi4PR0VNuGHvap3pGmC2y9eUOBKQ/L5Kx 9I8QRsPSnp43LaMD X-Received: by 10.98.67.68 with SMTP id q65mr2321057pfa.175.1502275178659; Wed, 09 Aug 2017 03:39:38 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.63]) by smtp.gmail.com with ESMTPSA id g2sm5511578pgu.86.2017.08.09.03.39.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Aug 2017 03:39:37 -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, 9 Aug 2017 18:39:22 +0800 Message-Id: <1502275163-3690-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v6 1/2] 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 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__ */