7 #include <syslinux/loadfile.h>
8 #include <syslinux/linux.h>
9 #include <syslinux/pxe.h>
12 const char *globaldefault
= NULL
;
13 const char *append
= NULL
;
15 /* Will be called from readconfig.c */
16 int new_linux_kernel(char *okernel
, char *ocmdline
)
18 const char *kernel_name
= NULL
, *args
= NULL
;
19 struct initramfs
*initramfs
= NULL
;
22 size_t kernel_len
, cmdline_len
;
23 bool opt_quiet
= false;
24 char *initrd_name
, *cmdline
;
26 dprintf("okernel = %s, ocmdline = %s", okernel
, ocmdline
);
29 kernel_name
= okernel
;
30 else if (globaldefault
)
31 kernel_name
= globaldefault
;
38 cmdline_len
= strlen(kernel_name
);
40 /* +1 for the space (' ') between kernel and args */
41 cmdline_len
+= strlen(args
) + 1;
44 /* +1 for NUL termination */
47 cmdline
= malloc(cmdline_len
);
49 printf("Failed to alloc memory for cmdline\n");
54 snprintf(cmdline
, cmdline_len
, "%s %s", kernel_name
, args
);
56 snprintf(cmdline
, cmdline_len
, "%s", kernel_name
);
58 /* "keeppxe" handling */
62 if (strstr(cmdline
, "keeppxe"))
66 if (strstr(cmdline
, "quiet"))
70 printf("Loading %s... ", kernel_name
);
72 if (loadfile(kernel_name
, &kernel_data
, &kernel_len
)) {
74 printf("Loading %s ", kernel_name
);
82 /* Find and load initramfs */
83 temp
= strstr(cmdline
, "initrd=");
85 /* Initialize the initramfs chain */
86 initramfs
= initramfs_init();
90 temp
+= 6; /* strlen("initrd") */
95 temp
++; /* Skip = or , */
98 while (*p
!= ' ' && *p
!= ',' && *p
) {
103 initrd_name
= malloc(n
+ 1);
105 printf("Failed to allocate space for initrd\n");
109 snprintf(initrd_name
, n
+ 1, "%s", temp
);
113 printf("Loading %s...", initrd_name
);
115 if (initramfs_load_archive(initramfs
, initrd_name
)) {
117 printf("Loading %s ", initrd_name
);
127 } while (*temp
== ',');
130 /* This should not return... */
131 syslinux_boot_linux(kernel_data
, kernel_len
, initramfs
, NULL
, cmdline
);
132 printf("Booting kernel failed: ");
136 printf("%s\n", strerror(errno
));