aboutsummaryrefslogtreecommitdiff
path: root/fw_cfg.c
blob: c1b354e75f88706ee74e7e98273aea5f3f6d9a1c (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
#include "bios.h"
#include "stdio.h"
#include "ioport.h"
#include "string.h"
#include "fw_cfg.h"
#include "linuxboot.h"

struct fw_cfg_file {
	uint32_t size;
	uint16_t select;
	char name[57];
};

static struct fw_cfg_file files[32];

void fw_cfg_setup(void)
{
	int i, n;

	fw_cfg_select(FW_CFG_FILE_DIR);
	n = fw_cfg_readl_be();
	if (n > ARRAY_SIZE(files))
		n = ARRAY_SIZE(files);

	for (i = 0; i < n; i++) {
		files[i].size = fw_cfg_readl_be();
		files[i].select = fw_cfg_readw_be();
		fw_cfg_readw_be();
		fw_cfg_read(files[i].name, sizeof(files[i].name) - 1);
	}
}

int fw_cfg_file_id(char *name)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(files); i++)
		if (!strcmp(name, files[i].name))
			return i;

	return -1;
}

uint32_t fw_cfg_file_size(int id)
{
	return files[id].size;
}

void fw_cfg_file_select(int id)
{
	fw_cfg_select(files[id].select);
}

void boot_from_fwcfg(void)
{
	struct linuxboot_args args;
	uint32_t kernel_size;

	fw_cfg_select(FW_CFG_CMDLINE_SIZE);
	args.cmdline_size = fw_cfg_readl_le();
	fw_cfg_select(FW_CFG_INITRD_SIZE);
	args.initrd_size = fw_cfg_readl_le();

	/* QEMU has already split the real mode and protected mode
	 * parts.  Recombine them in args.vmlinuz_size.
	 */
	fw_cfg_select(FW_CFG_KERNEL_SIZE);
	kernel_size = fw_cfg_readl_le();
	fw_cfg_select(FW_CFG_SETUP_SIZE);
	args.vmlinuz_size = kernel_size + fw_cfg_readl_le();

	fw_cfg_select(FW_CFG_SETUP_DATA);
	fw_cfg_read(args.header, sizeof(args.header));

	if (!parse_bzimage(&args))
		return;

	/* SETUP_DATA already selected */
	if (args.setup_size > sizeof(args.header))
		fw_cfg_read(args.setup_addr + sizeof(args.header),
			    args.setup_size - sizeof(args.header));

	fw_cfg_select(FW_CFG_KERNEL_DATA);
	fw_cfg_read(args.kernel_addr, kernel_size);

	fw_cfg_select(FW_CFG_CMDLINE_DATA);
	fw_cfg_read(args.cmdline_addr, args.cmdline_size);

	if (args.initrd_size) {
		fw_cfg_select(FW_CFG_INITRD_DATA);
		fw_cfg_read(args.initrd_addr, args.initrd_size);
	}

	boot_bzimage(&args);
}