[PATCH v5 00/29] image: Reduce #ifdefs and ad-hoc defines in image code (Part B)

Simon Glass
2021-09-26T01:44:03Z

Much of the image-handling code predates the introduction of Kconfig and
has quite a few #ifdefs in it. It also uses its own IMAGE_... defines to
help reduce the #ifdefs, which is unnecessary now that we can use
IS_ENABLED() et al.

The image code is also where quite a bit of code is shared with the host
tools. At present this uses a lot of checks of USE_HOSTCC.

This series introduces more 'tools' Kconfig options and a way to use
CONFIG_IS_ENABLED() to check them. This works in a similar way to SPL, so

CONFIG_IS_ENABLED(FIT)

will evaluate to true on the host build (USE_HOSTCC) if CONFIG_TOOLS_FIT
is enabled. This allows quite a bit of clean-up of the image.h header file
and many of the image C files.

The 'tools' Kconfig options should help to solve a more general problem in
that we mostly want the host tools to build with all features enabled, no
matter which features the 'target' build actually uses. This is a pain to
arrange at present, but with 'host' Kconfigs, we can just define them all
to y.

There are cases where the host tools do not have features which are
present on the target, for example environment and physical addressing.
To help with this, some of the core image code is split out into
image-board.c and image-host.c files.

Even with these changes, some #ifdefs remain (down from about 100 to
about 40 in common/image*). But the code is somewhat easier to follow and
there are fewer build paths.

Note: The original version of this series met with resistance and resulted
in another series that went in first. That did make some improvements
but the fundamental problem of sharing code with tools remains. It seems
like a good time to get this one in, before further refactoring happens.
It was a significant effort to rebase this series on -next and I hope not
to do it again.

This series is available at u-boot-dm/host-working

Changes in v5:
- Add a new patch to rename host_build() to tools_build()
- Add new patch to bring back SPL_ versions of SHA
- Avoid preprocessor in a few more places
- Drop I_WANT_MD5
- Drop changes to tools/Makefile since they already use TOOLS_ Kconfigs
- Drop rd_load since it is not used
- Fix up tools/Makefile to have the correct condition
- Rebase to next
- Update commit message
- Update commit message to indicate that the code is in a separate file
- Use TOOLS_ instead of HOST_

Changes in v2:
- Add SPL_ Kconfigs also, since otherwise hashing algorithms drop from SPL
- All patches rebased to -next
- Consider selecting a raw FDT to be success
- Correct comment about USE_HOSTCC being undefined in CONFIG_VAL()
- Correct logic for the non-FIT case
- Drop unnecessary setting of rd_len, etc.
- Fix up comment to put an underscore after every CONFIG

Simon Glass (29):
compiler: Rename host_build() to tools_build()
kconfig: Add tools support to CONFIG_IS_ENABLED()
image: Add Kconfig options for FIT in the tools build
spl: cypto: Bring back SPL_ versions of SHA
hash: Use Kconfig to enable hashing in host tools and SPL
hash: Drop some #ifdefs in hash.c
image: Drop IMAGE_ENABLE_FIT
image: Drop IMAGE_ENABLE_OF_LIBFDT
image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host
image: Use Kconfig to enable FIT_RSASSA_PSS on host
image: Use the correct checks for CRC32
image: Drop IMAGE_BOOT_GET_CMDLINE
image: Drop IMAGE_OF_BOARD_SETUP
image: Drop IMAGE_OF_SYSTEM_SETUP
image: Drop IMAGE_ENABLE_IGNORE
efi: Correct dependency on FIT_SIGNATURE
image: Drop IMAGE_ENABLE_SIGN/VERIFY defines
image: Drop IMAGE_ENABLE_EN/DECRYPT defines
image: Tidy up fit_unsupported_reset()
image: Drop unnecessary #ifdefs from image.h
image: Drop #ifdefs for fit_print_contents()
image: Drop most #ifdefs in image-board.c
image: Reduce variable scope in boot_get_ramdisk()
image: Split up boot_get_ramdisk()
image: Remove #ifdefs from select_ramdisk()
image: Remove some #ifdefs from image-fit and image-fit-sig
image: Reduce variable scope in boot_get_fdt()
image: Split up boot_get_fdt()
image: Remove #ifdefs from select_fdt()

arch/arc/lib/bootm.c | 2 +-
arch/arm/lib/bootm.c | 4 +-
arch/arm/mach-imx/hab.c | 2 +-
arch/microblaze/lib/bootm.c | 2 +-
arch/nds32/lib/bootm.c | 4 +-
arch/riscv/lib/bootm.c | 4 +-
board/synopsys/hsdk/hsdk.c | 2 +-
common/Kconfig.boot | 10 +
common/bootm.c | 14 +-
common/bootm_os.c | 8 +
common/hash.c | 108 +++++-----
common/image-board.c | 359 +++++++++++++++++----------------
common/image-cipher.c | 6 +-
common/image-fdt.c | 275 +++++++++++++------------
common/image-fit-sig.c | 7 +-
common/image-fit.c | 36 ++--
common/image.c | 14 +-
common/spl/Kconfig | 13 +-
include/compiler.h | 5 +-
include/fdt_support.h | 2 +-
include/image.h | 127 ++----------
include/linux/kconfig.h | 13 +-
include/u-boot/aes.h | 8 +-
include/u-boot/hash-checksum.h | 5 +-
include/u-boot/rsa.h | 2 -
lib/Kconfig | 66 +++++-
lib/Makefile | 4 +-
lib/efi_loader/Kconfig | 2 +-
lib/hash-checksum.c | 2 +-
lib/lmb.c | 2 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 16 +-
tools/Kconfig | 92 +++++++++
tools/Makefile | 2 +-
tools/image-host.c | 6 +-
35 files changed, 675 insertions(+), 554 deletions(-)

--
2.33.0.685.g46640cef36-goog