|
55 | 55 | #include "rom_quirks.h"
|
56 | 56 | #include "kexec.h"
|
57 | 57 |
|
| 58 | +#ifdef MR_NO_KEXEC |
| 59 | +#include "no_kexec.h" |
| 60 | +#endif |
| 61 | + |
| 62 | + |
58 | 63 | #define REALDATA "/realdata"
|
59 | 64 | #define BUSYBOX_BIN "busybox"
|
60 | 65 | #define KEXEC_BIN "kexec"
|
@@ -260,6 +265,23 @@ int multirom(const char *rom_to_boot)
|
260 | 265 | struct multirom_rom *to_boot = NULL;
|
261 | 266 | int exit = (EXIT_REBOOT | EXIT_UMOUNT);
|
262 | 267 |
|
| 268 | +#ifdef MR_NO_KEXEC |
| 269 | + // setup global variables here |
| 270 | + nokexec_set_struct(&s); |
| 271 | + |
| 272 | + |
| 273 | + // check if a partition mount failed, in which case multirom usually just boots internal |
| 274 | + if (s.current_rom->type == ROM_DEFAULT && nokexec_is_second_boot()) |
| 275 | + { |
| 276 | + ERROR("NO_KEXEC: Something went wrong in mounting the needed partition, so falling back..."); |
| 277 | + nokexec()->selected_method = NO_KEXEC_BOOT_NORMAL; |
| 278 | + s.is_second_boot = 0; |
| 279 | + //ERROR("NO_KEXEC: to Internal\n"); s.auto_boot_type = AUTOBOOT_FORCE_CURRENT; // force reboot to Internal (this would be mrom default behaviour) |
| 280 | + //ERROR("NO_KEXEC: to MultiROM GUI\n"); s.auto_boot_type = AUTOBOOT_NAME; // bring up the gui instead |
| 281 | + ERROR("NO_KEXEC: to Recovery\n"); exit = (EXIT_REBOOT_RECOVERY | EXIT_UMOUNT); goto finish; // reboot to recovery |
| 282 | + } |
| 283 | +#endif |
| 284 | + |
263 | 285 | if(rom_to_boot != NULL)
|
264 | 286 | {
|
265 | 287 | struct multirom_rom *rom = multirom_get_rom(&s, rom_to_boot, NULL);
|
@@ -320,6 +342,42 @@ int multirom(const char *rom_to_boot)
|
320 | 342 | {
|
321 | 343 | s.auto_boot_type &= ~(AUTOBOOT_FORCE_CURRENT);
|
322 | 344 |
|
| 345 | +#ifdef MR_NO_KEXEC |
| 346 | + #define MR_NO_KEXEC_ABORT { \ |
| 347 | + ERROR("NO_KEXEC: ERROR occurred in the above, aborting to recovery\n"); \ |
| 348 | + exit = (EXIT_REBOOT_RECOVERY | EXIT_UMOUNT); goto finish; \ |
| 349 | + } |
| 350 | + |
| 351 | + if (s.is_second_boot != 0) |
| 352 | + { |
| 353 | + // Restore primary boot.img, and continue |
| 354 | + if (nokexec_restore_primary_and_cleanup() < 0) |
| 355 | + MR_NO_KEXEC_ABORT; |
| 356 | + } |
| 357 | + else |
| 358 | + { |
| 359 | + if ((to_boot->type != ROM_DEFAULT) && to_boot->has_bootimg) |
| 360 | + { |
| 361 | + // Flash secondary boot.img, and reboot |
| 362 | + // note: a secondary boot.img in primary slot will trigger second_boot=1 |
| 363 | + // so we don't need to worry about that any more |
| 364 | + if (nokexec_flash_secondary_bootimg(to_boot) < 0) |
| 365 | + MR_NO_KEXEC_ABORT; |
| 366 | + |
| 367 | + s.current_rom = to_boot; |
| 368 | + |
| 369 | + free(s.curr_rom_part); |
| 370 | + s.curr_rom_part = NULL; |
| 371 | + |
| 372 | + if(to_boot->partition) |
| 373 | + s.curr_rom_part = strdup(to_boot->partition->uuid); |
| 374 | + |
| 375 | + exit = (EXIT_REBOOT | EXIT_UMOUNT); |
| 376 | + goto finish; |
| 377 | + } |
| 378 | + } |
| 379 | +#endif |
| 380 | + |
323 | 381 | if(rom_to_boot == NULL)
|
324 | 382 | multirom_run_scripts("run-on-boot", to_boot);
|
325 | 383 |
|
@@ -358,6 +416,9 @@ int multirom(const char *rom_to_boot)
|
358 | 416 | }
|
359 | 417 |
|
360 | 418 | finish:
|
| 419 | +#ifdef MR_NO_KEXEC |
| 420 | + nokexec_free_struct(); |
| 421 | +#endif |
361 | 422 | if (s.enable_kmsg_logging != 0)
|
362 | 423 | multirom_kmsg_logging(BACKUP_LATE_KLOG);
|
363 | 424 | multirom_save_status(&s);
|
@@ -515,6 +576,9 @@ int multirom_default_status(struct multirom_status *s)
|
515 | 576 | s->is_second_boot = 0;
|
516 | 577 | s->current_rom = NULL;
|
517 | 578 | s->roms = NULL;
|
| 579 | +#ifdef MR_NO_KEXEC |
| 580 | + s->no_kexec = MR_NO_KEXEC; |
| 581 | +#endif |
518 | 582 | s->colors = 0;
|
519 | 583 | s->brightness = MULTIROM_DEFAULT_BRIGHTNESS;
|
520 | 584 | s->enable_adb = 0;
|
@@ -657,6 +721,10 @@ int multirom_load_status(struct multirom_status *s)
|
657 | 721 | s->auto_boot_type = atoi(arg);
|
658 | 722 | else if(strstr(name, "curr_rom_part"))
|
659 | 723 | s->curr_rom_part = strdup(arg);
|
| 724 | +#ifdef MR_NO_KEXEC |
| 725 | + else if(strstr(name, "no_kexec")) |
| 726 | + s->no_kexec = atoi(arg); |
| 727 | +#endif |
660 | 728 | else if(strstr(name, "colors_v2"))
|
661 | 729 | s->colors = atoi(arg);
|
662 | 730 | else if(strstr(name, "brightness"))
|
@@ -764,6 +832,9 @@ int multirom_save_status(struct multirom_status *s)
|
764 | 832 | fprintf(f, "auto_boot_rom=%s\n", auto_boot_name);
|
765 | 833 | fprintf(f, "auto_boot_type=%d\n", s->auto_boot_type);
|
766 | 834 | fprintf(f, "curr_rom_part=%s\n", s->curr_rom_part ? s->curr_rom_part : "");
|
| 835 | +#ifdef MR_NO_KEXEC |
| 836 | + fprintf(f, "no_kexec=%d\n", s->no_kexec); |
| 837 | +#endif |
767 | 838 | fprintf(f, "colors_v2=%d\n", s->colors);
|
768 | 839 | fprintf(f, "brightness=%d\n", s->brightness);
|
769 | 840 | fprintf(f, "enable_adb=%d\n", s->enable_adb);
|
@@ -799,6 +870,9 @@ void multirom_dump_status(struct multirom_status *s)
|
799 | 870 | INFO(" is_second_boot=%d\n", s->is_second_boot);
|
800 | 871 | INFO(" is_running_in_primary_rom=%d\n", s->is_running_in_primary_rom);
|
801 | 872 | INFO(" current_rom=%s\n", s->current_rom ? s->current_rom->name : "NULL");
|
| 873 | +#ifdef MR_NO_KEXEC |
| 874 | + INFO(" no_kexec=%d\n", s->no_kexec); |
| 875 | +#endif |
802 | 876 | INFO(" colors_v2=%d\n", s->colors);
|
803 | 877 | INFO(" brightness=%d\n", s->brightness);
|
804 | 878 | INFO(" enable_adb=%d\n", s->enable_adb);
|
@@ -1105,7 +1179,12 @@ int multirom_prepare_for_boot(struct multirom_status *s, struct multirom_rom *to
|
1105 | 1179 | int exit = EXIT_UMOUNT;
|
1106 | 1180 | int type = to_boot->type;
|
1107 | 1181 |
|
| 1182 | + |
| 1183 | +#ifndef MR_NO_KEXEC |
1108 | 1184 | if(((M(type) & MASK_KEXEC) || to_boot->has_bootimg) && type != ROM_DEFAULT && s->is_second_boot == 0)
|
| 1185 | +#else |
| 1186 | + if(((M(type) & MASK_KEXEC) || (to_boot->has_bootimg && (nokexec()->selected_method == NO_KEXEC_BOOT_NORMAL))) && type != ROM_DEFAULT && s->is_second_boot == 0) |
| 1187 | +#endif |
1109 | 1188 | {
|
1110 | 1189 | if(multirom_load_kexec(s, to_boot) != 0)
|
1111 | 1190 | return -1;
|
@@ -1686,7 +1765,12 @@ int multirom_get_bootloader_cmdline(struct multirom_status *s, char *str, size_t
|
1686 | 1765 | *c = ' ';
|
1687 | 1766 |
|
1688 | 1767 | // Remove the part from boot.img
|
| 1768 | +//#ifndef MR_NO_KEXEC |
1689 | 1769 | if(s->is_running_in_primary_rom || !s->current_rom || !s->current_rom->has_bootimg)
|
| 1770 | +//#else |
| 1771 | +// // probably not needed, but for consistency |
| 1772 | +// if(s->is_running_in_primary_rom || !s->current_rom || !(s->current_rom->has_bootimg && (nokexec()->selected_method == NO_KEXEC_BOOT_KEXEC))) |
| 1773 | +//#endif |
1690 | 1774 | {
|
1691 | 1775 | boot = fstab_find_first_by_path(s->fstab, "/boot");
|
1692 | 1776 | if(boot && libbootimg_load_header(&hdr, boot->device) >= 0)
|
|
0 commit comments