xref: /haiku/src/system/boot/platform/u-boot/devices.cpp (revision 4b7e219688450694efc9d1890f83f816758c16d3)
1 /*
2  * Copyright 2009, Johannes Wischert, johanneswi@gmail.com. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <KernelExport.h>
8 
9 #include <boot/disk_identifier.h>
10 #include <boot/vfs.h>
11 #include <boot/platform.h>
12 #include <boot/stage2.h>
13 #include <boot/stdio.h>
14 
15 #define TRACE_DEVICES
16 #ifdef TRACE_DEVICES
17 #	define TRACE(x...) dprintf(x)
18 #else
19 #	define TRACE(x...)
20 #endif
21 
22 
23 
24 
25 status_t
26 platform_add_boot_device(struct stage2_args *args, NodeList *devicesList)
27 {
28 	TRACE("platform_add_boot_device\n");
29 
30 	if (!args->platform.boot_tgz_data || !args->platform.boot_tgz_size)
31 		return B_DEVICE_NOT_FOUND;
32 
33 	TRACE("Memory Disk at: %p size: %lx\n", args->platform.boot_tgz_data,
34 		args->platform.boot_tgz_size);
35 
36 	MemoryDisk* disk = new(nothrow) MemoryDisk(
37 		(const uint8 *)args->platform.boot_tgz_data,
38 		args->platform.boot_tgz_size, "boot.tgz");
39 	if (!disk) {
40 		dprintf("platform_add_boot_device(): Could not create MemoryDisk !\n");
41 		return B_NO_MEMORY;
42 	}
43 
44 	devicesList->Add(disk);
45 	return B_OK;
46 }
47 
48 
49 status_t
50 platform_get_boot_partition(struct stage2_args *args, Node *device,
51 	NodeList *list, boot::Partition **_partition)
52 {
53 	TRACE("platform_get_boot_partition\n");
54 
55 	NodeIterator iterator = list->GetIterator();
56 	boot::Partition *partition = NULL;
57 	while ((partition = (boot::Partition *)iterator.Next()) != NULL) {
58 		// ToDo: just take the first partition for now
59 		*_partition = partition;
60 		return B_OK;
61 	}
62 
63 	return B_ENTRY_NOT_FOUND;
64 }
65 
66 
67 status_t
68 platform_add_block_devices(stage2_args *args, NodeList *devicesList)
69 {
70 	TRACE("platform_add_block_devices\n");
71 	return B_OK;
72 }
73 
74 
75 status_t
76 platform_register_boot_device(Node *device)
77 {
78 	disk_identifier disk_ident;
79         disk_ident.bus_type = UNKNOWN_BUS;
80         disk_ident.device_type = UNKNOWN_DEVICE;
81         disk_ident.device.unknown.size = device->Size();
82 
83         for (int32 i = 0; i < NUM_DISK_CHECK_SUMS; i++) {
84                 disk_ident.device.unknown.check_sums[i].offset = -1;
85                 disk_ident.device.unknown.check_sums[i].sum = 0;
86         }
87 
88 	gBootVolume.SetData(BOOT_VOLUME_DISK_IDENTIFIER, B_RAW_TYPE,
89 		&disk_ident, sizeof(disk_ident));
90 
91 	return B_OK;
92 }
93