Some work on the userland boot loader test: moved over to new DoublyLinkedList,

added some command line options - additional boot images can now be listed as
arguments.
platform_run_menu() now prints out the root directories of all known file systems.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11237 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-02-03 18:30:29 +00:00
parent 338d4420a4
commit d399ab82cc
4 changed files with 136 additions and 10 deletions

View File

@ -5,6 +5,7 @@ UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
UsePrivateHeaders [ FDirName storage ] ;
UsePrivateHeaders [ FDirName shared ] ;
SubDirHdrs $(OBOS_TOP) headers private kernel arch $(OBOS_ARCH) ;
SubDirHdrs $(OBOS_TOP) src kernel boot loader ;
# we need to redefine certain calls in the boot loader so that
# they will really be used instead of their POSIX counterparts
@ -20,12 +21,18 @@ ObjectsDefines
menu.cpp
loader.cpp
kernel_args.cpp
load_driver_settings.cpp
# other
platform_menu.cpp
driver_settings.c
# partitions
amiga_rdb.cpp
apple.cpp
intel.cpp
PartitionMap.cpp
PartitionMapParser.cpp
:
read_pos=boot_read_pos fstat=boot_fstat open=boot_open close=boot_close main=boot_main
;
@ -74,6 +81,7 @@ SimpleTest BootLoaderTest :
menu.cpp
loader.cpp
kernel_args.cpp
load_driver_settings.cpp
# partitioning systems
amiga_rdb.cpp
@ -85,6 +93,7 @@ SimpleTest BootLoaderTest :
# utility functions - Dano has a strlcpy() function in libroot.so, while R5 has not
list.c
strlcpy.c
driver_settings.c
: boottest_bfs.a boottest_amiga_ffs.a
;
@ -97,11 +106,14 @@ SEARCH on [ FGristFiles list.c ]
SEARCH on [ FGristFiles strlcpy.c ]
= [ FDirName $(OBOS_TOP) src kernel libroot posix string ] ;
SEARCH on [ FGristFiles driver_settings.c ]
= [ FDirName $(OBOS_TOP) src kernel libroot os ] ;
SEARCH on [ FGristFiles
main.cpp vfs.cpp partitions.cpp
heap.cpp RootFileSystem.cpp
elf.cpp menu.cpp loader.cpp
kernel_args.cpp
kernel_args.cpp load_driver_settings.cpp
] = [ FDirName $(OBOS_TOP) src kernel boot loader ] ;
# partitioning system modules

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
@ -17,6 +17,12 @@
#include <stdio.h>
// we're using some libroot specials
extern int __libc_argc;
extern char **__libc_argv;
extern const char *__progname;
static status_t
get_device(const char *path, Node **_device)
{
@ -25,6 +31,9 @@ get_device(const char *path, Node **_device)
return B_NO_MEMORY;
if (device->InitCheck() != B_OK) {
fprintf(stderr, "%s: Could not open image \"%s\": %s\n",
__progname, path, strerror(device->InitCheck()));
delete device;
return B_ERROR;
}
@ -80,12 +89,56 @@ recursive_add_device(const char *path, NodeList *list)
}
static char *
get_next_argument(int32 *cookie, bool options)
{
int32 i = *cookie + 1;
if (i == 1 && !options) {
// filter out options at the start
while (i < __libc_argc && __libc_argv[i][0] == '-')
i++;
}
for (; i < __libc_argc; i++) {
// Options come at the start
if (options && __libc_argv[i][0] != '-')
return NULL;
*cookie = i;
return __libc_argv[i];
}
return NULL;
}
static char *
get_next_option(int32 *cookie)
{
return get_next_argument(cookie, true);
}
static char *
get_next_device(int32 *cookie)
{
return get_next_argument(cookie, false);
}
// #pragma mark -
status_t
platform_get_boot_device(struct stage2_args *args, Node **_device)
{
// we accept a boot device from the command line
int32 cookie = 0;
char *path = get_next_device(&cookie);
if (path != NULL)
return get_device(path, _device);
return get_device("/boot/home/test-file-device", _device);
}
@ -94,7 +147,7 @@ status_t
platform_get_boot_partition(struct stage2_args *args, Node *device,
NodeList *list, boot::Partition **_partition)
{
NodeIterator iterator = list->Iterator();
NodeIterator iterator = list->GetIterator();
boot::Partition *partition = NULL;
while ((partition = (boot::Partition *)iterator.Next()) != NULL) {
// just take the first partition
@ -109,9 +162,39 @@ platform_get_boot_partition(struct stage2_args *args, Node *device,
status_t
platform_add_block_devices(struct stage2_args *args, NodeList *list)
{
recursive_add_device("/dev/disk/ide", list);
recursive_add_device("/dev/disk/scsi", list);
recursive_add_device("/dev/disk/virtual", list);
int32 cookie = 0;
if (get_next_device(&cookie) != NULL) {
// add the devices provided on the command line
char *path;
while ((path = get_next_device(&cookie)) != NULL)
add_device(path, list);
}
bool addDevices = true;
bool scsi = true;
char *option;
cookie = 0;
while ((option = get_next_option(&cookie)) != NULL) {
if (!strcmp(option, "--no-devices"))
addDevices = false;
else if (!strcmp(option, "--no-scsi"))
scsi = false;
else {
fprintf(stderr, "usage: %s [OPTIONS] [image ...]\n"
" --no-devices\tDon't add real devices from /dev/disk\n"
" --no-scsi\tDon't add SCSI devices (might be problematic with some\n"
"\t\tUSB mass storage drivers)\n", __progname);
exit(0);
}
}
if (addDevices) {
recursive_add_device("/dev/disk/ide", list);
recursive_add_device("/dev/disk/virtual", list);
if (scsi)
recursive_add_device("/dev/disk/scsi", list);
}
return B_OK;
}

View File

@ -1,12 +1,21 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
* Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "RootFileSystem.h"
#include <boot/platform.h>
#include <boot/vfs.h>
#include <boot/menu.h>
#include <fcntl.h>
#include <stdio.h>
extern RootFileSystem *gRoot;
void
platform_add_menus(Menu *menu)
@ -23,5 +32,25 @@ platform_update_menu_item(Menu *menu, MenuItem *item)
void
platform_run_menu(Menu *menu)
{
puts("List of known root directories:");
void *cookie;
if (gRoot->Open(&cookie, O_RDONLY) == B_OK) {
Directory *directory;
while (gRoot->GetNextNode(cookie, (Node **)&directory) == B_OK) {
char name[256];
if (directory->GetName(name, sizeof(name)) == B_OK)
printf(":: %s (%p)\n", name, directory);
void *subCookie;
if (directory->Open(&subCookie, O_RDONLY) == B_OK) {
while (directory->GetNextEntry(subCookie, name, sizeof(name)) == B_OK) {
printf("\t%s\n", name);
}
directory->Close(subCookie);
}
}
gRoot->Close(cookie);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
@ -33,6 +33,8 @@ platform_start_kernel(void)
int
main(int argc, char **argv)
{
// The command arguments are evaluated in platform_devices.cpp!
boot_main(NULL);
return 0;