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/partitions.h>
13 #include <boot/stage2.h>
14 #include <boot/stdio.h>
15
16 #define TRACE_DEVICES
17 #ifdef TRACE_DEVICES
18 # define TRACE(x...) dprintf(x)
19 #else
20 # define TRACE(x...)
21 #endif
22
23
24
25
26 status_t
platform_add_boot_device(struct stage2_args * args,NodeList * devicesList)27 platform_add_boot_device(struct stage2_args *args, NodeList *devicesList)
28 {
29 TRACE("platform_add_boot_device\n");
30
31 if (!args->platform.boot_tgz_data || !args->platform.boot_tgz_size)
32 return B_DEVICE_NOT_FOUND;
33
34 TRACE("Memory Disk at: %p size: %lx\n", args->platform.boot_tgz_data,
35 args->platform.boot_tgz_size);
36
37 MemoryDisk* disk = new(nothrow) MemoryDisk(
38 (const uint8 *)args->platform.boot_tgz_data,
39 args->platform.boot_tgz_size, "boot.tgz");
40 if (!disk) {
41 dprintf("platform_add_boot_device(): Could not create MemoryDisk !\n");
42 return B_NO_MEMORY;
43 }
44
45 devicesList->Add(disk);
46 return B_OK;
47 }
48
49
50 status_t
platform_get_boot_partitions(struct stage2_args * args,Node * device,NodeList * list,NodeList * partitionList)51 platform_get_boot_partitions(struct stage2_args *args, Node *device,
52 NodeList *list, NodeList *partitionList)
53 {
54 TRACE("platform_get_boot_partition\n");
55
56 NodeIterator iterator = list->GetIterator();
57 boot::Partition *partition = NULL;
58 while ((partition = (boot::Partition *)iterator.Next()) != NULL) {
59 // ToDo: just take the first partition for now
60 partitionList->Insert(partition);
61 return B_OK;
62 }
63
64 return B_ENTRY_NOT_FOUND;
65 }
66
67
68 status_t
platform_add_block_devices(stage2_args * args,NodeList * devicesList)69 platform_add_block_devices(stage2_args *args, NodeList *devicesList)
70 {
71 TRACE("platform_add_block_devices\n");
72 return B_OK;
73 }
74
75
76 status_t
platform_register_boot_device(Node * device)77 platform_register_boot_device(Node *device)
78 {
79 disk_identifier disk_ident;
80 disk_ident.bus_type = UNKNOWN_BUS;
81 disk_ident.device_type = UNKNOWN_DEVICE;
82 disk_ident.device.unknown.size = device->Size();
83
84 for (int32 i = 0; i < NUM_DISK_CHECK_SUMS; i++) {
85 disk_ident.device.unknown.check_sums[i].offset = -1;
86 disk_ident.device.unknown.check_sums[i].sum = 0;
87 }
88
89 gBootVolume.SetData(BOOT_VOLUME_DISK_IDENTIFIER, B_RAW_TYPE,
90 &disk_ident, sizeof(disk_ident));
91
92 return B_OK;
93 }
94
95
96 void
platform_cleanup_devices()97 platform_cleanup_devices()
98 {
99 }
100