Skip to content

Commit

Permalink
Makefile: Allow padding zeros when converting DTB to C source
Browse files Browse the repository at this point in the history
We extend d2c.sh to allow padding zeros in output C source when
converting DTB to C source. Using this feature, platforms can
create extra room for in-place FDT fixups on built-in DTBs.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Signed-off-by: Anup Patel <[email protected]>
Reviewed-by: Atish Patra <[email protected]>
  • Loading branch information
xypron authored and avpatel committed Oct 18, 2020
1 parent 9c07c51 commit e9a4bfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ compile_dts = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
$(CPP) $(DTSCPPFLAGS) $(2) | $(DTC) -O dtb -i `dirname $(2)` -o $(1)
compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
echo " D2C $(subst $(build_dir)/,,$(1))"; \
$(src_dir)/scripts/d2c.sh -i $(4) -a $(3) -p $(2) > $(1)
$(if $($(2)-varalign-$(3)),$(eval D2C_ALIGN_BYTES := $($(2)-varalign-$(3))),$(eval D2C_ALIGN_BYTES := $(4))) \
$(if $($(2)-varprefix-$(3)),$(eval D2C_NAME_PREFIX := $($(2)-varprefix-$(3))),$(eval D2C_NAME_PREFIX := $(5))) \
$(if $($(2)-padding-$(3)),$(eval D2C_PADDING_BYTES := $($(2)-padding-$(3))),$(eval D2C_PADDING_BYTES := 0)) \
$(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1)
compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \
echo "$(1:.dep=$(2)): $(3)" >> $(1)
Expand Down Expand Up @@ -361,7 +364,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
$(platform_build_dir)/%.c: $(platform_build_dir)/%.dtb
$(call compile_d2c,$@,$(platform-varprefix-$(subst .dtb,.o,$(subst /,-,$(subst $(platform_build_dir)/,,$<)))),16,$<)
$(call compile_d2c,$@,platform,$(subst .dtb,.o,$(subst /,-,$(subst $(platform_build_dir)/,,$<))),16,dt,$<)
$(platform_build_dir)/%.dtb: $(platform_src_dir)/%.dts
$(call compile_dts,$@,$<)
Expand Down
9 changes: 8 additions & 1 deletion scripts/d2c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ function usage()
echo " -i <input_file_path> Input binary file path"
echo " -a <c_align> Output C array alignment"
echo " -p <c_prefix> Output C array name prefix"
echo " -t <num_zero_bytes> Output padding zero bytes"
exit 1;
}

# Command line options
INPUT_PATH=""
OUTPUT_C_ALIGN=""
OUTPUT_C_PREFIX=""
NUM_ZERO_BYTES=0

while getopts "hi:a:p:o:" o; do
while getopts "hi:a:p:t:" o; do
case "${o}" in
h)
usage
Expand All @@ -31,6 +33,9 @@ while getopts "hi:a:p:o:" o; do
p)
OUTPUT_C_PREFIX=${OPTARG}
;;
t)
NUM_ZERO_BYTES=${OPTARG}
;;
*)
usage
;;
Expand Down Expand Up @@ -62,6 +67,8 @@ printf "const char __attribute__((aligned(%s))) %s_start[] = {\n" "${OUTPUT_C_AL

od -v -t x1 -An ${INPUT_PATH} | awk '{for (i=1; i<=NF; i++) printf " 0x%s,", $i; printf "\n"; }'

echo __dummy__ | awk "{for (i=1; i<=${NUM_ZERO_BYTES}; i++) { printf \" 0x00,\"; if (i % 16 == 0) printf \"\n\"; } }"

printf "};\n"

printf "const unsigned long %s_size = sizeof(%s_start);\n" "${OUTPUT_C_PREFIX}" "${OUTPUT_C_PREFIX}"

0 comments on commit e9a4bfb

Please sign in to comment.