Re: [PATCH 01/13] bootm: move open to image_handler

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:44:52AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  arch/arm/lib/bootm.c   |  2 +
>  arch/blackfin/lib/blackfin_linux.c |  1 +
>  arch/nios2/lib/bootm.c |  1 +
>  arch/ppc/lib/ppclinux.c|  1 +
>  common/bootm.c | 79 
> --
>  common/image-fit.c | 14 +++
>  common/misc.c  |  1 +
>  common/uimage.c| 32 +++
>  include/bootm.h|  1 +
>  include/image-fit.h|  1 +
>  include/image.h|  2 +
>  11 files changed, 80 insertions(+), 55 deletions(-)
> 
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index 8068a53be..204344f87 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -217,6 +217,7 @@ static int do_bootm_linux(struct image_data *data)
>  
>  static struct image_handler uimage_handler = {
>   .name = "ARM Linux uImage",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> @@ -579,6 +580,7 @@ BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable 
> overwrite of the tags addr wit
>  
>  static struct image_handler arm_fit_handler = {
>  .name = "FIT image",
> + .open = fit_bootm_open,
>  .bootm = do_bootm_linux,
>  .filetype = filetype_oftree,
>  };
> diff --git a/arch/blackfin/lib/blackfin_linux.c 
> b/arch/blackfin/lib/blackfin_linux.c
> index 5ebd284d1..27002eadb 100644
> --- a/arch/blackfin/lib/blackfin_linux.c
> +++ b/arch/blackfin/lib/blackfin_linux.c
> @@ -68,6 +68,7 @@ static int do_bootm_linux(struct image_data *idata)
>  
>  static struct image_handler handler = {
>   .name = "Blackfin Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
> index 34908bde3..f1b3c2624 100644
> --- a/arch/nios2/lib/bootm.c
> +++ b/arch/nios2/lib/bootm.c
> @@ -69,6 +69,7 @@ static int do_bootm_linux(struct image_data *idata)
>  
>  static struct image_handler handler = {
>   .name = "NIOS2 Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
> index 3fca6b272..c882938fa 100644
> --- a/arch/ppc/lib/ppclinux.c
> +++ b/arch/ppc/lib/ppclinux.c
> @@ -100,6 +100,7 @@ error:
>  
>  static struct image_handler handler = {
>   .name = "PowerPC Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/common/bootm.c b/common/bootm.c
> index 81625d915..64c933b3c 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -34,7 +34,7 @@ int register_image_handler(struct image_handler *handler)
>  }
>  
>  static struct image_handler *bootm_find_handler(enum filetype filetype,
> - struct image_data *data)
> + struct image_data *data, int enforce_os)
>  {
>   struct image_handler *handler;
>  
> @@ -42,9 +42,16 @@ static struct image_handler *bootm_find_handler(enum 
> filetype filetype,
>   if (filetype != filetype_uimage &&
>   handler->filetype == filetype)
>   return handler;
> - if  (filetype == filetype_uimage &&
> - handler->ih_os == data->os->header.ih_os)
> - return handler;
> + if (filetype == filetype_uimage) {
> + /*
> +  * we can take the first one as open is the same
> +  * not matter the OS
> +  */
> + if (enforce_os && handler->ih_os == 
> data->os->header.ih_os)
> + return handler;
> + else
> + return handler;
> + }
>   }
>  
>   return NULL;
> @@ -441,38 +448,6 @@ int bootm_get_os_size(struct image_data *data)
>   return -EINVAL;
>  }
>  
> -static int bootm_open_os_uimage(struct image_data *data)
> -{
> - int ret;
> -
> - data->os = uimage_open(data->os_file);
> - if (!data->os)
> - return -EINVAL;
> -
> - if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
> - ret = uimage_verify(data->os);
> - if (ret) {
> - printf("Checking data crc failed with %s\n",
> - strerror(-ret));
> - uimage_close(data->os);
> - return ret;
> - }
> - }
> -
> - uimage_print_contents(data->os);
> -
> - if (data->os->header.ih_arch != IH_ARCH) {
> - printf("U

[PATCH 01/13] bootm: move open to image_handler

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 arch/arm/lib/bootm.c   |  2 +
 arch/blackfin/lib/blackfin_linux.c |  1 +
 arch/nios2/lib/bootm.c |  1 +
 arch/ppc/lib/ppclinux.c|  1 +
 common/bootm.c | 79 --
 common/image-fit.c | 14 +++
 common/misc.c  |  1 +
 common/uimage.c| 32 +++
 include/bootm.h|  1 +
 include/image-fit.h|  1 +
 include/image.h|  2 +
 11 files changed, 80 insertions(+), 55 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 8068a53be..204344f87 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -217,6 +217,7 @@ static int do_bootm_linux(struct image_data *data)
 
 static struct image_handler uimage_handler = {
.name = "ARM Linux uImage",
+   .open = uimage_bootm_open,
.bootm = do_bootm_linux,
.filetype = filetype_uimage,
.ih_os = IH_OS_LINUX,
@@ -579,6 +580,7 @@ BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable overwrite 
of the tags addr wit
 
 static struct image_handler arm_fit_handler = {
 .name = "FIT image",
+   .open = fit_bootm_open,
 .bootm = do_bootm_linux,
 .filetype = filetype_oftree,
 };
diff --git a/arch/blackfin/lib/blackfin_linux.c 
b/arch/blackfin/lib/blackfin_linux.c
index 5ebd284d1..27002eadb 100644
--- a/arch/blackfin/lib/blackfin_linux.c
+++ b/arch/blackfin/lib/blackfin_linux.c
@@ -68,6 +68,7 @@ static int do_bootm_linux(struct image_data *idata)
 
 static struct image_handler handler = {
.name = "Blackfin Linux",
+   .open = uimage_bootm_open,
.bootm = do_bootm_linux,
.filetype = filetype_uimage,
.ih_os = IH_OS_LINUX,
diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
index 34908bde3..f1b3c2624 100644
--- a/arch/nios2/lib/bootm.c
+++ b/arch/nios2/lib/bootm.c
@@ -69,6 +69,7 @@ static int do_bootm_linux(struct image_data *idata)
 
 static struct image_handler handler = {
.name = "NIOS2 Linux",
+   .open = uimage_bootm_open,
.bootm = do_bootm_linux,
.filetype = filetype_uimage,
.ih_os = IH_OS_LINUX,
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 3fca6b272..c882938fa 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -100,6 +100,7 @@ error:
 
 static struct image_handler handler = {
.name = "PowerPC Linux",
+   .open = uimage_bootm_open,
.bootm = do_bootm_linux,
.filetype = filetype_uimage,
.ih_os = IH_OS_LINUX,
diff --git a/common/bootm.c b/common/bootm.c
index 81625d915..64c933b3c 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -34,7 +34,7 @@ int register_image_handler(struct image_handler *handler)
 }
 
 static struct image_handler *bootm_find_handler(enum filetype filetype,
-   struct image_data *data)
+   struct image_data *data, int enforce_os)
 {
struct image_handler *handler;
 
@@ -42,9 +42,16 @@ static struct image_handler *bootm_find_handler(enum 
filetype filetype,
if (filetype != filetype_uimage &&
handler->filetype == filetype)
return handler;
-   if  (filetype == filetype_uimage &&
-   handler->ih_os == data->os->header.ih_os)
-   return handler;
+   if (filetype == filetype_uimage) {
+   /*
+* we can take the first one as open is the same
+* not matter the OS
+*/
+   if (enforce_os && handler->ih_os == 
data->os->header.ih_os)
+   return handler;
+   else
+   return handler;
+   }
}
 
return NULL;
@@ -441,38 +448,6 @@ int bootm_get_os_size(struct image_data *data)
return -EINVAL;
 }
 
-static int bootm_open_os_uimage(struct image_data *data)
-{
-   int ret;
-
-   data->os = uimage_open(data->os_file);
-   if (!data->os)
-   return -EINVAL;
-
-   if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
-   ret = uimage_verify(data->os);
-   if (ret) {
-   printf("Checking data crc failed with %s\n",
-   strerror(-ret));
-   uimage_close(data->os);
-   return ret;
-   }
-   }
-
-   uimage_print_contents(data->os);
-
-   if (data->os->header.ih_arch != IH_ARCH) {
-   printf("Unsupported Architecture 0x%x\n",
-  data->os->header.ih_arch);
-   return -EINVAL;
-   }
-
-   if (data->os_address == UIMAGE_SOME_ADDRESS)
-   data->os_address = data->os->header.ih_l