Skip to contentSkip to conversation

libfdt: make lib/libfdt/ contain only wrappers

PATCH New Masahiro Yamada 2 participants 7 messages Apr 16, 2020 – Apr 27, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover libfdt: make lib/libfdt/ contain only wrappers

Linux DT community follows the strict rule that they never locally modify libfdt. In Linux, lib/fdt_*.c are wrapper files to scripts/dtc/libfdt/fdt_*.c and scripts/dtc/ is synced with upstream DTC by running scripts/dtc/update-dtc-source.sh
The local code in Linux is separated in drivers/of/.

On the other hand, U-Boot originally had own copies in lib/libfdt/, and people locally modified them. The code diverged, and made it difficult to re-sync with upstream.

In 2018, I worked on migrating them to wrapper files, just like Linux does. 50a327ded68b7e675389ad284ea3f8c62e683bda 87be1e9fb4dcc130e90d497cc5ce49c715efc6c2 26e961c8cfdff00c5c9389d301d9a2eb10eb844c

This series completes this work.

1/3 migrates fdt_ro.c to a wrapper.
Two years ago, it diverged from the upstream, and gave up resync. Now, I do not see essential diff.

2/3 and 3/3 separate fdt_region out of the upstream code. I am resending them after two years since the previous rejection. It was unfortuate that they were rejected based on the assumption that is unlikely to happen. They should be re-evaluated.

Masahiro Yamada (3):
libfdt: migrate fdt_ro.c to a wrapper of scripts/dtc/libfdt/fdt_ro.c
fdt_region: move fdt_region.c to common/ from lib/libfdt/
libfdt: split fdt_region declarations out to <fdt_region.h>

 common/Makefile                     |   1 +
 {lib/libfdt => common}/fdt_region.c |   1 +
 common/image-fit-sig.c              |   1 +
 include/fdt_region.h                | 304 +++++++++
 include/linux/libfdt.h              | 299 ---------
 lib/libfdt/Makefile                 |   9 +-
 lib/libfdt/fdt_ro.c                 | 925 +---------------------------
 tools/Makefile                      |  13 +-
 tools/fdtgrep.c                     |   1 +
 tools/image-host.c                  |   1 +
 tools/libfdt/fdt_ro.c               |   2 +
 11 files changed, 317 insertions(+), 1240 deletions(-)
 rename {lib/libfdt => common}/fdt_region.c (99%)
 create mode 100644 include/fdt_region.h
 create mode 100644 tools/libfdt/fdt_ro.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/3 libfdt: migrate fdt_ro.c to a wrapper of scripts/dtc/libfdt/fdt_ro.c

There is no essential difference between scripts/dtc/libfdt/fdt_ro.c and lib/libfdt/fdt_ro.c

Migrate to a simple wrapper like the other files.

---

Changes in v2:
- refactor tools/Makefile

 lib/libfdt/Makefile   |   6 +-
 lib/libfdt/fdt_ro.c   | 925 +-----------------------------------------
 tools/Makefile        |   5 +-
 tools/libfdt/fdt_ro.c |   2 +
 4 files changed, 6 insertions(+), 932 deletions(-)
 create mode 100644 tools/libfdt/fdt_ro.c
lib/libfdt/Makefile +1 -5
index 5d3ae4e2f1..878659f99e 100644
@@ -3,9 +3,9 @@
 # (C) Copyright 2000-2007
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 
-# Use upstream code.
 obj-y += \
 	fdt.o \
+	fdt_ro.o \
 	fdt_wip.o \
 	fdt_strerror.o \
 	fdt_sw.o \
@@ -15,10 +15,6 @@ obj-y += \
 
 obj-$(CONFIG_OF_LIBFDT_OVERLAY) += fdt_overlay.o
 
-# Locally modified for U-Boot.
-# TODO: split out the local modifiction.
-obj-y += fdt_ro.o
-
 # U-Boot own file
 obj-y += fdt_region.o
 
lib/libfdt/fdt_ro.c +1 -924

926 lines not on this page · raw message

tools/Makefile +2 -3
index 3b9ae90369..bfdbb1339c 100644
@@ -63,11 +63,10 @@ FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := common/image-cipher.o
 
 # The following files are synced with upstream DTC.
 # Use synced versions from scripts/dtc/libfdt/.
-LIBFDT_SRCS_SYNCED := fdt.c fdt_wip.c fdt_sw.c fdt_rw.c \
+LIBFDT_SRCS_SYNCED := 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
-# The following files are locally modified for U-Boot (unfotunately).
 # Use U-Boot own versions from lib/libfdt/.
-LIBFDT_SRCS_UNSYNCED := fdt_ro.c fdt_region.c
+LIBFDT_SRCS_UNSYNCED := fdt_region.c
 
 LIBFDT_OBJS := $(addprefix libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_SYNCED))) \
 	       $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_UNSYNCED)))
tools/libfdt/fdt_ro.c new file +2 -0
new file mode 100644
index 0000000000..8a9735a48c
@@ -0,0 +1,2 @@
+#include "fdt_host.h"
+#include "../scripts/dtc/libfdt/fdt_ro.c"
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 1/3 libfdt: migrate fdt_ro.c to a wrapper of scripts/dtc/libfdt/fdt_ro.c

There is no essential difference between scripts/dtc/libfdt/fdt_ro.c and lib/libfdt/fdt_ro.c

Migrate to a simple wrapper like the other files.

---

Changes in v2:
- refactor tools/Makefile

 lib/libfdt/Makefile   |   6 +-
 lib/libfdt/fdt_ro.c   | 925 +-----------------------------------------
 tools/Makefile        |   5 +-
 tools/libfdt/fdt_ro.c |   2 +
 4 files changed, 6 insertions(+), 932 deletions(-)
 create mode 100644 tools/libfdt/fdt_ro.c

Applied to u-boot-dm, thanks!

#3 lore raw

PATCH v2 2/3 fdt_region: move fdt_region.c to common/ from lib/libfdt/

In reply to Masahiro Yamada

My goal is to sync lib/libfdt/ with scripts/dtc/libfdt/, that is, make lib/libfdt/ contain only wrapper files.

fdt_region.c was written only for U-Boot to implement the verified boot. So, this belongs to the same group as common/fdt_support.c, which is a collection of U-Boot own fdt helpers.

Move lib/libfdt/fdt_region.c to common/fdt_region.c . This is necessary only when CONFIG_(SPL_TPL_)_FIT_SIGNATURE is enabled.

---

I am resending this after two years since v1.

My previous attempt sank by this comment:
http://patchwork.ozlabs.org/project/uboot/patch/1521623017-29312-5-git-send-email-yamada.masahiro at socionext.com/#1881196

Two years have passed, but I still do not see this file in upstream DTC.

Changes in v2:
- rebase

 common/Makefile                     |  1 +
 {lib/libfdt => common}/fdt_region.c |  0
 lib/libfdt/Makefile                 |  3 ---
 tools/Makefile                      | 12 ++++--------
 4 files changed, 5 insertions(+), 11 deletions(-)
 rename {lib/libfdt => common}/fdt_region.c (100%)
common/Makefile +1 -0
index 702f2396cf..a3f3faf479 100644
@@ -110,6 +110,7 @@ obj-y += image.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
+obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
 obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
 obj-$(CONFIG_IMAGE_SIGN_INFO) += image-sig.o
common/fdt_region.c renamed from lib/libfdt/fdt_region.c +0 -0
similarity index 100%
rename from lib/libfdt/fdt_region.c
rename to common/fdt_region.c
lib/libfdt/Makefile +0 -3
index 878659f99e..1fe50ecbe5 100644
@@ -15,8 +15,5 @@ obj-y += \
 
 obj-$(CONFIG_OF_LIBFDT_OVERLAY) += fdt_overlay.o
 
-# U-Boot own file
-obj-y += fdt_region.o
-
 ccflags-y := -I$(srctree)/scripts/dtc/libfdt \
 	-DFDT_ASSUME_MASK=$(CONFIG_$(SPL_TPL_)OF_LIBFDT_ASSUME_MASK)
tools/Makefile +4 -8
index bfdbb1339c..ee9077ca82 100644
@@ -63,13 +63,8 @@ FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := common/image-cipher.o
 
 # The following files are synced with upstream DTC.
 # Use synced versions from scripts/dtc/libfdt/.
-LIBFDT_SRCS_SYNCED := 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
-# Use U-Boot own versions from lib/libfdt/.
-LIBFDT_SRCS_UNSYNCED := fdt_region.c
-
-LIBFDT_OBJS := $(addprefix libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_SYNCED))) \
-	       $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_UNSYNCED)))
+LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \
+		fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
 
 RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
 					rsa-sign.o rsa-verify.o rsa-checksum.o \
@@ -86,6 +81,7 @@ dumpimage-mkimage-objs := aisimage.o \
 			$(FIT_OBJS-y) \
 			$(FIT_SIG_OBJS-y) \
 			$(FIT_CIPHER_OBJS-y) \
+			common/fdt_region.o \
 			common/bootm.o \
 			lib/crc32.o \
 			default_image.o \
@@ -210,7 +206,7 @@ hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
 hostprogs-$(CONFIG_RISCV) += prelink-riscv
 
 hostprogs-y += fdtgrep
-fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o
+fdtgrep-objs += $(LIBFDT_OBJS) common/fdt_region.o fdtgrep.o
 
 ifneq ($(TOOLS_ONLY),y)
 hostprogs-y += spl_size_limit
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 2/3 fdt_region: move fdt_region.c to common/ from lib/libfdt/

My goal is to sync lib/libfdt/ with scripts/dtc/libfdt/, that is, make lib/libfdt/ contain only wrapper files.

fdt_region.c was written only for U-Boot to implement the verified boot. So, this belongs to the same group as common/fdt_support.c, which is a collection of U-Boot own fdt helpers.

Move lib/libfdt/fdt_region.c to common/fdt_region.c . This is necessary only when CONFIG_(SPL_TPL_)_FIT_SIGNATURE is enabled.

---

I am resending this after two years since v1.

My previous attempt sank by this comment:
http://patchwork.ozlabs.org/project/uboot/patch/1521623017-29312-5-git-send-email-yamada.masahiro at socionext.com/#1881196

Two years have passed, but I still do not see this file in upstream DTC.

Changes in v2:
- rebase

 common/Makefile                     |  1 +
 {lib/libfdt => common}/fdt_region.c |  0
 lib/libfdt/Makefile                 |  3 ---
 tools/Makefile                      | 12 ++++--------
 4 files changed, 5 insertions(+), 11 deletions(-)
 rename {lib/libfdt => common}/fdt_region.c (100%)

Applied to u-boot-dm, thanks!

#5 lore raw

PATCH v2 3/3 libfdt: split fdt_region declarations out to <fdt_region.h>

In reply to Masahiro Yamada

fdt_region APIs are not part of libfdt. They are U-Boot extension for the verified boot. Split the declarations related to fdt_region out of <fdt_region.h>. This allows <linux/libfdt.h> to become a simple wrapper file, like Linux does.

---

I am resending this after two years since v1.

My previous attempt sank by this comment:
http://patchwork.ozlabs.org/project/uboot/patch/1521623017-29312-6-git-send-email-yamada.masahiro at socionext.com/#1881345

Two years have passed, but I still do not see such code in upstream DTC.

Changes in v2:
- Rebase

 common/fdt_region.c    |   1 +
 common/image-fit-sig.c |   1 +
 include/fdt_region.h   | 304 +++++++++++++++++++++++++++++++++++++++++
 include/linux/libfdt.h | 299 ----------------------------------------
 tools/fdtgrep.c        |   1 +
 tools/image-host.c     |   1 +
 6 files changed, 308 insertions(+), 299 deletions(-)
 create mode 100644 include/fdt_region.h
common/fdt_region.c +1 -0
index 7e9fa9272e..bf0a9be730 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/libfdt_env.h>
+#include <fdt_region.h>
 
 #ifndef USE_HOSTCC
 #include <fdt.h>
common/image-fit-sig.c +1 -0
index f6caeb0c59..64a181266e 100644
@@ -11,6 +11,7 @@
 #include <malloc.h>
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
+#include <fdt_region.h>
 #include <image.h>
 #include <u-boot/rsa.h>
 #include <u-boot/rsa-checksum.h>
include/fdt_region.h new file +304 -0

304 lines not on this page · raw message

include/linux/libfdt.h +0 -299

305 lines not on this page · raw message

tools/fdtgrep.c +1 -0
index 2a8058f57f..7e168a1e6b 100644
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fdt_region.h>
 
 #include "fdt_host.h"
 #include "libfdt_internal.h"
tools/image-host.c +1 -0
index 76a361b9d6..1b4bc0eb58 100644
@@ -10,6 +10,7 @@
 
 #include "mkimage.h"
 #include <bootm.h>
+#include <fdt_region.h>
 #include <image.h>
 #include <version.h>
 
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 3/3 libfdt: split fdt_region declarations out to <fdt_region.h>

fdt_region APIs are not part of libfdt. They are U-Boot extension for the verified boot. Split the declarations related to fdt_region out of <fdt_region.h>. This allows <linux/libfdt.h> to become a simple wrapper file, like Linux does.

---

I am resending this after two years since v1.

My previous attempt sank by this comment:
http://patchwork.ozlabs.org/project/uboot/patch/1521623017-29312-6-git-send-email-yamada.masahiro at socionext.com/#1881345

Two years have passed, but I still do not see such code in upstream DTC.

Changes in v2:
- Rebase

 common/fdt_region.c    |   1 +
 common/image-fit-sig.c |   1 +
 include/fdt_region.h   | 304 +++++++++++++++++++++++++++++++++++++++++
 include/linux/libfdt.h | 299 ----------------------------------------
 tools/fdtgrep.c        |   1 +
 tools/image-host.c     |   1 +
 6 files changed, 308 insertions(+), 299 deletions(-)
 create mode 100644 include/fdt_region.h

Applied to u-boot-dm, thanks!