drivers: introduce ramdisk-handler (adds linux,initrd-start/end at boot time)
This commit is contained in:
1 parent
f4a3e966b5
commit
266fb485dd
5 files changed
+87
No files matched your search
@@ -1,4 +1,5 @@
|
||||
# the drivers registration framework
|
||||
lib-y += framework.o
|
||||
lib-y += ramdisk-handler.o
|
||||
lib-y += samsung/exynos-speedy.o
|
||||
lib-y += samsung/exynos-acpm.o
|
||||
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2025, Victor Paul <vipollmail@gmail.com>
|
||||
*/
|
||||
|
||||
#include <drivers/ramdisk-handler.h>
|
||||
#include <lib/debug.h>
|
||||
#include <lib/libfdt/libfdt.h>
|
||||
|
||||
int ramdisk_handler_patch_dtb(const void *fdt, void *buf, int bufsize)
|
||||
{
|
||||
int ret, dtb_chosen_offset;
|
||||
void *ramdisk_end = (void*)CONFIG_RAMDISK_ENTRY + (unsigned long)&ramdisk_size;
|
||||
|
||||
printk(KERN_INFO, "trying to open fdt...\n");
|
||||
ret = fdt_open_into(fdt, buf, bufsize);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR, "fdt_open_into() failed: %s\n", fdt_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
dtb_chosen_offset = fdt_path_offset(buf, "/chosen");
|
||||
if (dtb_chosen_offset < 0) {
|
||||
printk(KERN_ERR, "Could not find /chosen node: %s\n", fdt_strerror(dtb_chosen_offset));
|
||||
return dtb_chosen_offset;
|
||||
}
|
||||
|
||||
printk(KERN_INFO, "adding linux,initrd-start...\n");
|
||||
#ifdef __aarch64__
|
||||
ret = fdt_setprop_u64(buf, dtb_chosen_offset, "linux,initrd-start", (uint64_t)CONFIG_RAMDISK_ENTRY);
|
||||
#elif __arm__
|
||||
ret = fdt_setprop_u32(buf, dtb_chosen_offset, "linux,initrd-start", (uint32_t)CONFIG_RAMDISK_ENTRY);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR, "failed to add linux,initrd-start: %s\n", fdt_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
printk(KERN_INFO, "adding linux,initrd-end...\n");
|
||||
#ifdef __aarch64__
|
||||
ret = fdt_setprop_u64(buf, dtb_chosen_offset, "linux,initrd-end", (uint64_t)ramdisk_end);
|
||||
#elif __arm__
|
||||
ret = fdt_setprop_u32(buf, dtb_chosen_offset, "linux,initrd-end", (uint32_t)ramdisk_end);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR, "failed to add linux,initrd-end: %s\n", fdt_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2025, Victor Paul <vipollmail@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef RAMDISK_HANDLER_H_ /* Include guard */
|
||||
#define RAMDISK_HANDLER_H_
|
||||
|
||||
extern unsigned long ramdisk_size;
|
||||
|
||||
int ramdisk_handler_patch_dtb(const void *fdt, void *buf, int bufsize);
|
||||
|
||||
#endif
|
||||
@@ -16,4 +16,11 @@ menu "Libraries"
|
||||
default y
|
||||
help
|
||||
Say Y if you want to have libfdt features.
|
||||
|
||||
config FDT_BUF_SIZE
|
||||
int "Size of the static buffer for the Flattened Device Tree"
|
||||
default 500000
|
||||
depends on LIBFDT
|
||||
help
|
||||
This option specifies the size (in bytes) of the buffer used for DTB modifying. The default value of 500 KB should be sufficient even for downstream device trees.
|
||||
endmenu
|
||||
+15
@@ -7,11 +7,18 @@
|
||||
#include <main.h>
|
||||
#include <string.h>
|
||||
#include <lib/debug.h>
|
||||
#include <drivers/ramdisk-handler.h>
|
||||
|
||||
extern struct board_data board_ops;
|
||||
|
||||
#ifdef CONFIG_LIBFDT
|
||||
static char fdt_buf[CONFIG_FDT_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
void main(void* dt, void* kernel, void* ramdisk)
|
||||
{
|
||||
int ret;
|
||||
|
||||
INITCALL(board_ops.ops.early_init);
|
||||
INITCALL(board_ops.ops.drivers_init);
|
||||
|
||||
@@ -27,6 +34,14 @@ void main(void* dt, void* kernel, void* ramdisk)
|
||||
|
||||
INITCALL(board_ops.ops.drivers_init);
|
||||
|
||||
#ifdef CONFIG_LIBFDT
|
||||
ret = ramdisk_handler_patch_dtb(dt, &fdt_buf, sizeof(fdt_buf));
|
||||
if (ret == 0)
|
||||
dt = &fdt_buf;
|
||||
else
|
||||
printk(KERN_ERR, "failed to patch dtb\n");
|
||||
#endif
|
||||
|
||||
/* copy kernel to memory and boot */
|
||||
printk(KERN_INFO, "booting linux...\n");
|
||||
#ifdef __aarch64__
|
||||
|
||||
Reference in new issue
Block a user