base: Add support for DT initrd/initramfs

Add a new API function, addBootData(), which allows the ports to specify
the size and load address of the initrd/initramfs via DeviceTree. This
uses the standard chosen nodes for initrd-start/initrd-end.

Update the addBootCmdline() to call addBootData() with no
initrd/initramfs so as to maintain backwards compatibility.

Change-Id: I7b1d5cf2a0b18685eaadf1d881434f3d48c45d8b
Signed-off-by: Alistair Delva <adelva@google.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/54183
Reviewed-by: Richard Cooper <richard.cooper@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Alistair Delva
2021-12-14 10:13:57 -08:00
parent f894de5486
commit 5af49d03da
2 changed files with 46 additions and 5 deletions

View File

@@ -63,12 +63,15 @@ DtbFile::~DtbFile()
}
bool
DtbFile::addBootCmdLine(const char *_args, size_t len)
DtbFile::addBootData(const char *_cmdline, size_t cmdline_len,
off_t initrd_start, size_t initrd_len)
{
const char *root_path = "/";
const char *node_name = "chosen";
const char *full_path_node_name = "/chosen";
const char *property_name = "bootargs";
const char *bootargs_property_name = "bootargs";
const char *linux_initrd_start_property_name = "linux,initrd-start";
const char *linux_initrd_end_property_name = "linux,initrd-end";
// Make a new buffer that has extra space to add nodes/properties
int newLen = 2 * length;
@@ -102,8 +105,8 @@ DtbFile::addBootCmdLine(const char *_args, size_t len)
}
// Set the bootargs property in the /chosen node
ret = fdt_setprop((void *)fdt_buf_w_space, offset, property_name,
(const void *)_args, len+1);
ret = fdt_setprop((void *)fdt_buf_w_space, offset, bootargs_property_name,
(const void *)_cmdline, cmdline_len+1);
if (ret < 0) {
warn("Error setting \"bootargs\" property to flattened device tree, "
"errno: %d\n", ret);
@@ -111,6 +114,30 @@ DtbFile::addBootCmdLine(const char *_args, size_t len)
return false;
}
if (initrd_len != 0) {
// Set the linux,initrd-start property in the /chosen node
ret = fdt_setprop_u64((void *)fdt_buf_w_space, offset,
linux_initrd_start_property_name,
(uint64_t)initrd_start);
if (ret < 0) {
warn("Error setting \"linux,initrd-start\" property to flattened "
"device tree, errno: %d\n", ret);
delete [] fdt_buf_w_space;
return false;
}
// Set the computed linux,initrd-end property in the /chosen node
ret = fdt_setprop_u64((void *)fdt_buf_w_space, offset,
linux_initrd_end_property_name,
(uint64_t)initrd_start + initrd_len);
if (ret < 0) {
warn("Error setting \"linux,initrd-len\" property to flattened "
"device tree, errno: %d\n", ret);
delete [] fdt_buf_w_space;
return false;
}
}
// Repack the dtb for kernel use
ret = fdt_pack((void *)fdt_buf_w_space);
if (ret < 0) {

View File

@@ -58,13 +58,27 @@ class DtbFile : public ImageFile
DtbFile(const std::string &name);
~DtbFile();
/** Adds the passed in Command Line options and initrd for the kernel
* to the proper location in the device tree.
* @param _cmdline command line to append
* @param cmdline_len length of the command line string
* @param initrd_addr starting physical address of initrd
* @param initrd_len length of initrd data in memory
* @return returns true on success, false otherwise
*/
bool addBootData(const char* _cmdline, size_t cmdline_len,
off_t initrd_addr, size_t initrd_len);
/** Adds the passed in Command Line options for the kernel
* to the proper location in the device tree.
* @param _args command line to append
* @param len length of the command line string
* @return returns true on success, false otherwise
*/
bool addBootCmdLine(const char* _args, size_t len);
inline bool
addBootCmdLine(const char* _args, size_t len) {
return addBootData(_args, len, 0, 0);
}
/** Parse the DTB file enough to find the provided release
* address and return it.