summaryrefslogtreecommitdiffstats
path: root/arch/x86/boards/x86_generic/generic_pc.c
blob: bd93bc168de30e2057b94bc90cd33264cba13fbc (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
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright (C) 2009 Juergen Beisert, Pengutronix
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

/**
 * @file
 * @brief Generic PC support to let barebox acting as a boot loader
 */

#include <common.h>
#include <types.h>
#include <driver.h>
#include <init.h>
#include <asm/syslib.h>
#include <ns16550.h>

static struct memory_platform_data ram_pdata = {
	.name		= "ram0",
	.flags		= DEVFS_RDWR,
};

static struct device_d sdram_dev = {
	.name		= "mem",
	.size		= 16 * 1024 * 1024,
	.map_base	= 0,
	.platform_data	= &ram_pdata,
};

static struct device_d bios_disk_dev = {
	.name		= "biosdrive",
	.size		= 1,
};

/*
 * These datas are from the MBR, created by the linker and filled by the
 * setup tool while installing barebox on the disk drive
 */
extern uint64_t pers_env_storage;
extern uint16_t pers_env_size;
extern uint8_t pers_env_drive;

/**
 * Persistant environment "not used" marker.
 * Note: Must be in accordance to the value the tool "setup_mbr" writes.
 */
#define PATCH_AREA_PERS_SIZE_UNUSED 0x000

static int devices_init(void)
{
	int rc;

	sdram_dev.size = bios_get_memsize();	/* extended memory only */
	sdram_dev.size <<= 10;

	register_device(&sdram_dev);
	register_device(&bios_disk_dev);

	if (pers_env_size != PATCH_AREA_PERS_SIZE_UNUSED) {
		rc = devfs_add_partition("disk0",	/* FIXME */
				pers_env_storage * 512,
				(unsigned)pers_env_size * 512,
				DEVFS_PARTITION_FIXED, "env0");
		printf("Partition: %d\n", rc);
	} else
		printf("No persistant storage defined\n");

        return 0;
}
device_initcall(devices_init);

#ifdef CONFIG_DRIVER_SERIAL_NS16550

static struct NS16550_plat serial_plat = {
       .clock = 1843200,
       .f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR,
       .reg_read = x86_uart_read,
       .reg_write = x86_uart_write,
};

/* we are expecting always one serial interface */
static struct device_d generic_pc_serial_device = {
       .name = "serial_ns16550",
       .map_base = 0x3f8,
       .size = 8,
       .platform_data = (void *)&serial_plat,
};

static int pc_console_init(void)
{
       /* Register the serial port */
       return register_device(&generic_pc_serial_device);
}
console_initcall(pc_console_init);

#endif

/** @page generic_pc Generic PC based bootloader

This platform acts as a generic PC based bootloader. It depends on at least
one boot media that is connected locally (no network boot) and can be
handled by the regular BIOS (any kind of hard disks for example).

The created @a barebox image can be used to boot a standard x86 bzImage
Linux kernel.

Refer section @ref x86_bootloader_preparations how to do so.

How to get the binary image:

Using the default configuration:

@code
make ARCH=x86 generic_defconfig
@endcode

Build the binary image:

@code
make ARCH=x86 CROSS_COMPILE=x86compiler
@endcode

@note replace the 'x86compiler' with your x86 (cross) compiler.

*/