aboutsummaryrefslogtreecommitdiffstats
path: root/core/elflink/kernel.c
blob: 6cb33639e0b59b0140f5ac092cd3d371daaf3808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <console.h>
#include <dprintf.h>
#include <syslinux/loadfile.h>
#include <syslinux/linux.h>
#include <syslinux/pxe.h>
#include "core.h"
#include "core-elf.h"

char *globaldefault = NULL;
char *append = NULL;

/* Will be called from readconfig.c */
int new_linux_kernel(char *okernel, char *ocmdline)
{
	const char *kernel_name;
	struct initramfs *initramfs;
	char *temp;
	void *kernel_data;
	size_t kernel_len;
	bool opt_quiet = false;
	char initrd_name[256];
	char cmdline_buf[256], *cmdline;
	int i;

	dprintf("okernel = %s, ocmdline = %s", okernel, ocmdline);

	cmdline = cmdline_buf;

	temp = cmdline;
	/*
	strcpy(temp, "BOOT_IMAGE=");
	temp += 11;
	*/

	if (okernel)
		kernel_name = okernel;
	else if (globaldefault)
		kernel_name = globaldefault;

	strcpy(temp, kernel_name);
	temp += strlen(kernel_name);

	/* in elflink branch, KernelCName no more exist */	
	/*
	else {
		strcpy(temp, KernelCName);
		temp += strlen(KernelCName);
		kernel_name = KernelCName;
	}
	*/

	*temp = ' ';
	temp++;
	if (ocmdline)
		strcpy(temp, ocmdline);
	else if (append)
		strcpy(temp, append);
	/*	
	else if (*(char *)CmdOptPtr)
		strcpy(temp, (char *)CmdOptPtr);
	else if (AppendLen) {
		for (i = 0; i < AppendLen; i++)
			*temp++ = AppendBuf[i];
		*temp = '\0';
	}
	*/

	printf("cmdline = %s\n", cmdline);
	/*
	printf("VkernelEnd = %x\n", VKernelEnd);
	printf("HighMemSize = %x\n", __com32.cs_memsize);
	*/

	/* "keeppxe" handling */
#if IS_PXELINUX
	extern char KeepPXE;

	if (strstr(cmdline, "keeppxe"))
		KeepPXE |= 1;
#endif

	if (strstr(cmdline, "quiet"))
		opt_quiet = true;

	if (!opt_quiet)
		printf("Loading %s... ", kernel_name);

	if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
		if (opt_quiet)
			printf("Loading %s ", kernel_name);
		printf("failed!\n");
		goto bail;
	}

	if (!opt_quiet)
		printf("ok\n");

	/* Initialize the initramfs chain */
	initramfs = initramfs_init();
	if (!initramfs)
		goto bail;

	/* Find and load initramfs */
	temp = strstr(cmdline, "initrd=");
	if (temp) {
		i = 0;

		temp += strlen("initrd=");
		while (*temp != ' ' && *temp)
			initrd_name[i++] = *temp++;
		initrd_name[i] = '\0';

		initramfs_load_archive(initramfs, initrd_name);
	}

	//dprintf("loading initrd done");

	/* This should not return... */
	syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);

bail:
	printf("Kernel load failure (insufficient memory?)\n");
	return 1;
}