[PATCH v3 14/46] boot: Convert IMAGE_FORMAT into an enum

Simon Glass sjg at chromium.org
Fri Dec 6 03:35:53 CET 2024


Use an enum so it is clearer that these options are related. Update
genimg_get_format(), tidy up the function comment and move it to the
header file, since it is exported.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v3:
- Add new patch to convert IMAGE_FORMAT into an enum

 boot/image-board.c | 18 +++---------------
 include/image.h    | 26 +++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index b726bd6b303..c681972109e 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -234,21 +234,7 @@ ulong genimg_get_kernel_addr(char * const img_addr)
 					  &fit_uname_kernel);
 }
 
-/**
- * genimg_get_format - get image format type
- * @img_addr: image start address
- *
- * genimg_get_format() checks whether provided address points to a valid
- * legacy or FIT image.
- *
- * New uImage format and FDT blob are based on a libfdt. FDT blob
- * may be passed directly or embedded in a FIT image. In both situations
- * genimg_get_format() must be able to dectect libfdt header.
- *
- * returns:
- *     image format type or IMAGE_FORMAT_INVALID if no image is present
- */
-int genimg_get_format(const void *img_addr)
+enum image_fmt_t genimg_get_format(const void *img_addr)
 {
 	if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
 		const struct legacy_img_hdr *hdr;
@@ -434,6 +420,8 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
 			done = true;
 		}
 		break;
+	case IMAGE_FORMAT_INVALID:
+		break;
 	}
 
 	if (!done) {
diff --git a/include/image.h b/include/image.h
index 9be5acd8158..e3fc4b83b1d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -597,10 +597,12 @@ int boot_get_setup(struct bootm_headers *images, uint8_t arch, ulong *setup_star
 		   ulong *setup_len);
 
 /* Image format types, returned by _get_format() routine */
-#define IMAGE_FORMAT_INVALID	0x00
-#define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
-#define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
-#define IMAGE_FORMAT_ANDROID	0x03	/* Android boot image */
+enum image_fmt_t {
+	IMAGE_FORMAT_INVALID,
+	IMAGE_FORMAT_LEGACY,		/* legacy image_header based format */
+	IMAGE_FORMAT_FIT,		/* new, libfdt based format */
+	IMAGE_FORMAT_ANDROID,		/* Android boot image */
+};
 
 /**
  * genimg_get_kernel_addr_fit() - Parse FIT specifier
@@ -629,7 +631,21 @@ ulong genimg_get_kernel_addr_fit(const char *const img_addr,
 				 const char **fit_uname_kernel);
 
 ulong genimg_get_kernel_addr(char * const img_addr);
-int genimg_get_format(const void *img_addr);
+
+/**
+ * genimg_get_format - get image format type
+ * @img_addr: image start address
+ * Return: image format type or IMAGE_FORMAT_INVALID if no image is present
+ *
+ * genimg_get_format() checks whether provided address points to a valid
+ * legacy or FIT image.
+ *
+ * New uImage format and FDT blob are based on a libfdt. FDT blob
+ * may be passed directly or embedded in a FIT image. In both situations
+ * genimg_get_format() must be able to dectect libfdt header.
+ */
+enum image_fmt_t genimg_get_format(const void *img_addr);
+
 int genimg_has_config(struct bootm_headers *images);
 
 /**
-- 
2.34.1



More information about the U-Boot mailing list