1/*
2 * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2010, Andreas Färber <andreas.faerber@web.de>
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6
7
8#include <string.h>
9
10#include <boot/platform.h>
11#include <boot/vfs.h>
12#include <boot/stdio.h>
13#include <boot/stage2.h>
14#include <boot/net/IP.h>
15#include <boot/net/iSCSITarget.h>
16#include <boot/net/NetStack.h>
17#include <boot/net/RemoteDisk.h>
18//#include <platform/cfe/devices.h>
19#include <boot/platform/cfe/cfe.h>
20#include <util/kernel_cpp.h>
21
22#include "Handle.h"
23
24
25char sBootPath[192];
26
27
28status_t
29platform_add_boot_device(struct stage2_args *args, NodeList *devicesList)
30{
31#warning PPC:TODO
32	return B_ERROR;
33}
34
35
36status_t
37platform_get_boot_partition(struct stage2_args *args, Node *device,
38	NodeList *list, boot::Partition **_partition)
39{
40	NodeIterator iterator = list->GetIterator();
41	boot::Partition *partition = NULL;
42	while ((partition = (boot::Partition *)iterator.Next()) != NULL) {
43		// ToDo: just take the first partition for now
44		*_partition = partition;
45		return B_OK;
46	}
47
48	return B_ENTRY_NOT_FOUND;
49}
50
51
52#define DUMPED_BLOCK_SIZE 16
53
54void
55dumpBlock(const char *buffer, int size, const char *prefix)
56{
57	int i;
58
59	for (i = 0; i < size;) {
60		int start = i;
61
62		printf(prefix);
63		for (; i < start+DUMPED_BLOCK_SIZE; i++) {
64			if (!(i % 4))
65				printf(" ");
66
67			if (i >= size)
68				printf("  ");
69			else
70				printf("%02x", *(unsigned char *)(buffer + i));
71		}
72		printf("  ");
73
74		for (i = start; i < start + DUMPED_BLOCK_SIZE; i++) {
75			if (i < size) {
76				char c = buffer[i];
77
78				if (c < 30)
79					printf(".");
80				else
81					printf("%c", c);
82			} else
83				break;
84		}
85		printf("\n");
86	}
87}
88
89
90status_t
91platform_add_block_devices(stage2_args *args, NodeList *devicesList)
92{
93	// add all block devices to the list of possible boot devices
94
95	int cookie = 0;
96	char path[256];
97	int status;
98	for (; (status = cfe_enumdev(cookie, path, sizeof(path))) == B_OK; 				cookie++) {
99		if (!strcmp(path, sBootPath)) {
100			// don't add the boot device twice
101			continue;
102		}
103
104		printf("\t%s\n", path);
105
106		int handle = cfe_open(path);
107		if (handle < CFE_OK) {
108			puts("\t\t(failed)");
109			continue;
110		}
111
112		Handle *device = new(nothrow) Handle(handle);
113		printf("\t\t(could open device, handle = %d, node = %p)\n",
114			handle, device);
115
116		devicesList->Add(device);
117	}
118	printf("\t(loop ended with %ld)\n", status);
119
120	return B_OK;
121}
122
123
124status_t
125platform_register_boot_device(Node *device)
126{
127	disk_identifier disk;
128
129	disk.bus_type = UNKNOWN_BUS;
130	disk.device_type = UNKNOWN_DEVICE;
131	disk.device.unknown.size = device->Size();
132
133	gBootVolume.SetData(BOOT_VOLUME_DISK_IDENTIFIER, B_RAW_TYPE, &disk,
134		sizeof(disk_identifier));
135
136	return B_OK;
137}
138
139