From 74dddfe92bd4ed8a871da29797923fcc9def482b Mon Sep 17 00:00:00 2001 From: liaoao Date: Mon, 31 Jul 2023 21:51:39 +0800 Subject: [PATCH] fdt: add libfdt support Signed-off-by: liaoao --- libs/libc/.gitignore | 2 ++ libs/libc/Kconfig | 1 + libs/libc/Makefile | 1 + libs/libc/fdt/CMakeLists.txt | 44 ++++++++++++++++++++++++++ libs/libc/fdt/Kconfig | 20 ++++++++++++ libs/libc/fdt/Make.defs | 60 ++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 libs/libc/fdt/CMakeLists.txt create mode 100644 libs/libc/fdt/Kconfig create mode 100644 libs/libc/fdt/Make.defs diff --git a/libs/libc/.gitignore b/libs/libc/.gitignore index 2f99ba5919..355c8b8ed6 100644 --- a/libs/libc/.gitignore +++ b/libs/libc/.gitignore @@ -1,2 +1,4 @@ /exec_symtab.c /modlib_symtab.c +/dtc +/dtc.zip diff --git a/libs/libc/Kconfig b/libs/libc/Kconfig index e8a220fe4b..3c15475ead 100644 --- a/libs/libc/Kconfig +++ b/libs/libc/Kconfig @@ -32,3 +32,4 @@ source "libs/libc/symtab/Kconfig" source "libs/libc/stream/Kconfig" source "libs/libc/regex/Kconfig" source "libs/libc/gpsutils/Kconfig" +source "libs/libc/fdt/Kconfig" diff --git a/libs/libc/Makefile b/libs/libc/Makefile index b18f91c36c..42d9f4c3e8 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -68,6 +68,7 @@ include uuid/Make.defs include wchar/Make.defs include wctype/Make.defs include wqueue/Make.defs +include fdt/Make.defs # Use double delim to fix windows native build and give an error: # makefile:132: *** target mode do not include“%”. stop. diff --git a/libs/libc/fdt/CMakeLists.txt b/libs/libc/fdt/CMakeLists.txt new file mode 100644 index 0000000000..1a2d39d068 --- /dev/null +++ b/libs/libc/fdt/CMakeLists.txt @@ -0,0 +1,44 @@ +# ############################################################################## +# libs/libc/fdt/CMakeLists.txt +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## +if(CONFIG_LIBFDT) + + set(VERSION CONFIG_LIBFDT_DTC_VERSION) + + FetchContent_Declare( + dtc URL https://github.com/dgibson/dtc/archive/v$(VERSION).zip) + FetchContent_Populate(dtc) + FetchContent_GetProperties(dtc) + + set(SRCS + 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_check.c) + list(TRANSFORM SRCS PREPEND ${dtc_SOURCE_DIR}/libfdt/) + target_sources(c PRIVATE ${SRCS}) + + target_include_directories(c PRIVATE ${dtc_SOURCE_DIR}/libfdt) +endif() diff --git a/libs/libc/fdt/Kconfig b/libs/libc/fdt/Kconfig new file mode 100644 index 0000000000..e0a62e2881 --- /dev/null +++ b/libs/libc/fdt/Kconfig @@ -0,0 +1,20 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIBFDT + bool "Flattened Device Tree Library" + default n + ---help--- + Enable or disable Flattened Device Tree Library features. + +if LIBFDT + +config LIBFDT_DTC_VERSION + string "LIBFDT DTC Version" + default "1.7.0" + ---help--- + Version of DTC source code to download from github. + +endif # LIBFDT diff --git a/libs/libc/fdt/Make.defs b/libs/libc/fdt/Make.defs new file mode 100644 index 0000000000..78502c741b --- /dev/null +++ b/libs/libc/fdt/Make.defs @@ -0,0 +1,60 @@ +############################################################################ +# libs/libc/fdt/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifeq ($(CONFIG_LIBFDT),y) + +VERSION=$(CONFIG_LIBFDT_DTC_VERSION) + +# Download and unpack tarball if no git repo found +ifeq ($(wildcard dtc/.git),) +dtc: + $(call DOWNLOAD,https://github.com/dgibson/dtc/archive,v$(VERSION).zip,dtc.zip) + $(Q) unzip -o dtc.zip + $(Q) mv dtc-$(VERSION) dtc +else +dtc: +endif + +context:: dtc + +CSRCS += fdt.c +CSRCS += fdt_ro.c +CSRCS += fdt_wip.c +CSRCS += fdt_sw.c +CSRCS += fdt_rw.c +CSRCS += fdt_strerror.c +CSRCS += fdt_empty_tree.c +CSRCS += fdt_addresses.c +CSRCS += fdt_overlay.c +CSRCS += fdt_check.c + +CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)dtc$(DELIM)libfdt$(DELIM) + +VPATH += dtc/libfdt +SUBDIRS += dtc/libfdt +DEPPATH += --dep-path dtc/libfdt + +distclean:: +ifeq ($(wildcard dtc/.git),) + $(call DELDIR, dtc) + $(call DELFILE, dtc.zip) +endif + +endif