public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Jun Nie <jun.nie@linaro.org>
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
Subject: Re: [PATCH v4 2/4] EmbeddedPkg/AndroidFastboot: split android boot header
Date: Tue, 1 Aug 2017 16:18:31 +0100	[thread overview]
Message-ID: <20170801151831.GC26462@bivouac.eciton.net> (raw)
In-Reply-To: <1501579741-28866-2-git-send-email-jun.nie@linaro.org>

On Tue, Aug 01, 2017 at 05:28:59PM +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 <jun.nie@linaro.org>
> ---
>  .../Application/AndroidFastboot/AndroidBootImg.c   | 35 +++------------
>  .../AndroidFastboot/AndroidFastbootApp.h           |  1 +
>  .../AndroidFastboot/Arm/BootAndroidBootImg.c       |  2 +-
>  EmbeddedPkg/Include/Library/AndroidBootImgLib.h    | 50 ++++++++++++++++++++++
>  4 files changed, 57 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));

So, this change uses the macro that is now only introduced in patch
2/4, and hence this patch breaks bisect.

Could you move this change to 3/4 instead?

>  
>    *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 <Library/AndroidBootImgLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/MemoryAllocationLib.h>
> 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..8116c7c
> --- /dev/null
> +++ b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
> @@ -0,0 +1,50 @@
> +/** @file
> +
> +  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
> +  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 <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +
> +#include <Uefi/UefiBaseType.h>
> +#include <Uefi/UefiSpec.h>
> +
> +#define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE  512
> +
> +#define ANDROID_BOOT_MAGIC                "ANDROID!"
> +#define ANDROID_BOOT_MAGIC_LENGTH         (sizeof (ANDROID_BOOT_MAGIC) - 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;

The original definition used
#pragma pack (1)
#pragma pack ()
around this struct definition.
I believe we should maintain that.

/
    Leif

> +
> +/* 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))
> +#endif /* __ABOOTIMG_H__ */
> -- 
> 1.9.1
> 


  reply	other threads:[~2017-08-01 15:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01  9:28 [PATCH v4 1/4] ArmPkg: Move IS_DEVICE_PATH_NODE for sharing Jun Nie
2017-08-01  9:28 ` [PATCH v4 2/4] EmbeddedPkg/AndroidFastboot: split android boot header Jun Nie
2017-08-01 15:18   ` Leif Lindholm [this message]
2017-08-01  9:29 ` [PATCH v4 3/4] EmbeddedPkg/AndroidBoot: boot android kernel from storage Jun Nie
2017-08-01 15:50   ` Leif Lindholm
2017-08-02 14:03     ` Jun Nie
2017-08-01  9:29 ` [PATCH v4 4/4] EmbeddedPkg: add Android boot device path and guid Jun Nie
2017-08-01 16:19   ` Leif Lindholm
2017-08-02 14:02     ` Jun Nie
2017-08-01 14:59 ` [PATCH v4 1/4] ArmPkg: Move IS_DEVICE_PATH_NODE for sharing Leif Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170801151831.GC26462@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox