From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x235.google.com (mail-wr0-x235.google.com [IPv6:2a00:1450:400c:c0c::235]) (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 1E162209589FF for ; Mon, 7 Aug 2017 09:25:18 -0700 (PDT) Received: by mail-wr0-x235.google.com with SMTP id k71so3697285wrc.2 for ; Mon, 07 Aug 2017 09:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=WTIDk0sUATv+t09O4WStJ/yFDVKxrQBrxJ+Xj4LSG6A=; b=Keb1wybdjJKgLJT7/joRzOzcJ2mSeXRhvqI38JI++i1NYzKRIHnpTlLiEnsZQiMeRX HBy6Q5PsVoZxWls1ClDsBUEbU8uDn/y4D4ldXEBOs6rd68gabKBJYo07wBX0l6SFdvVC 9/olkRUdgJYwt7FacguGZgwf3w4JeJ4Qyod3c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=WTIDk0sUATv+t09O4WStJ/yFDVKxrQBrxJ+Xj4LSG6A=; b=WiRkmpBm+l/bQEqwWB6KStMKDj5QpBJPJwwa9etlJY1QDlZtS9CMF/LJvKhY9OkSWQ x+5q83JZSrsgjEnO+zPkr1mrsghq22ily5V+/2m6pL4reqn4GIDc6cYJkDvOuFOb9YrQ lHHaN6Cwc0k9sxL8s092PJW7tKfx7TqklZ3VYYy7bDr1K1vlWQ4ylzJb9YSEsQQCegT9 zitCmiB1yfho6Anuq991bjHC58UJtlnIKRm0zWaF/owniopY/eXl2Oku6C0C+pnvLJdx vABh94k6WGnk8yvCMSy/7roRAnzTDzew28xj77VSQ12hV62KPqdWnZJdgRCzzkmnrTTK uHUw== X-Gm-Message-State: AHYfb5hs2M26T9q5XqLOfY3/FMVIFgmnO8i+KQFV9oGcutz6nlp4wGgu ahNldXS75ex++isk X-Received: by 10.223.138.182 with SMTP id y51mr796708wry.83.1502123252566; Mon, 07 Aug 2017 09:27:32 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id m72sm9812860wmg.16.2017.08.07.09.27.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Aug 2017 09:27:32 -0700 (PDT) Date: Mon, 7 Aug 2017 17:27:30 +0100 From: Leif Lindholm To: Jun Nie Cc: haojian.zhuang@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org, linaro-uefi@lists.linaro.org, shawn.guo@linaro.org, jason.liu@linaro.org Message-ID: <20170807162730.6w2bmw53x6mcegj6@bivouac.eciton.net> References: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> MIME-Version: 1.0 In-Reply-To: <1501682622-8223-1-git-send-email-jun.nie@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [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: , X-List-Received-Date: Mon, 07 Aug 2017 16:25:18 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Aug 02, 2017 at 10:03:40PM +0800, Jun Nie wrote: > 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 Reviewed-by: Leif Lindholm Pushed as 6e414300b5. > --- > .../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 > > 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__ */ > -- > 1.9.1 >