[U-Boot] [RFC PATCH 0/2] tools: avoid including .c files in lib/ and common/

Masahiro Yamada (2): tools: refactor HOSTLOADLIBES_* options tools: avoid including .c files in lib/ or common/
tools/Makefile | 71 ++++++++++++++++++++++++--------------------------- tools/common/Makefile | 18 +++++++++++++ tools/crc32.c | 1 - tools/env_embedded.c | 1 - tools/fdt.c | 1 - tools/fdt_ro.c | 1 - tools/fdt_rw.c | 1 - tools/fdt_strerror.c | 1 - tools/fdt_wip.c | 1 - tools/fdtdec.c | 1 - tools/image-fit.c | 1 - tools/image-sig.c | 1 - tools/image.c | 1 - tools/lib/Makefile | 33 ++++++++++++++++++++++++ tools/md5.c | 1 - tools/rsa-checksum.c | 1 - tools/rsa-sign.c | 1 - tools/rsa-verify.c | 1 - tools/sha1.c | 1 - tools/sha256.c | 1 - 20 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 tools/common/Makefile delete mode 100644 tools/crc32.c delete mode 100644 tools/env_embedded.c delete mode 100644 tools/fdt.c delete mode 100644 tools/fdt_ro.c delete mode 100644 tools/fdt_rw.c delete mode 100644 tools/fdt_strerror.c delete mode 100644 tools/fdt_wip.c delete mode 100644 tools/fdtdec.c delete mode 100644 tools/image-fit.c delete mode 100644 tools/image-sig.c delete mode 100644 tools/image.c create mode 100644 tools/lib/Makefile delete mode 100644 tools/md5.c delete mode 100644 tools/rsa-checksum.c delete mode 100644 tools/rsa-sign.c delete mode 100644 tools/rsa-verify.c delete mode 100644 tools/sha1.c delete mode 100644 tools/sha256.c

The tools mkimage, dumpimage, fit_info, fit_check_sign always have the common libraries to be linked, so HOSTLOADLIBES_* can be consolidated a little bit.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com ---
tools/Makefile | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile index 7610557..a8c52b1 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -104,28 +104,27 @@ fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
# TODO(sjg@chromium.org): Is this correct on Mac OS?
-# MXSImage needs LibSSL ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) -HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS endif
ifdef CONFIG_FIT_SIGNATURE -HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto -HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto - # This affects include/image.h, but including the board config file # is tricky, so manually define this options here. HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE endif
+# MXSImage needs LibSSL +ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),) +HOSTLOADLIBES_mkimage$(SFX) += -lssl -lcrypto +endif + +HOSTLOADLIBES_dumpimage$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) +HOSTLOADLIBES_fit_info$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) +HOSTLOADLIBES_fit_check_sign$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) + hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX) hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX) HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic

On 4 June 2014 04:39, Masahiro Yamada yamada.m@jp.panasonic.com wrote:
The tools mkimage, dumpimage, fit_info, fit_check_sign always have the common libraries to be linked, so HOSTLOADLIBES_* can be consolidated a little bit.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com
Acked-by: Simon Glass sjg@chromium.org

We have many files in tools/ which include their counterpart .c files in lib/ or common/.
It seems better to directly generate .o files from lib/*.c or common/*.c.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com ---
tools/Makefile | 52 ++++++++++++++++++++++++--------------------------- tools/common/Makefile | 18 ++++++++++++++++++ tools/crc32.c | 1 - tools/env_embedded.c | 1 - tools/fdt.c | 1 - tools/fdt_ro.c | 1 - tools/fdt_rw.c | 1 - tools/fdt_strerror.c | 1 - tools/fdt_wip.c | 1 - tools/fdtdec.c | 1 - tools/image-fit.c | 1 - tools/image-sig.c | 1 - tools/image.c | 1 - tools/lib/Makefile | 33 ++++++++++++++++++++++++++++++++ tools/md5.c | 1 - tools/rsa-checksum.c | 1 - tools/rsa-sign.c | 1 - tools/rsa-verify.c | 1 - tools/sha1.c | 1 - tools/sha256.c | 1 - 20 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 tools/common/Makefile delete mode 100644 tools/crc32.c delete mode 100644 tools/env_embedded.c delete mode 100644 tools/fdt.c delete mode 100644 tools/fdt_ro.c delete mode 100644 tools/fdt_rw.c delete mode 100644 tools/fdt_strerror.c delete mode 100644 tools/fdt_wip.c delete mode 100644 tools/fdtdec.c delete mode 100644 tools/image-fit.c delete mode 100644 tools/image-sig.c delete mode 100644 tools/image.c create mode 100644 tools/lib/Makefile delete mode 100644 tools/md5.c delete mode 100644 tools/rsa-checksum.c delete mode 100644 tools/rsa-sign.c delete mode 100644 tools/rsa-verify.c delete mode 100644 tools/sha1.c delete mode 100644 tools/sha256.c
diff --git a/tools/Makefile b/tools/Makefile index a8c52b1..68d51e2 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -47,7 +47,9 @@ hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX) HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic
hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX) -envcrc$(SFX)-objs := crc32.o env_embedded.o envcrc.o sha1.o +envcrc$(SFX)-objs := envcrc.o +HOSTLOADLIBES_envcrc$(SFX) := $(addprefix $(obj)/, \ + lib/crc32.o lib/sha1.o common/env_embedded.o)
hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX) HOSTCFLAGS_gen_eth_addr$(SFX).o := -pedantic @@ -59,49 +61,49 @@ hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX) HOSTCFLAGS_xway-swap-bytes$(SFX).o := -pedantic
hostprogs-y += mkenvimage$(SFX) -mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o +mkenvimage$(SFX)-objs := mkenvimage.o os_support.o +HOSTLOADLIBES_mkenvimage$(SFX) := $(obj)/lib/crc32.o
hostprogs-y += dumpimage$(SFX) mkimage$(SFX) hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info$(SFX) fit_check_sign$(SFX)
-FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o -# Flattened device tree objects -LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o -RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o - # common objs for dumpimage and mkimage dumpimage-mkimage-objs := aisimage.o \ atmelimage.o \ - $(FIT_SIG_OBJS-y) \ - crc32.o \ default_image.o \ - fdtdec.o \ fit_common.o \ fit_image.o \ gpimage.o \ gpimage-common.o \ - image-fit.o \ image-host.o \ - image.o \ imagetool.o \ imximage.o \ kwbimage.o \ - md5.o \ mxsimage.o \ omapimage.o \ os_support.o \ pblimage.o \ - sha1.o \ - sha256.o \ - ublimage.o \ - $(LIBFDT_OBJS) \ - $(RSA_OBJS-y) + ublimage.o
dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
+IMAGE_OBJS-y := image.o image-fit.o +IMAGE_OBJS-$(CONFIG_FIT_SIGNATURE) += image-sig.o +# Flattened device tree objects +LIBFDT_OBJS := fdtdec.o libfdt/fdt.o libfdt/fdt_ro.o libfdt/fdt_rw.o \ + libfdt/fdt_strerror.o libfdt/fdt_wip.o +RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa/rsa-sign.o rsa/rsa-verify.o \ + rsa/rsa-checksum.o +export IMAGE_OBJS-y LIBFDT_OBJS RSA_OBJS-y + +HOSTLOADLIBES_mkimage$(SFX) += \ + $(addprefix $(obj)/, lib/crc32.o lib/sha1.o lib/sha256.o lib/md5.o \ + $(addprefix common/, $(IMAGE_OBJS-y)) \ + $(addprefix lib/, $(LIBFDT_OBJS) $(RSA_OBJS-y))) + # TODO(sjg@chromium.org): Is this correct on Mac OS?
ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) @@ -138,26 +140,20 @@ hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX) hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX) hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
-ubsha1$(SFX)-objs := os_support.o sha1.o ubsha1.o - +ubsha1$(SFX)-objs := os_support.o ubsha1.o HOSTCFLAGS_ubsha1.o := -pedantic +HOSTLOADLIBES_ubsha1 := $(obj)/lib/sha1.o
hostprogs-$(CONFIG_KIRKWOOD) += kwboot$(SFX) hostprogs-y += proftool$(SFX) hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
-# We build some files with extra pedantic flags to try to minimize things -# that won't build on some weird host compiler -- though there are lots of -# exceptions for files that aren't complaint. -HOSTCFLAGS_crc32.o := -pedantic -HOSTCFLAGS_md5.o := -pedantic -HOSTCFLAGS_sha1.o := -pedantic -HOSTCFLAGS_sha256.o := -pedantic - # Don't build by default #hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX) #HOSTCFLAGS_mpc86x_clk$(SFX).o := -pedantic
+subdir-y := lib common + always := $(hostprogs-y)
# Generated LCD/video logo diff --git a/tools/common/Makefile b/tools/common/Makefile new file mode 100644 index 0000000..8d262f8 --- /dev/null +++ b/tools/common/Makefile @@ -0,0 +1,18 @@ +# Generate tools/common/*.o from common/*.c +src := common + +# Define "hostprogs-y := __dummy" to include scripts/Makefile.host +# but we do not want "__dummy". +hostprogs-y := __dummy + +__dummy-objs := env_embedded.o $(IMAGE_OBJS-y) +always := $(__dummy-objs) + +HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \ + $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ + -I$(srctree)/lib/libfdt \ + -I$(srctree)/tools \ + -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \ + -DUSE_HOSTCC \ + -D__KERNEL_STRICT_NAMES \ + -D_GNU_SOURCE diff --git a/tools/crc32.c b/tools/crc32.c deleted file mode 100644 index aed7112..0000000 --- a/tools/crc32.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/crc32.c" diff --git a/tools/env_embedded.c b/tools/env_embedded.c deleted file mode 100644 index 59a6357..0000000 --- a/tools/env_embedded.c +++ /dev/null @@ -1 +0,0 @@ -#include "../common/env_embedded.c" diff --git a/tools/fdt.c b/tools/fdt.c deleted file mode 100644 index 1eafc56..0000000 --- a/tools/fdt.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/libfdt/fdt.c" diff --git a/tools/fdt_ro.c b/tools/fdt_ro.c deleted file mode 100644 index 9005fe3..0000000 --- a/tools/fdt_ro.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/libfdt/fdt_ro.c" diff --git a/tools/fdt_rw.c b/tools/fdt_rw.c deleted file mode 100644 index adc3fdf..0000000 --- a/tools/fdt_rw.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/libfdt/fdt_rw.c" diff --git a/tools/fdt_strerror.c b/tools/fdt_strerror.c deleted file mode 100644 index d0b5822..0000000 --- a/tools/fdt_strerror.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/libfdt/fdt_strerror.c" diff --git a/tools/fdt_wip.c b/tools/fdt_wip.c deleted file mode 100644 index 7810f07..0000000 --- a/tools/fdt_wip.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/libfdt/fdt_wip.c" diff --git a/tools/fdtdec.c b/tools/fdtdec.c deleted file mode 100644 index f1c2256..0000000 --- a/tools/fdtdec.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/fdtdec.c" diff --git a/tools/image-fit.c b/tools/image-fit.c deleted file mode 100644 index 037e5cc..0000000 --- a/tools/image-fit.c +++ /dev/null @@ -1 +0,0 @@ -#include "../common/image-fit.c" diff --git a/tools/image-sig.c b/tools/image-sig.c deleted file mode 100644 index e45419f..0000000 --- a/tools/image-sig.c +++ /dev/null @@ -1 +0,0 @@ -#include "../common/image-sig.c" diff --git a/tools/image.c b/tools/image.c deleted file mode 100644 index 0f9bacc..0000000 --- a/tools/image.c +++ /dev/null @@ -1 +0,0 @@ -#include "../common/image.c" diff --git a/tools/lib/Makefile b/tools/lib/Makefile new file mode 100644 index 0000000..9284746 --- /dev/null +++ b/tools/lib/Makefile @@ -0,0 +1,33 @@ +# Generate tools/lib/*.o from lib/*.c +src := lib + +# Define "hostprogs-y := __dummy" to include scripts/Makefile.host +# but we do not want "__dummy". +hostprogs-y := __dummy + +__dummy-objs := crc32.o sha1.o sha256.o md5.o \ + $(LIBFDT_OBJS) $(RSA_OBJS-y) +always := $(__dummy-objs) + +# We build some files with extra pedantic flags to try to minimize things +# that won't build on some weird host compiler -- though there are lots of +# exceptions for files that aren't complaint. +HOSTCFLAGS_crc32.o := -pedantic +HOSTCFLAGS_md5.o := -pedantic +HOSTCFLAGS_sha1.o := -pedantic +HOSTCFLAGS_sha256.o := -pedantic + +ifdef CONFIG_FIT_SIGNATURE +# This affects include/image.h, but including the board config file +# is tricky, so manually define this options here. +HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE +endif + +HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \ + $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ + -I$(srctree)/lib/libfdt \ + -I$(srctree)/tools \ + -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \ + -DUSE_HOSTCC \ + -D__KERNEL_STRICT_NAMES \ + -D_GNU_SOURCE diff --git a/tools/md5.c b/tools/md5.c deleted file mode 100644 index befaa32..0000000 --- a/tools/md5.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/md5.c" diff --git a/tools/rsa-checksum.c b/tools/rsa-checksum.c deleted file mode 100644 index 09033e6..0000000 --- a/tools/rsa-checksum.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/rsa/rsa-checksum.c" diff --git a/tools/rsa-sign.c b/tools/rsa-sign.c deleted file mode 100644 index 150bbe1..0000000 --- a/tools/rsa-sign.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/rsa/rsa-sign.c" diff --git a/tools/rsa-verify.c b/tools/rsa-verify.c deleted file mode 100644 index bb662a1..0000000 --- a/tools/rsa-verify.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/rsa/rsa-verify.c" diff --git a/tools/sha1.c b/tools/sha1.c deleted file mode 100644 index 0d717df..0000000 --- a/tools/sha1.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/sha1.c" diff --git a/tools/sha256.c b/tools/sha256.c deleted file mode 100644 index 8ca931f..0000000 --- a/tools/sha256.c +++ /dev/null @@ -1 +0,0 @@ -#include "../lib/sha256.c"

Hi Simon,
On Wed, 4 Jun 2014 19:39:14 +0900 Masahiro Yamada yamada.m@jp.panasonic.com wrote:
We have many files in tools/ which include their counterpart .c files in lib/ or common/.
It seems better to directly generate .o files from lib/*.c or common/*.c.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com
I was thinking about this patch last night and I changed my mind. This patch seems too tricky and ugly.
So I decided to discard this one and take a more simple and standard way.
Could you check the following, please? http://patchwork.ozlabs.org/patch/356149/
Best Regards Masahiro Yamada
participants (2)
-
Masahiro Yamada
-
Simon Glass