:: commit 4e23f005c9bb7f325787079bafa067e4b202d4e0

mintsuki <mintsuki@protonmail.com> — 2020-12-29 00:01

parents: 3f3971415d

uri: Make boot resource be an alias of tftp of booted off PXE

diff --git a/CONFIG.md b/CONFIG.md
index 19d8e2e0..4425b61d 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -104,7 +104,7 @@ resource://root/path
 The format for `root` changes depending on the resource used.
 
 A resource can be one of the following:
-* `boot` - The `root` is the 1-based decimal value representing the partition on the boot drive (values of 5+ for MBR logical partitions). If omitted, the partition containing the configuration file on the boot drive is used. For example: `boot://2/...` will use partition 2 of the boot drive and `boot:///...` will use the partition containing the config file on the boot drive.
+* `boot` - If booted off PXE this is an alias of `tftp`. Else the `root` is the 1-based decimal value representing the partition on the boot drive (values of 5+ for MBR logical partitions). If omitted, the partition containing the configuration file on the boot drive is used. For example: `boot://2/...` will use partition 2 of the boot drive and `boot:///...` will use the partition containing the config file on the boot drive.
 * `bios` - The `root` takes the form of `drive:partition`; for example: `bios://3:1/...` would use BIOS drive 3, partition 1. Partitions and BIOS drives are both 1-based (partition values of 5+ for MBR logical partitions). Omitting the drive is possible; for example: `bios://:2/...`. Omitting the drive makes Limine use the boot drive.
 * `guid` - The `root` takes the form of a GUID/UUID, such as `guid://736b5698-5ae1-4dff-be2c-ef8f44a61c52/...`. The GUID is that of either a filesystem, when available, or a GPT partition GUID, when using GPT, in a unified namespace.
 * `uuid` - Alias of `guid`.
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 5cfe58a7..7ed24641 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 25b1fbce..a4979175 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 1d181e33..80962933 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/blib.c b/stage2/lib/blib.c
index fde7dd39..fa391d9f 100644
--- a/stage2/lib/blib.c
+++ b/stage2/lib/blib.c
@@ -10,6 +10,8 @@
 uint8_t boot_drive;
 int     boot_partition = -1;
 
+bool booted_from_pxe = false;
+
 bool parse_resolution(int *width, int *height, int *bpp, const char *buf) {
     int res[3] = {0};
 
diff --git a/stage2/lib/blib.h b/stage2/lib/blib.h
index 5cf9ceb1..0d327b01 100644
--- a/stage2/lib/blib.h
+++ b/stage2/lib/blib.h
@@ -8,6 +8,8 @@
 extern uint8_t boot_drive;
 extern int     boot_partition;
 
+extern bool booted_from_pxe;
+
 bool parse_resolution(int *width, int *height, int *bpp, const char *buf);
 
 uint64_t sqrt(uint64_t a_nInput);
diff --git a/stage2/lib/uri.c b/stage2/lib/uri.c
index e4fab567..9e4b558f 100644
--- a/stage2/lib/uri.c
+++ b/stage2/lib/uri.c
@@ -91,33 +91,6 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
     return true;
 }
 
-static bool uri_boot_dispatch(struct file_handle *fd, char *s_part, char *path) {
-    uint8_t partition;
-
-    if (s_part[0] != '\0') {
-        uint64_t val = strtoui(s_part, NULL, 10);
-        if (val < 1 || val > 256) {
-            panic("Partition number outside range 1-256");
-        }
-        partition = val - 1;
-    } else {
-        if (boot_partition != -1) {
-            partition = boot_partition;
-        } else {
-            panic("Boot partition information is unavailable.");
-        }
-    }
-
-    struct part part;
-    if (part_get(&part, boot_drive, partition))
-        return false;
-
-    if (fopen(fd, &part, path))
-        return false;
-
-    return true;
-}
-
 static bool uri_bios_dispatch(struct file_handle *fd, char *loc, char *path) {
     uint8_t drive, partition;
 
@@ -171,6 +144,36 @@ static bool uri_tftp_dispatch(struct file_handle *fd, char *root, char *path) {
     return true;
 }
 
+static bool uri_boot_dispatch(struct file_handle *fd, char *s_part, char *path) {
+    if (booted_from_pxe)
+        return uri_tftp_dispatch(fd, s_part, path);
+
+    uint8_t partition;
+
+    if (s_part[0] != '\0') {
+        uint64_t val = strtoui(s_part, NULL, 10);
+        if (val < 1 || val > 256) {
+            panic("Partition number outside range 1-256");
+        }
+        partition = val - 1;
+    } else {
+        if (boot_partition != -1) {
+            partition = boot_partition;
+        } else {
+            panic("Boot partition information is unavailable.");
+        }
+    }
+
+    struct part part;
+    if (part_get(&part, boot_drive, partition))
+        return false;
+
+    if (fopen(fd, &part, path))
+        return false;
+
+    return true;
+}
+
 static int mem_read(void *fd, void *buf, uint64_t loc, uint64_t count) {
     memcpy(buf, fd + loc, count);
     return 0;
diff --git a/stage2/main.c b/stage2/main.c
index ecbdf1ae..45a32f11 100644
--- a/stage2/main.c
+++ b/stage2/main.c
@@ -26,6 +26,8 @@ void entry(uint8_t _boot_drive, int pxe_boot, void *_tinf_gzip_uncompress) {
     boot_drive = _boot_drive;
     tinf_gzip_uncompress = _tinf_gzip_uncompress;
 
+    booted_from_pxe = pxe_boot;
+
     mtrr_save();
 
     term_textmode();
tab: 248 wrap: offon