Commit Graph

21 Commits

Author SHA1 Message Date
Ivaylo Ivanov
04a3e00bd3 drivers: introduce probe-based driver framework
The current drivers/framework.c is useless, as REGISTER_DRIVER() is a macro
that just directly calls the driver probe function. Every board file has to
reference each driver's probe function by name. This was just done to make room
for proper driver probing in the future, where we are now, so implement that.

Make drivers self-register at link time by emitting a struct driver into a
.uniloader_drivers section via DRIVER_REGISTER(). The linker brackets
the section with __drivers_start / __drivers_end symbols.

Boards describe their hardware as a static struct with the format
{ driver_name, plat_data, label }. Remove the drivers_init hook from
struct board_ops as it's no longer necessary.

The drivers probe will now be placed between early_init and splash.
The framework looks up each device's driver_name up in the
linker section and calls probe(plat_data). A failed probe is logged.

Do --whole-archive as well to convince the linker to not drop the drivers
in archived .o files that aren't called outside the archive.

Adopt all boards to use the framework.

All of the changes in this commit are co-dependent on each other, as we're
doing a large change to the ABI.
2026-05-28 00:02:41 +03:00
Ivaylo Ivanov
b2a3304179 arch: discard runtime-unused metadata sections
The toolchain emits several sections that have no meaning for a flat
binary bootloader:

  .eh_frame             DWARF unwind tables (we never unwind)
  .note.gnu.property    BTI/PAC ELF markers (lost at objcopy)
  .note.gnu.build-id    debug identity (lost at objcopy)
  .comment              compiler version string
  .ARM.attributes       ABI metadata

Gcc emits roughly 7-8 KB of .eh_frame by default for a build of this
size; the others are smaller but equally pointless. Just drop all of
them in the linker scripts.

Net effect on dreamlte_defconfig w/ empty embedded blobs:
61960 -> ~54000 bytes. Stonks.
2026-05-28 00:01:44 +03:00
Ivaylo Ivanov
89ead8a57a arch: aarch64: align .{rodata,data,bss} to 8 bytes
ALIGN(4) is left over from 32-bit linker script templates. On
aarch64 the natural pointer/long alignment is 8, and these sections
usually contain 64-bit constants (pointer tables, 64-bit literals). The
4-byte alignment was harmless because the linker happens to align
individual symbols anyway, but let's just align it properly for the
sake of correctness. For BSS also ensure we have extra padding before
the end of the section.
2026-05-28 00:00:29 +03:00
Ivaylo Ivanov
56f8caa1fa arch: aarch64: Fix up the Linux kernel image header
The current header implementation is incomplete: the text_offset and
image_size slots are overlaid with internal relocation metadata
(_rel_stack_base / _rel_stack_size), and the flags field is zero,
which makes some bootloaders unhappy. Fill up the the missing props and
while at it, stub out the image header into a header file to avoid duplicating.

image_size is computed in the linker script as _stack_end - _start
so the early stack page is included in the runtime memory footprint
advertised to the previous-stage bootloader.

Patch inspired by work from @Trijal08 and cleaned up to not account for
ELF PiE.
2026-05-27 17:26:32 +02:00
Akari Tsuyukusa
055ec0fab5 project: Add Clang/LLVM support
Makefile:
Add Clang/LLVM toolchain support

README.md:
Add Clang/LLVM build examples

start.S:
Fix compile error in Clang

```
  AS      arch/aarch64/start.o
/tmp/start-ebf313.s:22:9: error: invalid fixup for movz/movk instruction
 mov x1,_start
        ^
make[1]: *** [scripts/Makefile.build:194: arch/aarch64/start.o] Error 1
```

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
2026-05-24 10:10:37 +02:00
Igor Belwon
9a03aa6395 arch: Add architecture-dependent kernel copying functions
This is done to clean main/ code of ugly architecture ifdefs.

Signed-off-by: Igor Belwon <igor.belwon@mentallysanemainliners.org>
2026-02-23 23:02:53 +02:00
tildeguy
88cc20b0d6 project: allow not to load ramdisk but only its size
HiSilicon bootloader copies the ramdisk itself, and marks
its memory region as protected, so we can't memcpy on it.
Even more: we also can NOT include the ramdisk into uniLoader
for it, because the kernel partition is too small.

The easiest workaround for that is just using an empty
blob/ramdisk, so it won't be copied. But it breaks
libfdt, as it doesn't know the actual ramdisk size.
2026-02-21 11:16:21 +01:00
R0rt1z2
741f3e6a61 arch: zero BSS section during early boot
The C runtime requires that uninitialized global variables are zero.
In a bare-metal environment, memory contents are undefined at startup
and the BSS section is not automatically cleared, so we must zero out
this entire section ourselves.

Without this, static variables contain garbage values, leading to
unpredictable behavior. For example, the simplefb driver uses a static
variable to track the current print position, which resulted in text
being drawn at random locations on the screen.
2026-01-13 14:06:09 +02:00
Ivaylo Ivanov
3472279d6f aarch64: guard reloc's linux header with CONFIG_LINUX_KRNL_HEADER_IMG
Boards can enable it where needed.
2025-07-23 10:45:03 +03:00
Ivaylo Ivanov
be87eecf40 aarch64: add an option to append a linux kernel image header for no-PiC 2025-07-23 10:37:48 +03:00
Ivaylo Ivanov
c6b486f0ed aarch64: introduce early relocation of the bootloader
All newer exynos devices with s-boot have the "feature" of placing the
android kernel at a random location in dram, specifically around
0x80000000 and 0x83000000. This made it hard to assume where we are at,
hence why we made everything as PiE (position-independent) as possible.

This, however, resulted in a lot of issues. I usually managed to get
around them with ugly hacks, but in the last 5-6 commits, with the
fixed support for armv7, everything fell apart for arm64.

So, the solution for this is to implement code at the beginning
of the bootloader that relocates it to a safe place in memory.
This is currently enabled for dreamlte, and it must be enabled
and configured for all other boards with that issue. Otherwise they
will NOT boot anymore. Boards that don't need this can keep
CONFIG_POSITION_INDEPENDENT disabled.
2025-07-10 15:58:45 +03:00
Ivaylo Ivanov
4763355d48 aarch64: drop hardcoding start.o in favor of having a text section
This resolves the current compiling issue of multiple definitions,
since arch/built-in.o is included in makefile.
2025-07-09 11:42:19 +03:00
Ivaylo Ivanov
0008ecfa60 arch: use per-arch makefile instead of hardcoding in the root one
At some point building for arm32 was broken, because the assumption
of an assembly memcpy existing was made. It, however, did not exist
for arm32, only arm64, hence build failing. Avoid this.
2025-07-08 18:07:32 +03:00
Ivaylo Ivanov
8dc27cc402 board: introduce Amazon Kindle PW3 support
With support for this board also come the following changes:
- rework blobs handling to get past the 0 size bug
- basic cpu "set up" in start.S
- assembly memcpy
- uart debugging
2025-07-08 15:54:02 +03:00
Ivaylo Ivanov
9c60b66f71 AARCH64: Allow for embedding an initramfs
This actually breaks the armv7 port. It has to be revisited in the
future, since it not only is not compilable right now, but also
cannot boot linux properly. TODO

Also introduce a new C-based __memcpy_optimized that does not
cause an exception on some devices when copying the initramfs.
This issue has to be debugged further.

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2024-10-12 19:43:05 +03:00
Ivaylo Ivanov
784bfd609a lib: unic: Optimize memcpy and memset for aarch64
Move onto using asmdefs macros in assembly files. Implement an
assembly-based memcpy for aarch64 and a C-optimized memset, while
also making place for replacing functions with more optimized ones
in the future.

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2024-10-09 18:49:23 +03:00
Ivaylo Ivanov
81d26edaa3 uniLoader: Mass rework
arch: aarch64: Load addresses via page + offset
arch: aarch64: Align the TEXT region
drivers: Introduce an empty framework
board: Rework to be PIC

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2024-10-08 21:22:21 +03:00
Ivaylo Ivanov
54d3d93a92 arch: aarch64: Set up Stack Pointer
Introduce stack and bss memory regions, rename Start.S to start.S
This commit should allow jumping out of assembly code for certain
SoCs that had issues with SP like MTK and QCOM.

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2024-08-06 19:23:47 +03:00
Ivaylo Ivanov
b37e225721 arch: arm: Implement TEXT_BASE instead of using a hardcoded address
This was an issue for other armv7 boards that have slightly different
addresses till now. This also allows to start working on relocation
in the near future for both armv7 and aarch64.

While we're at it, fix some mistakes here and there.

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2024-08-06 11:12:31 +03:00
Ivaylo Ivanov
ed98b5d900 .: Multiple changes
arch: Implement ARM32 support
soc: Implement ARM32 support for MSM8916
board: Implement ARM32 support for Samsung Galaxy J5 2015
include: main: Revert built-in memcpy, rearrange and add support for writel
lib: simplefb: Make the clear screen function usable

Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
Cc: Efim Girjeu <efimgirjeu@gmail.com>
2023-07-18 14:41:37 +03:00
ivoszbg
7ce00a6ed2 main: Move assembly code into an individual arch-specific folder
Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
2022-06-16 14:40:28 +03:00