Re: [PATCH v2 15/17] android: boot: support boot image header version 3 and 4

2023-02-02 Thread Safae Ouajih



On 01/02/2023 09:44, Mattijs Korpershoek wrote:

On Thu, Jan 26, 2023 at 17:55, Simon Glass  wrote:


Hi Safae,

On Thu, 26 Jan 2023 at 09:05, Safae Ouajih  wrote:

This enables the support for boot image header version 3 and 4
using abootimg command.

In order to use version 3 or 4:

1- Vendor boot image address should be given to abootimg cmd.

 abootimg addr $1 $vendor_boot_load_addr

2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host
the ramdisk : generic ramdisk + vendor ramdisk

"struct andr_boot_img_hdr_v0*" is replaced by "void *" in
some functions since v3 and v4 are now supported as well.

Signed-off-by: Safae Ouajih 
---
  boot/bootm.c | 29 -
  boot/image-android.c | 16 ++--
  boot/image-board.c   | 14 +++---
  boot/image-fdt.c |  2 +-
  cmd/abootimg.c   | 24 ++--
  include/image.h  | 14 --
  6 files changed, 76 insertions(+), 23 deletions(-)

Since this introduces the new formats (v3 and v4), can we also update
the doc/android/boot-image.rst files which lists all the boot formats
for android?



Hi Mattijs,

Thank you for the review,

I will update the documentation in a v3.

Best Regards,

Safae


diff --git a/boot/bootm.c b/boot/bootm.c
index a58e6f391e..3e130c175c 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, 
int argc,
  char *const argv[])
  {
 const void *os_hdr;
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+   const void *vendor_boot_img;
+   const void *boot_img;
+#endif
 bool ep_found = false;
 int ret;

@@ -181,12 +185,17 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, 
int argc,
  #endif
  #ifdef CONFIG_ANDROID_BOOT_IMAGE
 case IMAGE_FORMAT_ANDROID:
+   boot_img = os_hdr;
+   vendor_boot_img = NULL;
+   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+   boot_img = (void *)get_abootimg_addr();
+   vendor_boot_img = (void *)get_avendor_bootimg_addr();

map_sysmem() so it owrks on sandbox


+   }
 images.os.type = IH_TYPE_KERNEL;
-   images.os.comp = android_image_get_kcomp(os_hdr, NULL);
+   images.os.comp = android_image_get_kcomp(boot_img, 
vendor_boot_img);
 images.os.os = IH_OS_LINUX;
-
-   images.os.end = android_image_get_end(os_hdr, NULL);
-   images.os.load = android_image_get_kload(os_hdr, NULL);
+   images.os.end = android_image_get_end(boot_img, 
vendor_boot_img);
+   images.os.load = android_image_get_kload(boot_img, 
vendor_boot_img);
 images.ep = images.os.load;
 ep_found = true;
 break;
@@ -889,6 +898,10 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, 
int flag, int argc,
 int os_noffset;
  #endif

+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+   const void *boot_img;
+   const void *vendor_boot_img;
+#endif
 img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0],
   _uname_config,
   _uname_kernel);
@@ -964,8 +977,14 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, 
int flag, int argc,
  #endif
  #ifdef CONFIG_ANDROID_BOOT_IMAGE
 case IMAGE_FORMAT_ANDROID:
+   boot_img = buf;
+   vendor_boot_img = NULL;
+   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+   boot_img = (void *)get_abootimg_addr();
+   vendor_boot_img = (void *)get_avendor_bootimg_addr();

and here


+   }
 printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
-   if (android_image_get_kernel(buf, NULL, images->verify,
+   if (android_image_get_kernel(boot_img, vendor_boot_img, 
images->verify,
  os_data, os_len))
 return NULL;
 break;
diff --git a/boot/image-android.c b/boot/image-android.c
index edeeaaaee0..dd06c09279 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct 
andr_image_data *img_data)
   * Return: Zero, os start address and length on success,
   * otherwise on failure.
   */
-int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr,
+int android_image_get_kernel(const void *hdr,
  const void *vendor_boot_img, int verify,
  ulong *os_data, ulong *os_len)
  {
@@ -286,7 +286,7 @@ bool is_android_vendor_boot_image_header(const void 
*vendor_boot_img)
 return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, 
ANDR_VENDOR_BOOT_MAGIC_SIZE);
  }

-bool 

Re: [PATCH v2 15/17] android: boot: support boot image header version 3 and 4

2023-02-01 Thread Mattijs Korpershoek
On Thu, Jan 26, 2023 at 17:55, Simon Glass  wrote:

> Hi Safae,
>
> On Thu, 26 Jan 2023 at 09:05, Safae Ouajih  wrote:
>>
>> This enables the support for boot image header version 3 and 4
>> using abootimg command.
>>
>> In order to use version 3 or 4:
>>
>> 1- Vendor boot image address should be given to abootimg cmd.
>>
>> abootimg addr $1 $vendor_boot_load_addr
>>
>> 2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host
>> the ramdisk : generic ramdisk + vendor ramdisk
>>
>> "struct andr_boot_img_hdr_v0*" is replaced by "void *" in
>> some functions since v3 and v4 are now supported as well.
>>
>> Signed-off-by: Safae Ouajih 
>> ---
>>  boot/bootm.c | 29 -
>>  boot/image-android.c | 16 ++--
>>  boot/image-board.c   | 14 +++---
>>  boot/image-fdt.c |  2 +-
>>  cmd/abootimg.c   | 24 ++--
>>  include/image.h  | 14 --
>>  6 files changed, 76 insertions(+), 23 deletions(-)

Since this introduces the new formats (v3 and v4), can we also update
the doc/android/boot-image.rst files which lists all the boot formats
for android?

>>
>> diff --git a/boot/bootm.c b/boot/bootm.c
>> index a58e6f391e..3e130c175c 100644
>> --- a/boot/bootm.c
>> +++ b/boot/bootm.c
>> @@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int 
>> flag, int argc,
>>  char *const argv[])
>>  {
>> const void *os_hdr;
>> +#ifdef CONFIG_ANDROID_BOOT_IMAGE
>> +   const void *vendor_boot_img;
>> +   const void *boot_img;
>> +#endif
>> bool ep_found = false;
>> int ret;
>>
>> @@ -181,12 +185,17 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int 
>> flag, int argc,
>>  #endif
>>  #ifdef CONFIG_ANDROID_BOOT_IMAGE
>> case IMAGE_FORMAT_ANDROID:
>> +   boot_img = os_hdr;
>> +   vendor_boot_img = NULL;
>> +   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
>> +   boot_img = (void *)get_abootimg_addr();
>> +   vendor_boot_img = (void *)get_avendor_bootimg_addr();
>
> map_sysmem() so it owrks on sandbox
>
>> +   }
>> images.os.type = IH_TYPE_KERNEL;
>> -   images.os.comp = android_image_get_kcomp(os_hdr, NULL);
>> +   images.os.comp = android_image_get_kcomp(boot_img, 
>> vendor_boot_img);
>> images.os.os = IH_OS_LINUX;
>> -
>> -   images.os.end = android_image_get_end(os_hdr, NULL);
>> -   images.os.load = android_image_get_kload(os_hdr, NULL);
>> +   images.os.end = android_image_get_end(boot_img, 
>> vendor_boot_img);
>> +   images.os.load = android_image_get_kload(boot_img, 
>> vendor_boot_img);
>> images.ep = images.os.load;
>> ep_found = true;
>> break;
>> @@ -889,6 +898,10 @@ static const void *boot_get_kernel(struct cmd_tbl 
>> *cmdtp, int flag, int argc,
>> int os_noffset;
>>  #endif
>>
>> +#ifdef CONFIG_ANDROID_BOOT_IMAGE
>> +   const void *boot_img;
>> +   const void *vendor_boot_img;
>> +#endif
>> img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0],
>>   _uname_config,
>>   _uname_kernel);
>> @@ -964,8 +977,14 @@ static const void *boot_get_kernel(struct cmd_tbl 
>> *cmdtp, int flag, int argc,
>>  #endif
>>  #ifdef CONFIG_ANDROID_BOOT_IMAGE
>> case IMAGE_FORMAT_ANDROID:
>> +   boot_img = buf;
>> +   vendor_boot_img = NULL;
>> +   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
>> +   boot_img = (void *)get_abootimg_addr();
>> +   vendor_boot_img = (void *)get_avendor_bootimg_addr();
>
> and here
>
>> +   }
>> printf("## Booting Android Image at 0x%08lx ...\n", 
>> img_addr);
>> -   if (android_image_get_kernel(buf, NULL, images->verify,
>> +   if (android_image_get_kernel(boot_img, vendor_boot_img, 
>> images->verify,
>>  os_data, os_len))
>> return NULL;
>> break;
>> diff --git a/boot/image-android.c b/boot/image-android.c
>> index edeeaaaee0..dd06c09279 100644
>> --- a/boot/image-android.c
>> +++ b/boot/image-android.c
>> @@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct 
>> andr_image_data *img_data)
>>   * Return: Zero, os start address and length on success,
>>   * otherwise on failure.
>>   */
>> -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr,
>> +int android_image_get_kernel(const void *hdr,
>>  const void *vendor_boot_img, int verify,
>>  ulong *os_data, ulong *os_len)
>>  {
>> @@ -286,7 +286,7 @@ bool is_android_vendor_boot_image_header(const void 
>> 

Re: [PATCH v2 15/17] android: boot: support boot image header version 3 and 4

2023-01-26 Thread Simon Glass
Hi Safae,

On Thu, 26 Jan 2023 at 09:05, Safae Ouajih  wrote:
>
> This enables the support for boot image header version 3 and 4
> using abootimg command.
>
> In order to use version 3 or 4:
>
> 1- Vendor boot image address should be given to abootimg cmd.
>
> abootimg addr $1 $vendor_boot_load_addr
>
> 2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host
> the ramdisk : generic ramdisk + vendor ramdisk
>
> "struct andr_boot_img_hdr_v0*" is replaced by "void *" in
> some functions since v3 and v4 are now supported as well.
>
> Signed-off-by: Safae Ouajih 
> ---
>  boot/bootm.c | 29 -
>  boot/image-android.c | 16 ++--
>  boot/image-board.c   | 14 +++---
>  boot/image-fdt.c |  2 +-
>  cmd/abootimg.c   | 24 ++--
>  include/image.h  | 14 --
>  6 files changed, 76 insertions(+), 23 deletions(-)
>
> diff --git a/boot/bootm.c b/boot/bootm.c
> index a58e6f391e..3e130c175c 100644
> --- a/boot/bootm.c
> +++ b/boot/bootm.c
> @@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int 
> flag, int argc,
>  char *const argv[])
>  {
> const void *os_hdr;
> +#ifdef CONFIG_ANDROID_BOOT_IMAGE
> +   const void *vendor_boot_img;
> +   const void *boot_img;
> +#endif
> bool ep_found = false;
> int ret;
>
> @@ -181,12 +185,17 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int 
> flag, int argc,
>  #endif
>  #ifdef CONFIG_ANDROID_BOOT_IMAGE
> case IMAGE_FORMAT_ANDROID:
> +   boot_img = os_hdr;
> +   vendor_boot_img = NULL;
> +   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
> +   boot_img = (void *)get_abootimg_addr();
> +   vendor_boot_img = (void *)get_avendor_bootimg_addr();

map_sysmem() so it owrks on sandbox

> +   }
> images.os.type = IH_TYPE_KERNEL;
> -   images.os.comp = android_image_get_kcomp(os_hdr, NULL);
> +   images.os.comp = android_image_get_kcomp(boot_img, 
> vendor_boot_img);
> images.os.os = IH_OS_LINUX;
> -
> -   images.os.end = android_image_get_end(os_hdr, NULL);
> -   images.os.load = android_image_get_kload(os_hdr, NULL);
> +   images.os.end = android_image_get_end(boot_img, 
> vendor_boot_img);
> +   images.os.load = android_image_get_kload(boot_img, 
> vendor_boot_img);
> images.ep = images.os.load;
> ep_found = true;
> break;
> @@ -889,6 +898,10 @@ static const void *boot_get_kernel(struct cmd_tbl 
> *cmdtp, int flag, int argc,
> int os_noffset;
>  #endif
>
> +#ifdef CONFIG_ANDROID_BOOT_IMAGE
> +   const void *boot_img;
> +   const void *vendor_boot_img;
> +#endif
> img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0],
>   _uname_config,
>   _uname_kernel);
> @@ -964,8 +977,14 @@ static const void *boot_get_kernel(struct cmd_tbl 
> *cmdtp, int flag, int argc,
>  #endif
>  #ifdef CONFIG_ANDROID_BOOT_IMAGE
> case IMAGE_FORMAT_ANDROID:
> +   boot_img = buf;
> +   vendor_boot_img = NULL;
> +   if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
> +   boot_img = (void *)get_abootimg_addr();
> +   vendor_boot_img = (void *)get_avendor_bootimg_addr();

and here

> +   }
> printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
> -   if (android_image_get_kernel(buf, NULL, images->verify,
> +   if (android_image_get_kernel(boot_img, vendor_boot_img, 
> images->verify,
>  os_data, os_len))
> return NULL;
> break;
> diff --git a/boot/image-android.c b/boot/image-android.c
> index edeeaaaee0..dd06c09279 100644
> --- a/boot/image-android.c
> +++ b/boot/image-android.c
> @@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct 
> andr_image_data *img_data)
>   * Return: Zero, os start address and length on success,
>   * otherwise on failure.
>   */
> -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr,
> +int android_image_get_kernel(const void *hdr,
>  const void *vendor_boot_img, int verify,
>  ulong *os_data, ulong *os_len)
>  {
> @@ -286,7 +286,7 @@ bool is_android_vendor_boot_image_header(const void 
> *vendor_boot_img)
> return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, 
> ANDR_VENDOR_BOOT_MAGIC_SIZE);
>  }
>
> -bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr)
> +bool is_android_boot_image_header(const void *hdr)
>  {
> return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
>  }
> @@