Make it a generic setup_data loader keyed by type.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Thierry Reding <thierry.reding@avionic-design.de>
};
#define INITRAMFS_MAX_ALIGN 4096
-struct fdt {
- void *data;
- size_t len;
-};
-#define DEVICETREE_MAX_ALIGN 4096
-
-struct setup_data {
+struct setup_data_header {
uint64_t next;
uint32_t type;
uint32_t len;
- uint8_t data[0];
+} __packed;
+
+struct setup_data {
+ struct setup_data *prev, *next;
+ const void *data;
+ struct setup_data_header hdr;
};
#define SETUP_NONE 0
#define SETUP_DTB 2
int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
- struct initramfs *initramfs, struct fdt *fdt,
+ struct initramfs *initramfs,
+ struct setup_data *setup_data,
char *cmdline);
/* Initramfs manipulation functions */
int initramfs_add_trailer(struct initramfs *ihead);
int initramfs_load_archive(struct initramfs *ihead, const char *filename);
-/* Device Tree manipulation functions */
+/* Setup data manipulation functions */
-struct fdt *fdt_init(void);
-int fdt_load(struct fdt *fdt, const char *filename);
+int setup_data_add(struct setup_data *head, uint32_t type,
+ const void *data, size_t data_len);
+int setup_data_load(struct setup_data *head, uint32_t type,
+ const char *filename);
#endif /* _SYSLINUX_LINUX_H */
\
syslinux/disk.o \
\
- syslinux/fdt.o
+ syslinux/setup_data.o
# These are the objects which are also imported into the core
LIBCOREOBJS = \
+++ /dev/null
-#include <stdlib.h>
-#include <syslinux/linux.h>
-#include <syslinux/loadfile.h>
-
-struct fdt *fdt_init(void)
-{
- struct fdt *fdt;
-
- fdt = calloc(1, sizeof(*fdt));
- if (!fdt)
- return NULL;
-
- return fdt;
-}
-
-int fdt_load(struct fdt *fdt, const char *filename)
-{
- void *data;
- size_t len;
-
- if (loadfile(filename, &data, &len))
- return -1;
-
- fdt->data = data;
- fdt->len = len;
-
- return 0;
-}
}
int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
- struct initramfs *initramfs, struct fdt *fdt,
+ struct initramfs *initramfs,
+ struct setup_data *setup_data,
char *cmdline)
{
struct linux_header hdr, *whdr;
addr_t real_mode_base, prot_mode_base;
addr_t irf_size;
size_t cmdline_size, cmdline_offset;
+ struct setup_data *sdp;
struct syslinux_rm_regs regs;
struct syslinux_movelist *fraglist = NULL;
struct syslinux_memmap *mmap = NULL;
}
}
- if (fdt && fdt->len > 0) {
- const addr_t align_mask = DEVICETREE_MAX_ALIGN - 1;
- struct syslinux_memmap *ml;
- struct setup_data *setup;
- addr_t best_addr = 0;
- size_t size;
+ if (setup_data) {
+ uint64_t *prev_ptr = &whdr->setup_data;
- size = sizeof(*setup) + fdt->len;
-
- setup = malloc(size);
- if (!setup)
- goto bail;
+ for (sdp = setup_data->next; sdp != setup_data; sdp = sdp->next) {
+ struct syslinux_memmap *ml;
+ const addr_t align_mask = 15; /* Header is 16 bytes */
+ addr_t best_addr = 0;
+ size_t size = sdp->hdr.len + sizeof(sdp->hdr);
- setup->next = 0;
- setup->type = SETUP_DTB;
- setup->len = fdt->len;
- memcpy(setup->data, fdt->data, fdt->len);
+ if (!sdp->data || !sdp->hdr.len)
+ continue;
- for (ml = amap; ml->type != SMT_END; ml = ml->next) {
+ for (ml = amap; ml->type != SMT_END; ml = ml->next) {
addr_t adj_start = (ml->start + align_mask) & ~align_mask;
addr_t adj_end = ml->next->start & ~align_mask;
if (ml->type == SMT_FREE && adj_end - adj_start >= size)
- best_addr = (adj_end - size) & ~align_mask;
- }
+ best_addr = (adj_end - size) & ~align_mask;
+ }
- if (!best_addr)
+ if (!best_addr)
goto bail;
- whdr->setup_data = best_addr;
-
- if (syslinux_add_memmap(&amap, best_addr, size, SMT_ALLOC))
- goto bail;
+ *prev_ptr = best_addr;
+ prev_ptr = &sdp->hdr.next;
- if (syslinux_add_movelist(&fraglist, best_addr, (addr_t) setup, size))
- goto bail;
+ if (syslinux_add_memmap(&amap, best_addr, size, SMT_ALLOC))
+ goto bail;
+ if (syslinux_add_movelist(&fraglist, best_addr,
+ (addr_t)&sdp->hdr, sizeof sdp->hdr))
+ goto bail;
+ if (syslinux_add_movelist(&fraglist, best_addr + sizeof sdp->hdr,
+ (addr_t)sdp->data, sdp->hdr.len))
+ goto bail;
+ }
}
/* Set up the registers on entry */
--- /dev/null
+#include <stdlib.h>
+#include <syslinux/linux.h>
+#include <syslinux/loadfile.h>
+
+struct setup_data *setup_data_init(void)
+{
+ struct setup_data *setup_data;
+
+ setup_data = zalloc(sizeof(*setup_data));
+ if (!setup_data)
+ return NULL;
+
+ setup_data->prev = setup_data->next = setup_data;
+ return setup_data;
+}
+
+int setup_data_add(struct setup_data *head, uint32_t type,
+ const void *data, size_t data_len)
+{
+ struct setup_data *setup_data;
+
+ setup_data = zalloc(sizeof(*setup_data));
+ if (!setup_data)
+ return -1;
+
+ setup_data->data = data;
+ setup_data->hdr.len = data_len;
+ setup_data->hdr.type = type;
+ setup_data->prev = head->prev;
+ setup_data->next = head;
+ head->prev->next = setup_data;
+ head->prev = setup_data;
+
+ return 0;
+}
+
+int setup_data_load(struct setup_data *head, uint32_t type,
+ const char *filename)
+{
+ void *data;
+ size_t len;
+
+ if (loadfile(filename, &data, &len))
+ return -1;
+
+ return setup_data_add(head, type, data, len);
+}
/* This should not return... */
errno = 0;
- syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
+ syslinux_boot_linux(kernel_data, kernel_len, initramfs, NULL, cmdline);
fprintf(stderr, "syslinux_boot_linux() failed: ");
bail: