build: add libfdt

This commit is contained in:
xvanc 2024-05-30 10:41:45 -05:00
parent 45fb3ded6f
commit 1ebeb06570
No known key found for this signature in database
7 changed files with 234 additions and 1 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
/limine-efi
/freestanding-headers
/common/flanterm
/common/libfdt
/common/lib/stb_image.h
/common/cc-runtime
/decompressor/tinf

View File

@ -337,7 +337,7 @@ distclean: clean
.PHONY: maintainer-clean
maintainer-clean: distclean
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/flanterm common/lib/stb_image.h decompressor/tinf tinf stb freestanding-headers common/cc-runtime decompressor/cc-runtime limine-efi configure timestamps build-aux *'~' autom4te.cache aclocal.m4 *.tar*
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/flanterm common/libfdt common/lib/stb_image.h decompressor/tinf tinf stb freestanding-headers common/cc-runtime decompressor/cc-runtime limine-efi configure timestamps build-aux *'~' autom4te.cache aclocal.m4 *.tar*
.PHONY: common-uefi-x86-64
common-uefi-x86-64:

View File

@ -154,6 +154,8 @@ Limine uses a stripped-down version of [tinf](https://github.com/jibsen/tinf) fo
Limine relies on [stb_image](https://github.com/nothings/stb/blob/master/stb_image.h) for runtime GZIP decompression and image loading.
Limine uses a patched version of libfdt (can be found in Linux's source tree) for manipulating FDTs.
## Discord server
We have a [Discord server](https://discord.gg/QEeZMz4) if you need support,
info, or you just want to hang out with us.

View File

@ -64,6 +64,13 @@ if ! [ -f version ]; then
cp stb/stb_image.h common/lib/
patch -p0 < common/stb_image.patch
rm -f common/lib/stb_image.h.orig
curl -Lo dtc-1.7.0.tar.xz https://mirrors.edge.kernel.org/pub/software/utils/dtc/dtc-1.7.0.tar.xz
tar -xf dtc-1.7.0.tar.xz
mv dtc-1.7.0/libfdt/ common/libfdt
rm -rf dtc-1.7.0 dtc-1.7.0.tar.xz
find common/libfdt/ -type f -not -name '*.c' -not -name '*.h' -delete
patch -p1 < common/libfdt.patch
fi
# Create timestamps file

View File

@ -18,10 +18,14 @@ void *memset(void *, int, size_t);
void *memcpy(void *, const void *, size_t);
int memcmp(const void *, const void *, size_t);
void *memmove(void *, const void *, size_t);
void *memchr(const void *, int, size_t);
char *strcpy(char *, const char *);
char *strncpy(char *, const char *, size_t);
char *strchr(const char *, int);
char *strrchr(const char *, int);
size_t strlen(const char *);
size_t strnlen(const char *, size_t);
int strcmp(const char *, const char *);
int strcasecmp(const char *, const char *);
int strncmp(const char *, const char *, size_t);

View File

@ -112,6 +112,48 @@ size_t strlen(const char *str) {
return len;
}
size_t strnlen(const char *str, size_t maxlen) {
size_t len;
for (len = 0; len < maxlen && str[len]; len++);
return len;
}
void *memchr(const void *ptr, int ch, size_t n) {
uint8_t *p = (uint8_t *)ptr;
for (size_t i = 0; i < n; i++) {
if (p[i] == ch) {
return (void *)ptr + i;
}
}
return NULL;
}
char *strchr(const char *str, int ch) {
for (size_t i = 0; str[i]; i++) {
if (str[i] == ch) {
return (char *)str + i;
}
}
return NULL;
}
char *strrchr(const char *str, int ch) {
char *p = NULL;
for (size_t i = 0; str[i]; i++) {
if (str[i] == ch) {
p = (char *)str + i;
}
}
return p;
}
int inet_pton(const char *src, void *dst) {
uint8_t array[4];
const char *current = src;

177
common/libfdt.patch Normal file
View File

@ -0,0 +1,177 @@
--- a/common/libfdt/fdt.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_addresses.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_addresses.c 2023-11-27 14:45:52.372043771 +0100
@@ -6,8 +6,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_check.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_check.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_empty_tree.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_empty_tree.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_overlay.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_overlay.c 2023-11-27 14:45:52.372043771 +0100
@@ -6,8 +6,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
@@ -461,7 +461,7 @@
if (!name_len)
return -FDT_ERR_BADOVERLAY;
- poffset = strtoul(sep + 1, &endptr, 10);
+ poffset = strtoui(sep + 1, (const char **)&endptr, 10);
if ((*endptr != '\0') || (endptr <= (sep + 1)))
return -FDT_ERR_BADOVERLAY;
--- a/common/libfdt/fdt_ro.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_ro.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_rw.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_rw.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_strerror.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_strerror.c 2023-11-27 14:45:52.372043771 +0100
@@ -6,8 +6,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_sw.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_sw.c 2023-11-27 14:45:52.372043771 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/fdt_wip.c 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/fdt_wip.c 2023-11-27 14:45:52.375377052 +0100
@@ -5,8 +5,8 @@
*/
#include "libfdt_env.h"
-#include <fdt.h>
-#include <libfdt.h>
+#include "fdt.h"
+#include "libfdt.h"
#include "libfdt_internal.h"
--- a/common/libfdt/libfdt.h 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/libfdt.h 2023-11-27 14:45:52.375377052 +0100
@@ -6,8 +6,8 @@
* Copyright (C) 2006 David Gibson, IBM Corporation.
*/
-#include <libfdt_env.h>
-#include <fdt.h>
+#include "libfdt_env.h"
+#include "fdt.h"
#ifdef __cplusplus
extern "C" {
--- a/common/libfdt/libfdt_env.h 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/libfdt_env.h 2023-11-27 14:45:52.375377052 +0100
@@ -10,9 +10,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
#include <limits.h>
+#include <lib/libc.h>
+#include <lib/misc.h>
#ifdef __CHECKER__
#define FDT_FORCE __attribute__((force))
--- a/common/libfdt/libfdt_internal.h 2023-02-09 11:01:35.000000000 +0100
+++ b/common/libfdt/libfdt_internal.h 2023-11-27 14:45:52.375377052 +0100
@@ -5,7 +5,7 @@
* libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation.
*/
-#include <fdt.h>
+#include "fdt.h"
#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))