Skip to content

Commit 15b97f5

Browse files
masahir0ytrini
authored andcommitted
pylibfdt: move pylibfdt to scripts/dtc/pylibfdt and refactor makefile
The pylibfdt is used by dtoc (and, indirectly by binman), but there is no reason why it must be generated in the tools/ directory. Recently, U-Boot switched over to the bundled DTC, and the directory structure under scripts/dtc/ now mirrors the upstream DTC project. So, scripts/dtc/pylibfdt is the best location. I also rewrote the Makefile in a cleaner Kbuild style. The scripts from the upstream have been moved as follows: lib/libfdt/pylibfdt/setup.py -> scripts/dtc/pylibfdt/setup.py lib/libfdt/pylibfdt/libfdt.i -> scripts/dtc/pylibfdt/libfdt.i_shipped The .i_shipped is coped to .i during building because the .i must be located in the objtree when we build it out of tree. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 999a78d commit 15b97f5

File tree

10 files changed

+41
-38
lines changed

10 files changed

+41
-38
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ $(timestamp_h): $(srctree)/Makefile FORCE
13801380
$(call filechk,timestamp.h)
13811381

13821382
checkbinman: tools
1383-
@if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \
1383+
@if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \
13841384
echo >&2; \
13851385
echo >&2 '*** binman needs the Python libfdt library.'; \
13861386
echo >&2 '*** Either install it on your system, or try:'; \

scripts/Makefile.spl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ quiet_cmd_fdtgrep = FDTGREP $@
257257
$(obj)/$(SPL_BIN).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE
258258
$(call if_changed,fdtgrep)
259259

260-
pythonpath = PYTHONPATH=tools
260+
pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
261261

262262
quiet_cmd_dtocc = DTOC C $@
263263
cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
@@ -381,7 +381,7 @@ ifneq ($(cmd_files),)
381381
endif
382382

383383
checkdtoc: tools
384-
@if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \
384+
@if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \
385385
echo '*** dtoc needs the Python libfdt library. Either '; \
386386
echo '*** install it on your system, or try:'; \
387387
echo '***'; \

scripts/dtc/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
2929

3030
# generated files need to be cleaned explicitly
3131
clean-files := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h
32+
33+
# Added for U-Boot
34+
subdir-y += pylibfdt

scripts/dtc/pylibfdt/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/_libfdt.so
2+
/libfdt.py
3+
/libfdt.pyc
4+
/libfdt_wrap.c

scripts/dtc/pylibfdt/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Unfortunately setup.py below cannot handle srctree being ".." which it often
2+
# is. It fails with an error like:
3+
# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o:
4+
# No such file or directory
5+
# To fix this, use an absolute path.
6+
LIBFDT_srcdir = $(abspath $(srctree)/$(src)/../libfdt)
7+
8+
include $(LIBFDT_srcdir)/Makefile.libfdt
9+
10+
# Unfortunately setup.py (or actually the Python distutil implementation) puts
11+
# files into the same directory as the .i file. We cannot touch the source
12+
# directory, so we "ship" .i file into the objtree.
13+
PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \
14+
$(obj)/libfdt.i
15+
16+
quiet_cmd_pymod = PYMOD $@
17+
cmd_pymod = unset CC; unset CROSS_COMPILE; unset CFLAGS;\
18+
LDFLAGS="$(HOSTLDFLAGS)" \
19+
VERSION="u-boot-$(UBOOTVERSION)" \
20+
CPPFLAGS="$(HOSTCFLAGS) -I$(LIBFDT_srcdir)" OBJDIR=$(obj) \
21+
SOURCES="$(PYLIBFDT_srcs)" \
22+
SWIG_OPTS="-I$(LIBFDT_srcdir) -I$(LIBFDT_srcdir)/.." \
23+
$(PYTHON) $< --quiet build_ext --inplace
24+
25+
$(obj)/_libfdt.so: $(src)/setup.py $(PYLIBFDT_srcs) FORCE
26+
$(call if_changed,pymod)
27+
28+
always += _libfdt.so
29+
30+
clean-files += libfdt.i _libfdt.so libfdt.py libfdt_wrap.c

tools/.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/_libfdt.so
21
/atmel_pmecc_params
32
/bin2header
43
/bmp_logo
@@ -17,9 +16,6 @@
1716
/img2srec
1817
/kwboot
1918
/lib/
20-
/libfdt.py
21-
/libfdt.pyc
22-
/libfdt_wrap.c
2319
/mips-relocs
2420
/mkenvimage
2521
/mkexynosspl

tools/Makefile

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ LIBFDT_CSRCS := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c \
6363
fdt_empty_tree.c fdt_addresses.c fdt_overlay.c \
6464
fdt_region.c
6565

66-
# Unfortunately setup.py below cannot handle srctree being ".." which it often
67-
# is. It fails with an error like:
68-
# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o:
69-
# No such file or directory
70-
# To fix this, use an absolute path.
71-
libfdt_tree := $(shell readlink -f $(srctree)/lib/libfdt)
72-
73-
LIBFDT_SRCS := $(addprefix $(libfdt_tree)/, $(LIBFDT_CSRCS))
74-
LIBFDT_SWIG := $(addprefix $(libfdt_tree)/, pylibfdt/libfdt.i)
7566
LIBFDT_OBJS := $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_CSRCS)))
7667

7768
RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
@@ -123,23 +114,6 @@ mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o
123114
fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
124115
fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
125116

126-
# Unfortunately setup.py (or actually the Python distutil implementation)
127-
# puts files into the same directory as the .i file. We cannot touch the source
128-
# directory, so we copy the .i file into the tools/ build subdirectory before
129-
# calling setup. This directory is safe to write to. This ensures that we get
130-
# all three files in $(obj)/tools: _libfdt.so, libfdt.py and libfdt_wrap.c
131-
# The latter is a temporary file which we could actually remove.
132-
tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG)
133-
$(Q)cp $(LIBFDT_SWIG) tools/.
134-
$(Q)unset CC; \
135-
unset CROSS_COMPILE; \
136-
LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION="u-boot-$(UBOOTVERSION)" \
137-
CPPFLAGS="$(_hostc_flags)" OBJDIR=tools \
138-
SOURCES="$(LIBFDT_SRCS) tools/libfdt.i" \
139-
SWIG_OPTS="-I$(srctree)/lib/libfdt -I$(srctree)/lib" \
140-
$(PYTHON) $(libfdt_tree)/pylibfdt/setup.py --quiet build_ext \
141-
--build-lib tools
142-
143117
ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
144118
# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
145119
# the mxsimage support within tools/mxsimage.c .
@@ -231,10 +205,6 @@ clean-dirs := lib common
231205

232206
always := $(hostprogs-y)
233207

234-
# Build a libfdt Python module if swig is available
235-
# Use 'sudo apt-get install swig libpython-dev' to enable this
236-
always += $(if $(shell which swig 2> /dev/null),_libfdt.so)
237-
238208
# Generated LCD/video logo
239209
LOGO_H = $(objtree)/include/bmp_logo.h
240210
LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h

tools/binman/binman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sys.path.insert(0, os.path.join(our_path, dirname))
2222

2323
# Bring in the libfdt module
24-
sys.path.insert(0, 'tools')
24+
sys.path.insert(0, 'scripts/dtc/pylibfdt')
2525

2626
# Also allow entry-type modules to be brought in from the etype directory.
2727
sys.path.insert(0, os.path.join(our_path, 'etype'))

0 commit comments

Comments
 (0)