:: commit e3519a6cfa4206fcdc1c1d1a5ad4d27ba7f24d90

mintsuki <mintsuki@protonmail.com> — 2020-11-09 14:04

parents: 92814b4728

misc: Change config location detection mechanism slightly

diff --git a/CONFIG.md b/CONFIG.md
index 88f182e4..8870ab41 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -1,5 +1,19 @@
 # Limine configuration file
 
+## Location of the config file
+
+Limine scans for a config file on *the boot drive*. Every partition on the boot drive
+is scanned sequentially (first partition first, last partition last) for the presence
+of either a `/limine.cfg` or a `/boot/limine.cfg` file, in that order.
+
+Once the file is located, Limine will use it as its config file. Other possible
+candidates in subsequent partitions or directories are ignored.
+
+It is thus imperative that the intended config file is placed in a location that will
+not be shadowed by another potentially candidate config file.
+
+## Structure of the config file
+
 The Limine configuration file is comprised of *assignments* and *entries*.
 
 *Entries* describe boot *entries* which the user can select in the *boot menu*.
diff --git a/README.md b/README.md
index f3dc56c4..0b66e108 100644
--- a/README.md
+++ b/README.md
@@ -94,9 +94,12 @@ number (in decimal).
 
 ```bash
 fdisk <device>    # Create bootloader partition using your favourite method
-limine-install <bootloader image> <path to device/image> <start sector of boot partition>
+limine-install <bootloader image> <path to device/image> <start sector of boot partition> <sector size>
 ```
 
+The `<sector size>` argument is optional. Use it to specify the sector size in bytes
+if it is not Limine's expected default of 512 bytes.
+
 ### Configuration
 Then make sure the device/image contains at least 1 partition formatted in
 a supported filesystem containing a `/limine.cfg` or `/boot/limine.cfg` file
@@ -123,14 +126,13 @@ echfs-utils -m -p0 test.img import path/to/kernel.elf kernel.elf
 echfs-utils -m -p0 test.img import <path to file> <path in image>
 ...
 limine-install test.img
-
 ```
 
 One can get `echfs-utils` by installing https://github.com/qword-os/echfs.
 
 ## Acknowledgments
-Limine uses a stripped-down version of https://github.com/jibsen/tinf
+Limine uses a stripped-down version of [tinf](https://github.com/jibsen/tinf).
 
 ## Discord server
-We have a Discord server if you need support, info, or you just want to
-hang out: https://discord.gg/QEeZMz4
+We have a [Discord server](https://discord.gg/QEeZMz4) if you need support, info, or
+you just want to hang out with us.
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 2cec51e0..26504629 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 8298c90f..bc9b99cf 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/lib/part.c b/stage2/lib/part.c
index a905919d..b8d326ed 100644
--- a/stage2/lib/part.c
+++ b/stage2/lib/part.c
@@ -9,10 +9,6 @@
 #include <mm/pmm.h>
 #include <fs/file.h>
 
-#define NO_PARTITION  (-1)
-#define INVALID_TABLE (-2)
-#define END_OF_TABLE  (-3)
-
 struct gpt_table_header {
     // the head
     char     signature[8];
@@ -155,7 +151,7 @@ int part_get(struct part *part, int drive, int partition) {
     if (ret != INVALID_TABLE)
         return ret;
 
-    return -1;
+    return INVALID_TABLE;
 }
 
 static struct part *part_index = NULL;
diff --git a/stage2/lib/part.h b/stage2/lib/part.h
index c7848160..4fb9b08d 100644
--- a/stage2/lib/part.h
+++ b/stage2/lib/part.h
@@ -5,6 +5,10 @@
 #include <stdbool.h>
 #include <lib/guid.h>
 
+#define NO_PARTITION  (-1)
+#define INVALID_TABLE (-2)
+#define END_OF_TABLE  (-3)
+
 struct part {
     int drive;
     int partition;
diff --git a/stage2/main.c b/stage2/main.c
index 3c4e0218..dfdd9d4e 100644
--- a/stage2/main.c
+++ b/stage2/main.c
@@ -46,21 +46,23 @@ void entry(uint8_t _boot_drive, int pxe_boot) {
         print("Boot drive: %x\n", boot_drive);
         // Look for config file.
         print("Searching for config file...\n");
-        struct part parts[4];
         for (int i = 0; ; i++) {
-            if (i == 4) {
-                panic("Config file not found.");
-            }
+            struct part part;
             print("Checking partition %d...\n", i);
-            int ret = part_get(&parts[i], boot_drive, i);
-            if (ret) {
-                print("Partition not found.\n");
-            } else {
-                print("Partition found.\n");
-                if (!init_config_disk(&parts[i])) {
-                    print("Config file found and loaded.\n");
-                    break;
-                }
+            int ret = part_get(&part, boot_drive, i);
+            switch (ret) {
+                case INVALID_TABLE:
+                    panic("Partition table of boot drive is invalid.");
+                case END_OF_TABLE:
+                    panic("Config file not found.");
+                case NO_PARTITION:
+                    print("Partition not found.\n");
+                    continue;
+            }
+            print("Partition found.\n");
+            if (!init_config_disk(&part)) {
+                print("Config file found and loaded.\n");
+                break;
             }
         }
     }
tab: 248 wrap: offon