:: commit e5f2b2c0852ceb31f1a4d250e88732922148d495

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

parents: d8180342f0

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

diff --git a/limine-deploy/limine-deploy.c b/limine-deploy/limine-deploy.c
index b324e949..e32c00d7 100644
--- a/limine-deploy/limine-deploy.c
+++ b/limine-deploy/limine-deploy.c
@@ -428,8 +428,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 {
@@ -439,6 +442,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 {
@@ -448,6 +452,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 {
@@ -457,6 +462,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 {
@@ -465,6 +471,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) {
@@ -506,25 +519,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