From 4c3f18f0c5e9f5da4c4aa737c78cc8798513597f Mon Sep 17 00:00:00 2001
From: Paolo Fabio Zaino
Date: Sun, 19 Nov 2023 18:10:36 +0000
Subject: [PATCH] Added build scripts and fixed few issues
---
!LibDTB/!Boot,feb | 6 ++
!LibDTB/!Run,feb | 6 ++
!LibDTB/!Sprites,ff9 | Bin 0 -> 1280 bytes
{src/dtblib => !LibDTB}/h/dtblib | 0
.gitignore | 13 +++-
MkDDE,fd7 | 51 +++++++++++++++
MkDDEClean,fd7 | 6 ++
MkDDEExp,fd7 | 4 ++
MkGCC,fd7 | 37 +++++++++++
MkGCCClean,fd7 | 6 ++
src/MakefileDDE | 17 +++++
src/MakefileGCC | 102 +++++++++++++++++++++++++++++
src/dtblib/MakefileDDE | 27 ++++++++
src/dtblib/c/{dtblib => dtb} | 2 +-
src/dtblib/c/strlib | 2 +-
src/dtblib/h/dtb | 90 +++++++++++++++++++++++++
src/dtblib/h/strlib | 2 +-
tests/001BasicDTBParse/MakefileDDE | 9 ++-
tests/001BasicDTBParse/c/main | 2 +-
19 files changed, 374 insertions(+), 8 deletions(-)
create mode 100644 !LibDTB/!Boot,feb
create mode 100644 !LibDTB/!Run,feb
create mode 100644 !LibDTB/!Sprites,ff9
rename {src/dtblib => !LibDTB}/h/dtblib (100%)
create mode 100644 MkDDE,fd7
create mode 100644 MkDDEClean,fd7
create mode 100644 MkDDEExp,fd7
create mode 100644 MkGCC,fd7
create mode 100644 MkGCCClean,fd7
create mode 100644 src/MakefileDDE
create mode 100644 src/MakefileGCC
create mode 100644 src/dtblib/MakefileDDE
rename src/dtblib/c/{dtblib => dtb} (99%)
create mode 100644 src/dtblib/h/dtb
diff --git a/!LibDTB/!Boot,feb b/!LibDTB/!Boot,feb
new file mode 100644
index 0000000..7109b41
--- /dev/null
+++ b/!LibDTB/!Boot,feb
@@ -0,0 +1,6 @@
+| Lib DTB for RISC OS
+| by Paolo Fabio Zaino 2023
+
+IconSprites .!Sprites
+If "" = "" Then Set LibDTB$Dir
+Set LibDTB$Path .
diff --git a/!LibDTB/!Run,feb b/!LibDTB/!Run,feb
new file mode 100644
index 0000000..3e1014c
--- /dev/null
+++ b/!LibDTB/!Run,feb
@@ -0,0 +1,6 @@
+| Lib DTB for RISC OS
+| by Paolo Fabio Zaino 2023
+
+IconSprites .!Sprites
+Set LibDTB$Dir
+Set LibDTB$Path .
diff --git a/!LibDTB/!Sprites,ff9 b/!LibDTB/!Sprites,ff9
new file mode 100644
index 0000000000000000000000000000000000000000..29a1deed80386815661b7219650a93221a7638b1
GIT binary patch
literal 1280
zcmcgq!AiqG5FN7-DQKt)UX8&^z{BAB1NG7`DBg<~K_OsD@Ydhxhj_}j^xPlNgQq%g
zvePc1RZk8~X7=rSZ)cMvL^PC44~ganL|4yG)5m%$h+vY~LmWxogggd-aKv3xf39`u
zJSFUjJ-ZGfW+vwx3sWKRC?QV{JOXPCEI-2rqJw7A1@jGrc^oJbfd$BT)d#$03Yp)k
z3{VcDMwJc9FJ%QU=aSW+EXOI%3mE5BR=zzD7h8;|X`0Sm=2b8DRWlB)0`g$0?l`|s
z<$m6#<)RpkPOop}C2TIm-VM)*1#r15a851s*O%=VI1wxhwwF@v{lCvIc(GW>&2Zsu
z8fF!H8m&}GGo-W_x)}CUm88HmDkp`It%Wi`NM3`AZ%7>
z|Dv(8P@zG}uckisP0SM&n0kk^te;FK8x62n6Zbk~c*OXw9%msfFxNiscvkD7GY{zE
idl|
+
+WimpSlot -min 6144K
+
+echo ---------------------
+echo Building the Library:
+echo ---------------------
+
+Dir .src
+amu all THROWBACK=-throwback -f MakeFileDDE
+
+up
+
+IfThere @.!LibDTB Then Else CDir @.!LibDTB
+IfThere @.!LibDTB.o Then Else CDir @.!LibDTB.o
+IfThere @.!LibDTB.a Then Else CDir @.!LibDTB.a
+IfThere @.!LibDTB.h Then Else CDir @.!LibDTB.h
+
+IFthere @.src.dtblib.o.dtblib Then copy @.src.dtblib.o.dtblib @.!LibDTB.o.dtblib ~C N
+IFthere @.src.dtblib.o.dtblibzm Then copy @.src.dtblib.o.dtblibzm @.!LibDTB.o.dtblibzm ~C N
+IFthere @.src.dtblib.h.dtb Then copy @.src.dtblib.h.dtb @.!LibDTB.h.dtblib ~C N
+
+echo
+echo ---------------------
+echo
+
+echo ---------------------
+echo Building Tests:
+echo ---------------------
+
+Dir .tests
+
+Set CanRunTests$Flag 0
+IfThere @.^.!LibDTB.o.dtblib Then Set CanRunTests$Flag 1
+If "" = "1" Then IfThere @.MakefileDDE Then Set CanRunTests$Flag 2
+If "" = "2" Then make all THROWBACK=-throwback -f MakeFileDDE
+
+Unset CanRunTests$Flag
+
+echo
+echo ---------------------
+echo
+
+Dir
diff --git a/MkDDEClean,fd7 b/MkDDEClean,fd7
new file mode 100644
index 0000000..cefdcaa
--- /dev/null
+++ b/MkDDEClean,fd7
@@ -0,0 +1,6 @@
+Dir .src
+WimpSlot -min 2048k
+amu clean -f MakeFileDDE
+stripdepnd MakeFileDDE
+
+
diff --git a/MkDDEExp,fd7 b/MkDDEExp,fd7
new file mode 100644
index 0000000..87063f1
--- /dev/null
+++ b/MkDDEExp,fd7
@@ -0,0 +1,4 @@
+Dir
+WimpSlot -min 2048K
+amu export_hdrs LIBDIR=Export -f MakeFileDDE
+amu export_libs LIBDIR=Export THROWBACK=-throwback -f MakeFileDDE
diff --git a/MkGCC,fd7 b/MkGCC,fd7
new file mode 100644
index 0000000..1da17d7
--- /dev/null
+++ b/MkGCC,fd7
@@ -0,0 +1,37 @@
+| Generic Library builder for GCC on RISC OS
+| by Paolo Fabio Zaino
+
+echo ++++++++++++++++++++++++
+echo ++ Building using GCC ++
+echo ++++++++++++++++++++++++
+
+Set Build$Root
+
+WimpSlot -min 16384K
+
+echo ---------------------
+echo Building the Library:
+echo ---------------------
+
+Dir .src
+make all THROWBACK=-throwback OS=RISC_OS -f MakeFileGCC
+
+|IFthere @.o.ezinilib Then copy @.o.libezini @.^.!LibEzINI.a.libezini ~C N
+|IFthere @.h.ezini Then copy @.h.ezini @.^.!LibEzINI.h.ezini ~C N
+
+echo
+echo ---------------------
+echo
+
+echo ---------------------
+echo Building Tests:
+echo ---------------------
+
+Dir .tests
+make all THROWBACK=-throwback -f MakeFileGCC
+
+echo
+echo ---------------------
+echo
+
+Dir
diff --git a/MkGCCClean,fd7 b/MkGCCClean,fd7
new file mode 100644
index 0000000..8e3a731
--- /dev/null
+++ b/MkGCCClean,fd7
@@ -0,0 +1,6 @@
+Dir .src
+WimpSlot -min 16384K
+make clean -f MakeFileGCC
+
+
+
diff --git a/src/MakefileDDE b/src/MakefileDDE
new file mode 100644
index 0000000..6087c70
--- /dev/null
+++ b/src/MakefileDDE
@@ -0,0 +1,17 @@
+# Master Makefile
+
+OBJS=dtblib
+
+.PHONY: $(OBJS)
+$(OBJS):
+ dir @.$@
+ amu all_libs THROWBACK=-throwback -f MakefileDDE
+ up
+
+.PHONY: all
+all: $(OBJS)
+
+.PHONY: clean
+clean:
+# dir @.$<
+# @.MkCleanDDE
diff --git a/src/MakefileGCC b/src/MakefileGCC
new file mode 100644
index 0000000..7be3403
--- /dev/null
+++ b/src/MakefileGCC
@@ -0,0 +1,102 @@
+# Variables
+ifeq ($(OS),)
+ OS := RISC_OS
+endif
+
+# Set variables based on the detected OS
+ifeq ($(OS),Linux)
+ CD_CMD = cd
+ RM_CMD = rm -f
+ DIR_SYM =/
+ LOCAL_DIR=.
+ UP_DIR=..
+ EXT_SYM =.
+ MAKE_FLAGS = -j4
+else ifeq ($(OS),Darwin) # macOS
+ CD_CMD = cd
+ RM_CMD = rm -f
+ DIR_SYM =/
+ LOCAL_DIR=.
+ UP_DIR=..
+ EXT_SYM =.
+ MAKE_FLAGS = -j4
+else ifeq ($(OS),Windows)
+ CD_CMD = cd
+ RM_CMD = del
+ DIR_SYM =/
+ LOCAL_DIR=.
+ UP_DIR=..
+ EXT_SYM =.
+ MAKE_FLAGS = -j4
+else ifeq ($(OS),RISC_OS)
+ CD_CMD = cdir
+ RM_CMD = remove
+ DIR_SYM =.
+ LOCAL_DIR=@
+ UP_DIR=^
+ EXT_SYM =/
+ MAKE_FLAGS = -mthrowback
+else
+ $(error Unknown operating system: $(UNAME))
+endif
+
+CC = gcc
+MAKE = make
+
+LIB_DIR = libs
+# If needed add more libraries in the following format:
+# LIBS = $(LIB_DIR)$(DIR_SYM)lib1 $(LIB_DIR)$(DIR_SYM)lib2 $(LIB_DIR)$(DIR_SYM)lib3
+LIBS =
+LIB_NAME = DTBLib
+MAIN_DIR = DTBLib
+MAIN_LIB = $(LIB_NAME)
+ifeq ($(OS),RISC_OS)
+ MAIN_SRC = c.$(LIB_NAME)
+ MAIN_OBJ = o.$(LIB_NAME)
+else
+ MAIN_SRC = $(LIB_NAME).c
+ MAIN_OBJ = $(LIB_NAME).o
+endif
+
+# Setup CFLAGS
+CFLAGS = -Wall -Wextra -pedantic
+CFLAGS += -ansi -std=c99 -Wno-gnu-label-as-value
+# reduce code size:
+#CFLAGS += -Os -ffunction-sections -fdata-sections -flto
+# compile for maximum speed
+CFLAGS += -Ofast -fno-stack-protector -fno-strict-aliasing -fomit-frame-pointer -flto
+#LDFLAGS += -Wl,--gc-sections
+LDFLAGS += -flto
+
+# Add -I flags for each library to CFLAGS
+CFLAGS += -I$(LIB_DIR) $(foreach dir,$(LIBS),-I$(dir) -I$(dir)$(DIR_SYM)src)
+
+# Targets
+all: $(MAIN_LIB)
+
+# Building the main application
+$(MAIN_LIB): libs
+ $(MAKE) -C $(LOCAL_DIR)$(DIR_SYM)$(MAIN_DIR) all OS=$(OS) -f MakefileGCC
+
+# Building the libraries by invoking their own Makefiles
+libs: $(LIBS)
+
+$(LIBS):
+ $(MAKE) -C $(LOCAL_DIR)$(DIR_SYM)$@$(DIR_SYM)src all OS=$(OS) -f MakefileGCC
+
+# To initialize and update git submodules
+init-submodules:
+ git submodule init
+ git submodule update
+
+# Clean up
+clean:
+ $(RM_CMD) $(MAIN_LIB)
+ for dir in $(LIBS); do \
+ ($(CD_CMD) $$dir && $(MAKE) clean OS=$(OS) -f MakefileGCC); \
+ done
+
+# To force rebuild everything
+rebuild: clean all
+
+.PHONY: all clean rebuild init-submodules libs $(LIBS)
diff --git a/src/dtblib/MakefileDDE b/src/dtblib/MakefileDDE
new file mode 100644
index 0000000..77e0f8a
--- /dev/null
+++ b/src/dtblib/MakefileDDE
@@ -0,0 +1,27 @@
+# Makefile for dtblib
+
+COMPONENT = dtblib
+OBJS = krnllib strlib dtb
+
+include CLibrary
+LIBS =
+#LDFLAGS = -bin
+
+# Dynamic dependencies:
+
+oz.dtb: c.dtb
+oz.dtb: h.krnllib
+oz.dtb: h.strlib
+oz.dtb: h.krnllib
+oz.dtb: h.dtb
+o.krnllib: c.krnllib
+o.krnllib: h.krnllib
+o.strlib: c.strlib
+o.strlib: h.krnllib
+o.strlib: h.strlib
+o.strlib: h.krnllib
+o.dtb: c.dtb
+o.dtb: h.krnllib
+o.dtb: h.strlib
+o.dtb: h.krnllib
+o.dtb: h.dtb
diff --git a/src/dtblib/c/dtblib b/src/dtblib/c/dtb
similarity index 99%
rename from src/dtblib/c/dtblib
rename to src/dtblib/c/dtb
index fbc823b..121aeba 100644
--- a/src/dtblib/c/dtblib
+++ b/src/dtblib/c/dtb
@@ -54,7 +54,7 @@
#include "krnllib.h"
#include "strlib.h"
-#include "dtblib.h"
+#include "dtb.h"
static void free_tree(struct dt_node* node) {
if (node == NULL) return;
diff --git a/src/dtblib/c/strlib b/src/dtblib/c/strlib
index f288865..9d7577b 100644
--- a/src/dtblib/c/strlib
+++ b/src/dtblib/c/strlib
@@ -53,7 +53,7 @@
*/
#include "krnllib.h"
-// #include "strlib.h"
+#include "strlib.h"
size_t str_len(const char* str) {
size_t length = 0;
diff --git a/src/dtblib/h/dtb b/src/dtblib/h/dtb
new file mode 100644
index 0000000..0e61d9b
--- /dev/null
+++ b/src/dtblib/h/dtb
@@ -0,0 +1,90 @@
+/*
+ * DTBLib: Device Tree Blob Parsing Library
+ *
+ * Copyright (c) 2023 by Paolo Fabio Zaino, all rights reserved.
+ *
+ * Licensed 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.
+ *
+ * Limitations:
+ * - Redistribution and use of this software in source and binary
+ * forms, with or without modification, are permitted provided that
+ * the following conditions are met:
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions, and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ * - Neither the name of Paolo Fabio Zaino, nor the names
+ * of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ * - Users of this software are prohibited from misrepresenting
+ * themselves as the authors or original contributors of this
+ * software.
+ *
+ * This software is provided by the copyright holders and contributors
+ * "as is" and any express or implied warranties, including, but not
+ * limited to, the implied warranties of merchantability and fitness
+ * for a particular purpose are disclaimed. In no event shall the
+ * copyright owner or contributors be liable for any direct,
+ * indirect, incidental, special, exemplary, or consequential damages
+ * (including, but not limited to, procurement of substitute goods or
+ * services; loss of use, data, or profits; or business interruption)
+ * however caused and on any theory of liability, whether in
+ * contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software,
+ * even if advised of the possibility of such damage.
+ *
+ * For more details and the full text of the license, refer to the
+ * Apache 2.0 License file included with this project or available at
+ * the above URL.
+ */
+
+#ifndef DTBLIB_H_
+#define DTBLIB_H_
+
+#define FDT_MAGIC 0xd00dfeed
+#define FDT_BEGIN_NODE 1
+#define FDT_END_NODE 2
+#define FDT_PROP 3
+#define FDT_NOP 4
+#define FDT_END 9
+
+#define MIN_DTB_VERSION 1
+#define MAX_DTB_VERSION 17
+
+struct dt_node {
+ char* name; // Name of the node
+ struct dt_property* props; // Pointer to the first property of the node
+ int prop_count; // Count of properties in the node
+ struct dt_node* parent; // Pointer to the parent node (NULL for root)
+ struct dt_node* children; // Pointer to the first child node
+ struct dt_node* next_sibling; // Pointer to the next sibling node
+};
+
+struct dt_property {
+ char* name; // Name of the property
+ void* value; // Pointer to the value of the property
+ unsigned int size; // Size of the value in bytes
+ struct dt_property* next; // Pointer to the next property
+};
+
+struct dt_node* parse_dtb(
+ const char* dtb_data,
+ const char* strings_block,
+ int offset
+);
+
+#endif /* DTBLIB_H_ */
diff --git a/src/dtblib/h/strlib b/src/dtblib/h/strlib
index 31bcff1..ba2952f 100644
--- a/src/dtblib/h/strlib
+++ b/src/dtblib/h/strlib
@@ -58,6 +58,6 @@
#include "krnllib.h"
size_t str_len(const char* str);
-char* str_read(const char* data, int offset);
+char* str_read(const char* data, int offset);
#endif /* STRLIB_H_ */
diff --git a/tests/001BasicDTBParse/MakefileDDE b/tests/001BasicDTBParse/MakefileDDE
index 77ca8d0..b2b2fb9 100644
--- a/tests/001BasicDTBParse/MakefileDDE
+++ b/tests/001BasicDTBParse/MakefileDDE
@@ -1,10 +1,13 @@
-# Makefile for utilHelloWorld
+# Makefile for test
-COMPONENT = utilHW
+COMPONENT = BasicDTBParse
OBJS = main
include CUtil
-UTIL_LIBS = LibuCLib:o.entry LibuCLib:o.uCLib
+UTIL_LIBS = LibDTB:o.dtblib
LDFLAGS = -util
# Dynamic dependencies:
+
+o.main: c.main
+o.main: LibDTB:h.dtblib
diff --git a/tests/001BasicDTBParse/c/main b/tests/001BasicDTBParse/c/main
index 400043d..c37249b 100644
--- a/tests/001BasicDTBParse/c/main
+++ b/tests/001BasicDTBParse/c/main
@@ -3,7 +3,7 @@
#include
-#include "dtblib.h"
+#include "LibDTB:dtblib.h"
void test_simple_dtb() {
const char* simple_dtb = load_dtb("simple.dtb"); // Function to load a DTB file