-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lk2nd: add boot module with extlinux support
Co-authored-by: Stephan Gerhold <[email protected]>
- Loading branch information
1 parent
bc751c9
commit 62e29d5
Showing
8 changed files
with
736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/* Copyright (c) 2023 Nikita Travkin <[email protected]> */ | ||
|
||
#include <debug.h> | ||
#include <list.h> | ||
#include <lib/bio.h> | ||
#include <lib/fs.h> | ||
#include <stdlib.h> | ||
#include <target.h> | ||
|
||
#include <lk2nd/boot.h> | ||
#include <lk2nd/hw/bdev.h> | ||
|
||
#include "boot.h" | ||
|
||
#ifndef LK2ND_BOOT_MIN_SIZE | ||
#define LK2ND_BOOT_MIN_SIZE (16 * 1024 * 1024) | ||
#endif | ||
|
||
/** | ||
* lk2nd_scan_devices() - Scan filesystems and try to boot | ||
*/ | ||
static void lk2nd_scan_devices(void) | ||
{ | ||
struct bdev_struct *bdevs = bio_get_bdevs(); | ||
char mountpoint[16]; | ||
bdev_t *bdev; | ||
int ret; | ||
|
||
dprintf(INFO, "boot: Trying to boot from the file system...\n"); | ||
|
||
list_for_every_entry(&bdevs->list, bdev, bdev_t, node) { | ||
|
||
/* Skip top level block devices. */ | ||
if (!bdev->is_leaf) | ||
continue; | ||
|
||
/* Skip partitions that are too small to have a boot fs on. */ | ||
if (bdev->size < LK2ND_BOOT_MIN_SIZE) | ||
continue; | ||
|
||
snprintf(mountpoint, sizeof(mountpoint), "/%s", bdev->name); | ||
ret = fs_mount(mountpoint, "ext2", bdev->name); | ||
if (ret < 0) | ||
continue; | ||
|
||
if (DEBUGLEVEL >= SPEW) { | ||
dprintf(SPEW, "Scanning %s ...\n", bdev->name); | ||
dprintf(SPEW, "%s\n", mountpoint); | ||
lk2nd_print_file_tree(mountpoint, " "); | ||
} | ||
|
||
lk2nd_try_extlinux(mountpoint); | ||
} | ||
} | ||
|
||
/** | ||
* lk2nd_boot() - Try to boot the OS. | ||
* | ||
* This method is supposed to be called from aboot. | ||
* If appropriate OS is found, it will be booted, and this | ||
* method will never return. | ||
*/ | ||
void lk2nd_boot(void) | ||
{ | ||
static bool init_done = false; | ||
|
||
if (!init_done) { | ||
lk2nd_bdev_init(); | ||
init_done = true; | ||
} | ||
|
||
lk2nd_scan_devices(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause */ | ||
#ifndef LK2ND_BOOT_BOOT_H | ||
#define LK2ND_BOOT_BOOT_H | ||
|
||
#include <list.h> | ||
#include <string.h> | ||
|
||
#include <lk2nd/boot.h> | ||
|
||
/* util.c */ | ||
void lk2nd_print_file_tree(char *root, char *prefix); | ||
|
||
/* extlinux.c */ | ||
void lk2nd_try_extlinux(const char *mountpoint); | ||
|
||
#endif /* LK2ND_BOOT_BOOT_H */ |
Oops, something went wrong.