realtek: add rt-loader (runtime loader)

The bootloader of many Realtek switches only supports gzipped kernel images.
With limited flash space that might get critical in future versions. For better
compression allow support for compressed images. For this a new loader was
developed. Several ideas have been taken over from the existing lzma loader
but this has been enhanced to make integration simpler. What is new:

- Loader is position independent. No need to define load addresses
- Loader identifies device memory on its own
- Loader uses "official" upstream kernel lzma uncompress
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/decompress_unlzma.c
- Loader uses "official" UNMODIFIED nanoprintg that is used by several
  bare metal projects. https://github.com/charlesnicholson/nanoprintf

Compiled the loader ist just under 12KiB and during boot it will show:

rt-loader
Found RTL8380M (chip id 6275C) with 256MB
Relocate 2924240 bytes from 0x80100000 to 0x8fce0000
Extract kernel with 2900144 bytes from 0x8fce521c to 0x80100000...
Extracted kernel size is 9814907 bytes
Booting kernel from 0x80100000 ...

[    0.000000] Linux version 6.12.33 ...
[    0.000000] RTL838X model is 83806800
...

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/18397
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Markus Stockhausen
2025-06-08 12:11:37 -04:00
committed by Robert Marko
parent ba2ae60a00
commit ccbff8bbdd
11 changed files with 2603 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/*
* rt-loader header
* (c) 2025 Markus Stockhausen
*/
#ifndef _BOARD_H_
#define _BOARD_H_
unsigned int board_get_memory(void);
void board_get_system(char *buffer, int len);
void board_panic(void);
void board_putchar(int ch, void *ctx);;
#endif // _BOARD_H_

View File

@@ -0,0 +1,17 @@
/*
* rt-loader header
* (c) 2025 Markus Stockhausen
*/
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
#define KSEG0 0x80000000
#define STACK_SIZE 0x10000
#define HEAP_SIZE 0x40000
#define MEMORY_ALIGNMENT 32
#define printf(fmt, ...) npf_pprintf(board_putchar, NULL, fmt, ##__VA_ARGS__)
#define snprintf npf_snprintf
#endif // _GLOBALS_H_

View File

@@ -0,0 +1,30 @@
/*
* rt-loader header
* (c) 2025 Markus Stockhausen
*/
#ifndef _MEMORY_H_
#define _MEMORY_H_
#include <stddef.h>
#include "globals.h"
#define CACHE_HIT_INVALIDATE_I 0x10
#define CACHE_HIT_WRITEBACK_INV_D 0x15
#define ioread32(reg) (*(volatile int *)(reg))
#define iowrite32(val, reg) (*(volatile int *)(reg) = val)
void flush_cache(void *start_addr, unsigned long size);
void free(void *ptr);
void *malloc(size_t size);
int memcmp(const void *s1, const void *s2, size_t count);
void *memmove(void *dst, const void *src, size_t count);
void *memcpy(void *dst, const void *src, size_t count);
void *memset(void *dst, int value, size_t count);
size_t strlen(const char *s);
extern void *_heap_addr;
extern void *_heap_addr_max;
#endif // _MEMORY_H_

File diff suppressed because it is too large Load Diff