Skip to content

Commit

Permalink
Added build scripts and fixed few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pzaino committed Nov 19, 2023
1 parent a61a5b5 commit 4c3f18f
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 8 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



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
90 changes: 90 additions & 0 deletions src/dtblib/h/dtb
Original file line number Diff line number Diff line change
@@ -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_ */
Loading

0 comments on commit 4c3f18f

Please sign in to comment.