:: commit 0d0d2a00fcc9b4de322929fcc981846655efa5c4

mintsuki <mintsuki@protonmail.com> — 2022-04-15 17:46

parents: 0e1e88aa37

limine-deploy: Do not mark any protective MBR partition as active

diff --git a/limine-install/limine-install.c b/limine-install/limine-install.c
index 1a7dc200..b5f28cbb 100644
--- a/limine-install/limine-install.c
+++ b/limine-install/limine-install.c
@@ -420,8 +420,11 @@ int main(int argc, char *argv[]) {
             }
         }
 
+        bool any_active = false;
+
         device_read(&hint8, 446, sizeof(uint8_t));
         if (hint8 != 0x00 && hint8 != 0x80) {
+            any_active = any_active ? any_active : (hint8 & 0x80) != 0;
             if (!force_mbr) {
                 mbr = 0;
             } else {
@@ -431,6 +434,7 @@ int main(int argc, char *argv[]) {
         }
         device_read(&hint8, 462, sizeof(uint8_t));
         if (hint8 != 0x00 && hint8 != 0x80) {
+            any_active = any_active ? any_active : (hint8 & 0x80) != 0;
             if (!force_mbr) {
                 mbr = 0;
             } else {
@@ -440,6 +444,7 @@ int main(int argc, char *argv[]) {
         }
         device_read(&hint8, 478, sizeof(uint8_t));
         if (hint8 != 0x00 && hint8 != 0x80) {
+            any_active = any_active ? any_active : (hint8 & 0x80) != 0;
             if (!force_mbr) {
                 mbr = 0;
             } else {
@@ -449,6 +454,7 @@ int main(int argc, char *argv[]) {
         }
         device_read(&hint8, 494, sizeof(uint8_t));
         if (hint8 != 0x00 && hint8 != 0x80) {
+            any_active = any_active ? any_active : (hint8 & 0x80) != 0;
             if (!force_mbr) {
                 mbr = 0;
             } else {
@@ -457,6 +463,13 @@ int main(int argc, char *argv[]) {
             }
         }
 
+        if (!any_active) {
+            fprintf(stderr, "No active partition found, some systems may not boot.\n");
+            fprintf(stderr, "Setting partition 1 as active to work around the issue...\n");
+            hint8 = 0x80;
+            device_write(&hint8, 446, sizeof(uint8_t));
+        }
+
         char hintc[64];
         device_read(hintc, 4, 8);
         if (memcmp(hintc, "_ECH_FS_", 8) == 0) {
@@ -498,25 +511,6 @@ int main(int argc, char *argv[]) {
         goto cleanup;
     }
 
-    bool any_active = false;
-    uint8_t hint8;
-
-    device_read(&hint8, 446, sizeof(uint8_t));
-    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
-    device_read(&hint8, 462, sizeof(uint8_t));
-    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
-    device_read(&hint8, 478, sizeof(uint8_t));
-    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
-    device_read(&hint8, 494, sizeof(uint8_t));
-    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
-
-    if (!any_active) {
-        fprintf(stderr, "No active MBR partition found, some systems may not boot.\n");
-        fprintf(stderr, "Setting partition 1 as active to work around the issue...\n");
-        hint8 = 0x80;
-        device_write(&hint8, 446, sizeof(uint8_t));
-    }
-
     size_t   stage2_size   = bootloader_file_size - 512;
 
     size_t   stage2_sects  = DIV_ROUNDUP(stage2_size, 512);
tab: 248 wrap: offon