diff --git a/.gitignore b/.gitignore index d33a3c1e..cf494e93 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /limine-efi /freestanding-headers /common/flanterm +/common/libfdt /common/lib/stb_image.h /common/cc-runtime /decompressor/tinf diff --git a/GNUmakefile.in b/GNUmakefile.in index a589e0cd..2cdcb1fb 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -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: diff --git a/README.md b/README.md index e6c25048..7e72f097 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bootstrap b/bootstrap index 6bca6db9..7b2b26b6 100755 --- a/bootstrap +++ b/bootstrap @@ -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 diff --git a/common/lib/libc.h b/common/lib/libc.h index 57e0d39e..66b9a950 100644 --- a/common/lib/libc.h +++ b/common/lib/libc.h @@ -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); diff --git a/common/lib/libc.s2.c b/common/lib/libc.s2.c index 11bd4461..07aefc47 100644 --- a/common/lib/libc.s2.c +++ b/common/lib/libc.s2.c @@ -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; diff --git a/common/libfdt.patch b/common/libfdt.patch new file mode 100644 index 00000000..1f754e7f --- /dev/null +++ b/common/libfdt.patch @@ -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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 +-#include ++#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 + #include + #include +-#include +-#include + #include ++#include ++#include + + #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 ++#include "fdt.h" + + #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) + #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) \ No newline at end of file