Skip to content

Commit

Permalink
Merge pull request #2 from pzaino/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pzaino authored Nov 19, 2023
2 parents 2f7385e + 4c3f18f commit e091409
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 21 deletions.
6 changes: 6 additions & 0 deletions !LibDTB/!Boot,feb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Lib DTB for RISC OS
| by Paolo Fabio Zaino 2023

IconSprites <Obey$Dir>.!Sprites
If "<LibDTB$Dir>" = "" Then Set LibDTB$Dir <Obey$Dir>
Set LibDTB$Path <LibDTB$Dir>.
6 changes: 6 additions & 0 deletions !LibDTB/!Run,feb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Lib DTB for RISC OS
| by Paolo Fabio Zaino 2023

IconSprites <Obey$Dir>.!Sprites
Set LibDTB$Dir <Obey$Dir>
Set LibDTB$Path <LibDTB$Dir>.
Binary file added !LibDTB/!Sprites,ff9
Binary file not shown.
File renamed without changes.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
*.orig
.DS_Store
ux-src/

\!LibDTB/a/**
\!LibDTB/o/**
\!LibDTB/so/**
\!LibDTB/h/**
src/**/o/**
src/**/so/**
src/**/a/**
src/**/oz/**
tests/**/o/**
tests/**/so/**
tests/**/a/**
tests/**/oz/**
51 changes: 51 additions & 0 deletions MkDDE,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
| Generic Library builder for DDE on RISC OS
| by Paolo Fabio Zaino

echo ++++++++++++++++++++++++
echo ++ Building using DDE ++
echo ++++++++++++++++++++++++

Set Build$Root <Obey$Dir>

WimpSlot -min 6144K

echo ---------------------
echo Building the Library:
echo ---------------------

Dir <Build$Root>.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 <Build$Root>.tests

Set CanRunTests$Flag 0
IfThere @.^.!LibDTB.o.dtblib Then Set CanRunTests$Flag 1
If "<CanRunTests$Flag>" = "1" Then IfThere @.MakefileDDE Then Set CanRunTests$Flag 2
If "<CanRunTests$Flag>" = "2" Then make all THROWBACK=-throwback -f MakeFileDDE

Unset CanRunTests$Flag

echo
echo ---------------------
echo

Dir <Build$Root>
6 changes: 6 additions & 0 deletions MkDDEClean,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dir <Obey$Dir>.src
WimpSlot -min 2048k
amu clean -f MakeFileDDE
stripdepnd MakeFileDDE


4 changes: 4 additions & 0 deletions MkDDEExp,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dir <Obey$Dir>
WimpSlot -min 2048K
amu export_hdrs LIBDIR=Export -f MakeFileDDE
amu export_libs LIBDIR=Export THROWBACK=-throwback -f MakeFileDDE
37 changes: 37 additions & 0 deletions MkGCC,fd7
Original file line number Diff line number Diff line change
@@ -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 <Obey$Dir>

WimpSlot -min 16384K

echo ---------------------
echo Building the Library:
echo ---------------------

Dir <Build$Root>.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 <Build$Root>.tests
make all THROWBACK=-throwback -f MakeFileGCC

echo
echo ---------------------
echo

Dir <Build$Root>
6 changes: 6 additions & 0 deletions MkGCCClean,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dir <Obey$Dir>.src
WimpSlot -min 16384K
make clean -f MakeFileGCC



37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
# DTBLib
# DTBLib: Device Tree Blob Parsing Library

This is a library for reading and parsing Device Tree Blob files. It is written in ANSI C and without Standard C Library (SCL) dependencies.
**Overview:**

The reason for writing this library is that I needed a library for parsing DTB files in a project of mine, but I couldn't find any library that was written in ANSI C and without SCL dependencies. So I decided to write my own library.
DTBLib is a specialized library designed for reading and parsing Device Tree Blob (DTB) files. Developed in strict adherence to ANSI C standards, this library is distinct for its lack of dependencies on the Standard C Library (SCL). This unique attribute makes DTBLib particularly suited for use in environments where standard library support is unavailable or undesirable.

This library is specifically written to be used in the RISC OS Kernel project, but it can be used in any other project as well as long as you understand what krnllib does and doesn't do.
**Background:**

## Features
The genesis of DTBLib was born out of a necessity encountered during a personal project. A need arose for a tool capable of parsing DTB files within the constraints of ANSI C and without relying on SCL. When existing solutions fell short of these specific requirements, the development of DTBLib was initiated to bridge this gap.

* Written in ANSI C and without SCL dependencies.
* Supports parsing DTB files.
* Supports parsing DTB files with a size of up to 4MB.
* Supports parsing DTB files with a maximum depth of 32 levels.
* Supports parsing DTB files with a maximum string length of 256 characters.
* Supports parsing DTB files with a maximum number of 65536 nodes.
**Primary Use Case:**

While the initial intention behind DTBLib was to serve as a component in the RISC OS Kernel — specifically within its Hardware Abstraction Layer (HAL) — the library's design is not exclusive to this use. Its creation was driven by an experimental endeavor to integrate DeviceTree support into RISC OS. Nevertheless, DTBLib's versatile and adaptable nature makes it a suitable choice for a wide range of projects that require DTB parsing capabilities under similar constraints.

**Considerations for Usage:**

Potential users should be aware of the following:

DTBLib is tailor-made for environments similar to the RISC OS Kernel's HAL. Its functionality aligns with the requirements and limitations of such systems.
A comprehensive understanding of the library's internal workings, particularly the functions and limitations of krnllib (the kernel library used by DTBLib), is crucial for effective utilization.
The library is distributed under the Apache License, Version 2.0, ensuring a balance between open collaboration and respect for original authorship.

**Contributions and Enhancements:**

DTBLib is open to contributions from the developer community. Enhancements, bug fixes, and adaptations for broader use are all welcome. This collaborative approach is aimed at refining the library and extending its utility to a wider range of applications.

## Building

The library is very easy to build. You just need to run the following command:

To build with GCC on RISC OS (go in the src directory):
To build with GCC on RISC OS (from the DTBLib directory):

```bash
MkGCC
```

To build with DDE on RISC OS (go in the src directory):
To build with DDE on RISC OS (from the DTBLib directory):

```bash
MkDDE
Expand All @@ -50,6 +59,8 @@ The library is very easy to use. You just need to include the header file and li
...
```

For more information, please refer to the [documentation](doc/README.md).

## License

This library is licensed under Apache License 2.0. See the [LICENSE](LICENSE) file for details.
17 changes: 17 additions & 0 deletions src/MakefileDDE
Original file line number Diff line number Diff line change
@@ -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
102 changes: 102 additions & 0 deletions src/MakefileGCC
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions src/dtblib/MakefileDDE
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/dtblib/c/dtblib → src/dtblib/c/dtb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/dtblib/c/strlib
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/

#include "krnllib.h"
// #include "strlib.h"
#include "strlib.h"

size_t str_len(const char* str) {
size_t length = 0;
Expand Down
Loading

0 comments on commit e091409

Please sign in to comment.