Skip to content

Commit

Permalink
lk2nd: boot: add extlinux support
Browse files Browse the repository at this point in the history
  • Loading branch information
TravMurav committed Aug 8, 2023
1 parent 97619fe commit 5947da9
Show file tree
Hide file tree
Showing 12 changed files with 620 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/aboot/aboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
#if WITH_LK2ND_DISPLAY_MENU
#include <lk2nd/menu.h>
#endif
#if WITH_LK2ND_BOOT
#include <lk2nd/boot.h>
#endif

extern bool target_use_signed_kernel(void);
extern void platform_uninit(void);
Expand Down Expand Up @@ -5632,6 +5635,11 @@ void aboot_init(const struct app_descriptor *app)
normal_boot:
if (!boot_into_fastboot)
{
#if WITH_LK2ND_BOOT
if (!boot_into_recovery)
lk2nd_boot();
#endif

if (target_is_emmc_boot())
{
if(!IS_ENABLED(ABOOT_STANDALONE) && emmc_recovery_init())
Expand Down
59 changes: 59 additions & 0 deletions lk2nd/boot/boot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright (c) 2023 Nikita Travkin <[email protected]> */

#include <stdlib.h>
#include <debug.h>
#include <target.h>
#include <list.h>
#include <lib/bio.h>
#include <lib/fs.h>

#include <lk2nd/boot.h>

#include "boot.h"

/**
* 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...\n");

list_for_every_entry(&bdevs->list, bdev, bdev_t, node) {

/* Skip top level block devices. */
if (!bdev->is_subdev)
continue;

snprintf(mountpoint, sizeof(mountpoint), "/%s", bdev->name);
ret = fs_mount(mountpoint, "ext2", bdev->name);
if (ret < 0)
continue;

/* TODO: THIS MUST BE DEBUG ONLY!!! */
dprintf(INFO, "Scanning %s ...\n", bdev->name);
dprintf(INFO, "%s\n", mountpoint);
//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)
{
lk2nd_boot_dump_devices();
dprintf(INFO, "boot: Trying to boot from the file system\n");
lk2nd_scan_devices();
}
17 changes: 17 additions & 0 deletions lk2nd/boot/boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* 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_boot_dump_devices(void);
void print_file_tree(char *root, char *prefix);

/* extlinux.c */
void lk2nd_try_extlinux(const char *mountpoint);

#endif /* LK2ND_BOOT_BOOT_H */
Loading

0 comments on commit 5947da9

Please sign in to comment.