Rather than assuming that a file can be booted with bootm, check that
the format is correct first. Do the same for booti.

Signed-off-by: Simon Glass <[email protected]>
---

Changes in v3:
- Add new patch to detect booti format properly in pxe_utils

 boot/pxe_utils.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 1468a8e8498..71347b19119 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -591,6 +591,7 @@ static int label_run_boot(struct pxe_context *ctx, struct 
pxe_label *label,
        ulong kernel_addr_r;
        int ret = 0;
        void *buf;
+       enum image_fmt_t  fmt;
 
        bootm_init(&bmi);
 
@@ -608,13 +609,18 @@ static int label_run_boot(struct pxe_context *ctx, struct 
pxe_label *label,
        kernel_addr_r = genimg_get_kernel_addr(kernel_addr);
        buf = map_sysmem(kernel_addr_r, 0);
 
-       /* Try bootm for legacy and FIT format image */
-       if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID &&
-           IS_ENABLED(CONFIG_CMD_BOOTM)) {
+       /*
+        * Try bootm for legacy and FIT format image, assume booti if
+        * compressed
+        */
+       fmt = genimg_get_format_comp(buf);
+
+       if (IS_ENABLED(CONFIG_CMD_BOOTM) && (fmt == IMAGE_FORMAT_FIT ||
+           fmt == IMAGE_FORMAT_LEGACY)) {
                log_debug("using bootm\n");
                ret = bootm_run(&bmi);
        /* Try booting an AArch64 Linux kernel image */
-       } else if (IS_ENABLED(CONFIG_CMD_BOOTI)) {
+       } else if (IS_ENABLED(CONFIG_CMD_BOOTI) && fmt == IMAGE_FORMAT_BOOTI) {
                log_debug("using booti\n");
                ret = booti_run(&bmi);
        /* Try booting a Image */
-- 
2.34.1

Reply via email to