mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 01:34:12 +00:00
kboot: Replace kboot_set_bootargs with kboot_set_chosen
This allows setting arbitrary /chosen string props Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
adb1cb943e
commit
123d1df1a7
7 changed files with 46 additions and 22 deletions
|
@ -538,7 +538,7 @@ class M1N1Proxy(Reloadable):
|
|||
P_FREE = 0x602
|
||||
|
||||
P_KBOOT_BOOT = 0x700
|
||||
P_KBOOT_SET_BOOTARGS = 0x701
|
||||
P_KBOOT_SET_CHOSEN = 0x701
|
||||
P_KBOOT_SET_INITRD = 0x702
|
||||
P_KBOOT_PREPARE_DT = 0x703
|
||||
|
||||
|
@ -920,8 +920,8 @@ class M1N1Proxy(Reloadable):
|
|||
|
||||
def kboot_boot(self, kernel):
|
||||
self.request(self.P_KBOOT_BOOT, kernel)
|
||||
def kboot_set_bootargs(self, bootargs):
|
||||
self.request(self.P_KBOOT_SET_BOOTARGS, bootargs)
|
||||
def kboot_set_chosen(self, name, value):
|
||||
self.request(self.P_KBOOT_SET_CHOSEN, name, value)
|
||||
def kboot_set_initrd(self, base, size):
|
||||
self.request(self.P_KBOOT_SET_INITRD, base, size)
|
||||
def kboot_prepare_dt(self, dt_addr):
|
||||
|
|
|
@ -45,7 +45,7 @@ else:
|
|||
|
||||
if args.bootargs is not None:
|
||||
print('Setting boot args: "{}"'.format(args.bootargs))
|
||||
p.kboot_set_bootargs(args.bootargs)
|
||||
p.kboot_set_chosen("bootargs", args.bootargs)
|
||||
|
||||
if args.compression != 'none':
|
||||
compressed_size = len(payload)
|
||||
|
|
50
src/kboot.c
50
src/kboot.c
|
@ -15,11 +15,13 @@
|
|||
|
||||
#include "libfdt/libfdt.h"
|
||||
|
||||
#define MAX_CHOSEN_PARAMS 16
|
||||
|
||||
static void *dt = NULL;
|
||||
static int dt_bufsize = 0;
|
||||
static char *bootargs = NULL;
|
||||
static void *initrd_start = NULL;
|
||||
static size_t initrd_size = 0;
|
||||
static char *chosen_params[MAX_CHOSEN_PARAMS][2];
|
||||
|
||||
#define DT_ALIGN 16384
|
||||
|
||||
|
@ -79,11 +81,15 @@ static int dt_set_chosen(void)
|
|||
if (node < 0)
|
||||
bail("FDT: /chosen node not found in devtree\n");
|
||||
|
||||
if (bootargs) {
|
||||
if (fdt_setprop(dt, node, "bootargs", bootargs, strlen(bootargs) + 1) < 0)
|
||||
bail("FDT: couldn't set chosen.bootargs property\n");
|
||||
for (int i = 0; i < MAX_CHOSEN_PARAMS; i++) {
|
||||
if (!chosen_params[i][0])
|
||||
break;
|
||||
|
||||
printf("FDT: bootargs = '%s'\n", bootargs);
|
||||
const char *name = chosen_params[i][0];
|
||||
const char *value = chosen_params[i][1];
|
||||
if (fdt_setprop(dt, node, name, value, strlen(value) + 1) < 0)
|
||||
bail("FDT: couldn't set chosen.%s property\n", name);
|
||||
printf("FDT: %s = '%s'\n", name, value);
|
||||
}
|
||||
|
||||
if (initrd_start && initrd_size) {
|
||||
|
@ -536,18 +542,36 @@ void kboot_set_initrd(void *start, size_t size)
|
|||
initrd_size = size;
|
||||
}
|
||||
|
||||
void kboot_set_bootargs(const char *ba)
|
||||
int kboot_set_chosen(const char *name, const char *value)
|
||||
{
|
||||
if (bootargs)
|
||||
free(bootargs);
|
||||
int i = 0;
|
||||
|
||||
if (!ba) {
|
||||
bootargs = NULL;
|
||||
return;
|
||||
if (!name)
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < MAX_CHOSEN_PARAMS; i++) {
|
||||
if (!chosen_params[i][0]) {
|
||||
chosen_params[i][0] = malloc(strlen(name) + 1);
|
||||
strcpy(chosen_params[i][0], name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp(name, chosen_params[i][0])) {
|
||||
free(chosen_params[i][1]);
|
||||
chosen_params[i][1] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bootargs = malloc(strlen(ba) + 1);
|
||||
strcpy(bootargs, ba);
|
||||
if (i >= MAX_CHOSEN_PARAMS)
|
||||
return -1;
|
||||
|
||||
if (value) {
|
||||
chosen_params[i][1] = malloc(strlen(value) + 1);
|
||||
strcpy(chosen_params[i][1], value);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int kboot_prepare_dt(void *fdt)
|
||||
|
|
|
@ -18,7 +18,7 @@ struct kernel_header {
|
|||
};
|
||||
|
||||
void kboot_set_initrd(void *start, size_t size);
|
||||
void kboot_set_bootargs(const char *ba);
|
||||
int kboot_set_chosen(const char *name, const char *value);
|
||||
int kboot_prepare_dt(void *fdt);
|
||||
int kboot_boot(void *kernel);
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ static bool check_var(u8 **p)
|
|||
|
||||
if (IS_VAR("boot-args=")) {
|
||||
*end = 0;
|
||||
kboot_set_bootargs(val);
|
||||
kboot_set_chosen("bootargs", val);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -355,8 +355,8 @@ int proxy_process(ProxyRequest *request, ProxyReply *reply)
|
|||
if (kboot_boot((void *)request->args[0]) == 0)
|
||||
return 1;
|
||||
break;
|
||||
case P_KBOOT_SET_BOOTARGS:
|
||||
kboot_set_bootargs((void *)request->args[0]);
|
||||
case P_KBOOT_SET_CHOSEN:
|
||||
reply->retval = kboot_set_chosen((void *)request->args[0], (void *)request->args[1]);
|
||||
break;
|
||||
case P_KBOOT_SET_INITRD:
|
||||
kboot_set_initrd((void *)request->args[0], request->args[1]);
|
||||
|
|
|
@ -90,7 +90,7 @@ typedef enum {
|
|||
P_FREE,
|
||||
|
||||
P_KBOOT_BOOT = 0x700, // Kernel boot ops
|
||||
P_KBOOT_SET_BOOTARGS,
|
||||
P_KBOOT_SET_CHOSEN,
|
||||
P_KBOOT_SET_INITRD,
|
||||
P_KBOOT_PREPARE_DT,
|
||||
|
||||
|
|
Loading…
Reference in a new issue