From 330274f19d287723e7f2dc507765e836639b7783 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 27 May 2017 07:38:17 -0600 Subject: fdt: Add all source files to the libfdt build At present only a subset of source files are build. Add the rest and refactor this so that a source file list is available also. This will be used in later commit. Signed-off-by: Simon Glass --- tools/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tools/Makefile') diff --git a/tools/Makefile b/tools/Makefile index 2fc4a583d44..dadc75b9123 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -60,9 +60,11 @@ hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o # Flattened device tree objects -LIBFDT_OBJS := $(addprefix lib/libfdt/, \ - fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o \ - fdt_region.o fdt_sw.o) +LIBFDT_CSRCS := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c \ + fdt_empty_tree.c fdt_addresses.c fdt_overlay.c \ + fdt_region.c +LIBFDT_OBJS := $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_CSRCS))) + RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ rsa-sign.o rsa-verify.o rsa-checksum.o \ rsa-mod-exp.o) -- cgit v1.3.1 From 555ba4889c8ffc5bac933976db9fd915c796f72d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 27 May 2017 07:38:18 -0600 Subject: fdt: Rename existing python libfdt module Now that this module has been accepted upstream we should stop using the local U-Boot one. In preparation for this, rename it to indicate it is for legacy use. Signed-off-by: Simon Glass --- lib/libfdt/libfdt.swig | 113 ------------------------------------------ lib/libfdt/libfdt_legacy.swig | 112 +++++++++++++++++++++++++++++++++++++++++ lib/libfdt/setup.py | 6 +-- tools/Makefile | 11 ++-- tools/dtoc/fdt_normal.py | 2 +- 5 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 lib/libfdt/libfdt.swig create mode 100644 lib/libfdt/libfdt_legacy.swig (limited to 'tools/Makefile') diff --git a/lib/libfdt/libfdt.swig b/lib/libfdt/libfdt.swig deleted file mode 100644 index b24c72b1a22..00000000000 --- a/lib/libfdt/libfdt.swig +++ /dev/null @@ -1,113 +0,0 @@ -/* File: libfdt.i */ -%module libfdt - -%{ -#define SWIG_FILE_WITH_INIT -#include "libfdt.h" -%} - -%pythoncode %{ -def Raise(errnum): - raise ValueError('Error %s' % fdt_strerror(errnum)) - -def Name(fdt, offset): - name, len = fdt_get_name(fdt, offset) - return name - -def String(fdt, offset): - offset = fdt32_to_cpu(offset) - name = fdt_string(fdt, offset) - return name - -def swap32(x): - return (((x << 24) & 0xFF000000) | - ((x << 8) & 0x00FF0000) | - ((x >> 8) & 0x0000FF00) | - ((x >> 24) & 0x000000FF)) - -def fdt32_to_cpu(x): - return swap32(x) - -def Data(prop): - set_prop(prop) - return get_prop_data() -%} - -%include "typemaps.i" -%include "cstring.i" - -%typemap(in) void* = char*; - -typedef int fdt32_t; - -struct fdt_property { - fdt32_t tag; - fdt32_t len; - fdt32_t nameoff; - char data[0]; -}; - -/* - * This is a work-around since I'm not sure of a better way to copy out the - * contents of a string. This is used in dtoc/GetProps(). The intent is to - * pass in a pointer to a property and access the data field at the end of - * it. Ideally the Data() function above would be able to do this directly, - * but I'm not sure how to do that. - */ -#pragma SWIG nowarn=454 -%inline %{ - static struct fdt_property *cur_prop; - - void set_prop(struct fdt_property *prop) { - cur_prop = prop; - } -%} - -%cstring_output_allocate_size(char **s, int *sz, free(*$1)); -%inline %{ - void get_prop_data(char **s, int *sz) { - *sz = fdt32_to_cpu(cur_prop->len); - *s = (char *)malloc(*sz); - if (!*s) - *sz = 0; - else - memcpy(*s, cur_prop + 1, *sz); - } -%} - -%typemap(in) (const void *) { - if (!PyByteArray_Check($input)) { - SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " - "$argnum"" of type '" "$type""'"); - } - $1 = (void *) PyByteArray_AsString($input); -} - -const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); -int fdt_path_offset(const void *fdt, const char *path); -int fdt_first_property_offset(const void *fdt, int nodeoffset); -int fdt_next_property_offset(const void *fdt, int offset); -const char *fdt_strerror(int errval); -const struct fdt_property *fdt_get_property_by_offset(const void *fdt, - int offset, - int *OUTPUT); -const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); -const char *fdt_string(const void *fdt, int stroffset); -int fdt_first_subnode(const void *fdt, int offset); -int fdt_next_subnode(const void *fdt, int offset); - -%typemap(in) (void *) { - if (!PyByteArray_Check($input)) { - SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " - "$argnum"" of type '" "$type""'"); - } - $1 = PyByteArray_AsString($input); -} - -int fdt_delprop(void *fdt, int nodeoffset, const char *name); - -const char *fdt_strerror(int errval); -int fdt_pack(void *fdt); - -int fdt_totalsize(const void *fdt); -int fdt_off_dt_struct(const void *fdt); diff --git a/lib/libfdt/libfdt_legacy.swig b/lib/libfdt/libfdt_legacy.swig new file mode 100644 index 00000000000..9880dd998e6 --- /dev/null +++ b/lib/libfdt/libfdt_legacy.swig @@ -0,0 +1,112 @@ +%module libfdt_legacy + +%{ +#define SWIG_FILE_WITH_INIT +#include "libfdt.h" +%} + +%pythoncode %{ +def Raise(errnum): + raise ValueError('Error %s' % fdt_strerror(errnum)) + +def Name(fdt, offset): + name, len = fdt_get_name(fdt, offset) + return name + +def String(fdt, offset): + offset = fdt32_to_cpu(offset) + name = fdt_string(fdt, offset) + return name + +def swap32(x): + return (((x << 24) & 0xFF000000) | + ((x << 8) & 0x00FF0000) | + ((x >> 8) & 0x0000FF00) | + ((x >> 24) & 0x000000FF)) + +def fdt32_to_cpu(x): + return swap32(x) + +def Data(prop): + set_prop(prop) + return get_prop_data() +%} + +%include "typemaps.i" +%include "cstring.i" + +%typemap(in) void* = char*; + +typedef int fdt32_t; + +struct fdt_property { + fdt32_t tag; + fdt32_t len; + fdt32_t nameoff; + char data[0]; +}; + +/* + * This is a work-around since I'm not sure of a better way to copy out the + * contents of a string. This is used in dtoc/GetProps(). The intent is to + * pass in a pointer to a property and access the data field at the end of + * it. Ideally the Data() function above would be able to do this directly, + * but I'm not sure how to do that. + */ +#pragma SWIG nowarn=454 +%inline %{ + static struct fdt_property *cur_prop; + + void set_prop(struct fdt_property *prop) { + cur_prop = prop; + } +%} + +%cstring_output_allocate_size(char **s, int *sz, free(*$1)); +%inline %{ + void get_prop_data(char **s, int *sz) { + *sz = fdt32_to_cpu(cur_prop->len); + *s = (char *)malloc(*sz); + if (!*s) + *sz = 0; + else + memcpy(*s, cur_prop + 1, *sz); + } +%} + +%typemap(in) (const void *) { + if (!PyByteArray_Check($input)) { + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " + "$argnum"" of type '" "$type""'"); + } + $1 = (void *) PyByteArray_AsString($input); +} + +const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); +int fdt_path_offset(const void *fdt, const char *path); +int fdt_first_property_offset(const void *fdt, int nodeoffset); +int fdt_next_property_offset(const void *fdt, int offset); +const char *fdt_strerror(int errval); +const struct fdt_property *fdt_get_property_by_offset(const void *fdt, + int offset, + int *OUTPUT); +const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); +const char *fdt_string(const void *fdt, int stroffset); +int fdt_first_subnode(const void *fdt, int offset); +int fdt_next_subnode(const void *fdt, int offset); + +%typemap(in) (void *) { + if (!PyByteArray_Check($input)) { + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " + "$argnum"" of type '" "$type""'"); + } + $1 = PyByteArray_AsString($input); +} + +int fdt_delprop(void *fdt, int nodeoffset, const char *name); + +const char *fdt_strerror(int errval); +int fdt_pack(void *fdt); + +int fdt_totalsize(const void *fdt); +int fdt_off_dt_struct(const void *fdt); diff --git a/lib/libfdt/setup.py b/lib/libfdt/setup.py index 845a0c2b10d..fc881351c6d 100644 --- a/lib/libfdt/setup.py +++ b/lib/libfdt/setup.py @@ -22,17 +22,17 @@ else: cflags = None libfdt_module = Extension( - '_libfdt', + '_libfdt_legacy', sources = files, extra_compile_args = cflags ) sys.argv = [progname, '--quiet', 'build_ext', '--inplace', '--force'] -setup (name = 'libfdt', +setup (name = 'libfdt_legaacy', version = '0.1', author = "SWIG Docs", description = """Simple swig libfdt from docs""", ext_modules = [libfdt_module], - py_modules = ["libfdt"], + py_modules = ["libfdt_legacy"], ) diff --git a/tools/Makefile b/tools/Makefile index dadc75b9123..cd08d3b33b6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -117,16 +117,17 @@ fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o # Build a libfdt Python module if swig is available # Use 'sudo apt-get install swig libpython-dev' to enable this hostprogs-y += \ - $(if $(shell which swig 2> /dev/null),_libfdt.so) -_libfdt.so-sharedobjs += $(LIBFDT_OBJS) + $(if $(shell which swig 2> /dev/null),_libfdt_legacy.so) +_libfdt_legacy.so-sharedobjs += $(LIBFDT_OBJS) libfdt: -tools/_libfdt.so: $(patsubst %.o,%.c,$(LIBFDT_OBJS)) tools/libfdt_wrap.c +tools/_libfdt_legacy.so: $(patsubst %.o,%.c,$(LIBFDT_OBJS)) \ + tools/libfdt_legacy_wrap.c LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= ${PYTHON} $(srctree)/lib/libfdt/setup.py \ "$(_hostc_flags)" $^ - mv _libfdt.so $@ + mv _libfdt_legacy.so $@ -tools/libfdt_wrap.c: $(srctree)/lib/libfdt/libfdt.swig +tools/libfdt_legacy_wrap.c: $(srctree)/lib/libfdt/libfdt_legacy.swig swig -python -o $@ $< # TODO(sjg@chromium.org): Is this correct on Mac OS? diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py index cce5c06d8c1..17b0a9a7262 100644 --- a/tools/dtoc/fdt_normal.py +++ b/tools/dtoc/fdt_normal.py @@ -12,7 +12,7 @@ import sys import fdt from fdt import Fdt, NodeBase, PropBase import fdt_util -import libfdt +import libfdt_legacy as libfdt # This deals with a device tree, presenting it as a list of Node and Prop # objects, representing nodes and properties, respectively. -- cgit v1.3.1 From ee95d10ba95092d41dfd740628b04f2b8e9cc8f6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 27 May 2017 07:38:19 -0600 Subject: fdt: Build the new python libfdt module Build the upstream python libfdt module. At present the legacy module is still built and is the one that it used. Future work will switch this over. Signed-off-by: Simon Glass --- tools/Makefile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tools/Makefile') diff --git a/tools/Makefile b/tools/Makefile index cd08d3b33b6..bc411e4ae43 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -63,6 +63,16 @@ FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o LIBFDT_CSRCS := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c \ fdt_empty_tree.c fdt_addresses.c fdt_overlay.c \ fdt_region.c + +# Unfortunately setup.py below cannot handle srctree being ".." which it often +# is. It fails with an error like: +# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o: +# No such file or directory +# To fix this, use an absolute path. +libfdt_tree := $(shell readlink -f $(srctree)/lib/libfdt) + +LIBFDT_SRCS := $(addprefix $(libfdt_tree)/, $(LIBFDT_CSRCS)) +LIBFDT_SWIG := $(addprefix $(libfdt_tree)/, pylibfdt/libfdt.i) LIBFDT_OBJS := $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_CSRCS))) RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ @@ -114,6 +124,23 @@ mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o +# Unfortunately setup.py (or actually the Python distutil implementation) +# puts files into the same directory as the .i file. We cannot touch the source +# directory, so we copy the .i file into the tools/ build subdirectory before +# calling setup. This directory is safe to write to. This ensures that we get +# all three files in $(obj)/tools: _libfdt.so, libfdt.py and libfdt_wrap.c +# The latter is a temporary file which we could actually remove. +tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG) + cp $(LIBFDT_SWIG) tools/. + unset CC; \ + unset CROSS_COMPILE; \ + LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION="u-boot-$(UBOOTVERSION)" \ + CPPFLAGS="$(_hostc_flags)" OBJDIR=tools \ + SOURCES="$(LIBFDT_SRCS) tools/libfdt.i" \ + SWIG_OPTS="-I$(srctree)/lib/libfdt -I$(srctree)/lib" \ + $(libfdt_tree)/pylibfdt/setup.py --quiet build_ext \ + --build-lib tools + # Build a libfdt Python module if swig is available # Use 'sudo apt-get install swig libpython-dev' to enable this hostprogs-y += \ @@ -219,6 +246,10 @@ clean-dirs := lib common always := $(hostprogs-y) +# Build a libfdt Python module if swig is available +# Use 'sudo apt-get install swig libpython-dev' to enable this +always += $(if $(shell which swig 2> /dev/null),_libfdt.so) + # Generated LCD/video logo LOGO_H = $(objtree)/include/bmp_logo.h LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h -- cgit v1.3.1 From 727f153629719c93f9c5df6e391fdfee32377ca7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 27 May 2017 07:38:24 -0600 Subject: fdt: Stop building the old python libfdt module This is no-longer needed, so stop building it. Signed-off-by: Simon Glass --- lib/libfdt/libfdt_legacy.swig | 112 ------------------------------------------ lib/libfdt/setup.py | 38 -------------- tools/Makefile | 18 ------- 3 files changed, 168 deletions(-) delete mode 100644 lib/libfdt/libfdt_legacy.swig delete mode 100644 lib/libfdt/setup.py (limited to 'tools/Makefile') diff --git a/lib/libfdt/libfdt_legacy.swig b/lib/libfdt/libfdt_legacy.swig deleted file mode 100644 index 9880dd998e6..00000000000 --- a/lib/libfdt/libfdt_legacy.swig +++ /dev/null @@ -1,112 +0,0 @@ -%module libfdt_legacy - -%{ -#define SWIG_FILE_WITH_INIT -#include "libfdt.h" -%} - -%pythoncode %{ -def Raise(errnum): - raise ValueError('Error %s' % fdt_strerror(errnum)) - -def Name(fdt, offset): - name, len = fdt_get_name(fdt, offset) - return name - -def String(fdt, offset): - offset = fdt32_to_cpu(offset) - name = fdt_string(fdt, offset) - return name - -def swap32(x): - return (((x << 24) & 0xFF000000) | - ((x << 8) & 0x00FF0000) | - ((x >> 8) & 0x0000FF00) | - ((x >> 24) & 0x000000FF)) - -def fdt32_to_cpu(x): - return swap32(x) - -def Data(prop): - set_prop(prop) - return get_prop_data() -%} - -%include "typemaps.i" -%include "cstring.i" - -%typemap(in) void* = char*; - -typedef int fdt32_t; - -struct fdt_property { - fdt32_t tag; - fdt32_t len; - fdt32_t nameoff; - char data[0]; -}; - -/* - * This is a work-around since I'm not sure of a better way to copy out the - * contents of a string. This is used in dtoc/GetProps(). The intent is to - * pass in a pointer to a property and access the data field at the end of - * it. Ideally the Data() function above would be able to do this directly, - * but I'm not sure how to do that. - */ -#pragma SWIG nowarn=454 -%inline %{ - static struct fdt_property *cur_prop; - - void set_prop(struct fdt_property *prop) { - cur_prop = prop; - } -%} - -%cstring_output_allocate_size(char **s, int *sz, free(*$1)); -%inline %{ - void get_prop_data(char **s, int *sz) { - *sz = fdt32_to_cpu(cur_prop->len); - *s = (char *)malloc(*sz); - if (!*s) - *sz = 0; - else - memcpy(*s, cur_prop + 1, *sz); - } -%} - -%typemap(in) (const void *) { - if (!PyByteArray_Check($input)) { - SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " - "$argnum"" of type '" "$type""'"); - } - $1 = (void *) PyByteArray_AsString($input); -} - -const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); -int fdt_path_offset(const void *fdt, const char *path); -int fdt_first_property_offset(const void *fdt, int nodeoffset); -int fdt_next_property_offset(const void *fdt, int offset); -const char *fdt_strerror(int errval); -const struct fdt_property *fdt_get_property_by_offset(const void *fdt, - int offset, - int *OUTPUT); -const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); -const char *fdt_string(const void *fdt, int stroffset); -int fdt_first_subnode(const void *fdt, int offset); -int fdt_next_subnode(const void *fdt, int offset); - -%typemap(in) (void *) { - if (!PyByteArray_Check($input)) { - SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " - "$argnum"" of type '" "$type""'"); - } - $1 = PyByteArray_AsString($input); -} - -int fdt_delprop(void *fdt, int nodeoffset, const char *name); - -const char *fdt_strerror(int errval); -int fdt_pack(void *fdt); - -int fdt_totalsize(const void *fdt); -int fdt_off_dt_struct(const void *fdt); diff --git a/lib/libfdt/setup.py b/lib/libfdt/setup.py deleted file mode 100644 index fc881351c6d..00000000000 --- a/lib/libfdt/setup.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -setup.py file for SWIG libfdt -""" - -from distutils.core import setup, Extension -import os -import sys - -# Don't cross-compile - always use the host compiler. -del os.environ['CROSS_COMPILE'] -del os.environ['CC'] - -progname = sys.argv[0] -cflags = sys.argv[1] -files = sys.argv[2:] - -if cflags: - cflags = [flag for flag in cflags.split(' ') if flag] -else: - cflags = None - -libfdt_module = Extension( - '_libfdt_legacy', - sources = files, - extra_compile_args = cflags -) - -sys.argv = [progname, '--quiet', 'build_ext', '--inplace', '--force'] - -setup (name = 'libfdt_legaacy', - version = '0.1', - author = "SWIG Docs", - description = """Simple swig libfdt from docs""", - ext_modules = [libfdt_module], - py_modules = ["libfdt_legacy"], - ) diff --git a/tools/Makefile b/tools/Makefile index bc411e4ae43..cb1683e1539 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -141,24 +141,6 @@ tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG) $(libfdt_tree)/pylibfdt/setup.py --quiet build_ext \ --build-lib tools -# Build a libfdt Python module if swig is available -# Use 'sudo apt-get install swig libpython-dev' to enable this -hostprogs-y += \ - $(if $(shell which swig 2> /dev/null),_libfdt_legacy.so) -_libfdt_legacy.so-sharedobjs += $(LIBFDT_OBJS) -libfdt: - -tools/_libfdt_legacy.so: $(patsubst %.o,%.c,$(LIBFDT_OBJS)) \ - tools/libfdt_legacy_wrap.c - LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= ${PYTHON} $(srctree)/lib/libfdt/setup.py \ - "$(_hostc_flags)" $^ - mv _libfdt_legacy.so $@ - -tools/libfdt_legacy_wrap.c: $(srctree)/lib/libfdt/libfdt_legacy.swig - swig -python -o $@ $< - -# TODO(sjg@chromium.org): Is this correct on Mac OS? - ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . -- cgit v1.3.1