nkk71

mrom no kexec main part

Nov 30th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.68 KB | None | 0 0
  1.         // nkk71: check for kexec support, otherwise use workaround
  2.         if (!multirom_has_kexec())
  3.         {
  4.             //==========================================================================================================================
  5.             // nkk71: workaround for lack of kexec-hb support:
  6.             // flash correct kernel to primary slot,
  7.             // initiate a reboot, and autoboot the ROM
  8.             if (s.is_second_boot == 0)
  9.             {
  10.                 char path_bootimg[500];
  11.                 char path_boot_mmcblk[500];
  12.  
  13.                 // find kernel mmcblk
  14.                 sprintf(path_boot_mmcblk, "/dev/block/platform/msm_sdcc.1/by-name/boot");
  15.                 ERROR("nkk71: boot mmcblk=%s\n",path_boot_mmcblk);
  16.  
  17.                 // primary boot.img
  18.                 sprintf(path_bootimg, "%s/primary_boot.img", s.roms[0]->base_path);
  19.                 ERROR("nkk71: primary_boot.img=%s\n",path_bootimg);
  20.  
  21.                 if (to_boot->type != ROM_DEFAULT)
  22.                 {
  23.                     FILE *fp1, *fp2;
  24.  
  25.                     // check if primary rom boot.img is backed up
  26.                     if (fp1 = fopen(path_bootimg, "r"))
  27.                     {
  28.                         // it's there, compare them maybe it's a new primary boot.img
  29.                         int ch1, ch2;
  30.  
  31.                         fp2 = fopen(path_boot_mmcblk, "r");
  32.      
  33.                         ch1 = getc(fp1);
  34.                         ch2 = getc(fp2);
  35.      
  36.                         while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2))
  37.                         {
  38.                             ch1 = getc(fp1);
  39.                             ch2 = getc(fp2);
  40.                         }
  41.                         fclose(fp1);
  42.                         fclose(fp2);
  43.      
  44.                         if (ch1 != ch2)
  45.                         {
  46.                             // looks like a new primary boot.img, so back it up (replacing the old one)
  47.                             ERROR("nkk71: backing up NEW primary boot.img; res=%d\n", copy_file(path_boot_mmcblk, path_bootimg));
  48.                         }
  49.                     }
  50.                     else
  51.                     {
  52.                         // it's not there, so backup primary boot.img
  53.                         ERROR("nkk71: backing up primary boot.img; res=%d\n", copy_file(path_boot_mmcblk, path_bootimg));
  54.                     }
  55.  
  56.                     // now flash the secondary boot.img to primary slot
  57.                     sprintf(path_bootimg, "%s/boot.img", to_boot->base_path);
  58.                     ERROR("nkk71: copy boot.img to primary slot; res=%d\n", copy_file(path_bootimg, path_boot_mmcblk));
  59.                 }
  60.                 else
  61.                 {
  62.                     // restore primay boot.img
  63.                     ERROR("nkk71: restore primary boot.img; res=%d\n", copy_file(path_bootimg, path_boot_mmcblk));
  64.                 }
  65.             }
  66.             // nkk71: end of workaround (boot.img flashing), later below, we'll set second_boot true, and ask for a full reboot
  67.             //==========================================================================================================================
  68.         }
  69.  
  70.         exit = multirom_prepare_for_boot(&s, to_boot);
  71.  
  72.         // Something went wrong, exit/reboot
  73.         if(exit == -1)
  74.         {
  75.             if(rom_to_boot == NULL)
  76.             {
  77.                 multirom_emergency_reboot();
  78.                 exit = EXIT_REBOOT;
  79.             }
  80.             else
  81.                 exit = EXIT_UMOUNT;
  82.             goto finish;
  83.         }
  84.  
  85.         s.current_rom = to_boot;
  86.  
  87.         free(s.curr_rom_part);
  88.         s.curr_rom_part = NULL;
  89.  
  90.         if(to_boot->partition)
  91.             s.curr_rom_part = strdup(to_boot->partition->uuid);
  92.  
  93.         if(s.is_second_boot == 0 && (M(to_boot->type) & MASK_ANDROID) && (exit & EXIT_KEXEC))
  94.         {
  95.             s.is_second_boot = 1;
  96.  
  97.             // mrom_kexecd=1 param might be lost if kernel does not have kexec patches
  98.             ERROR(SECOND_BOOT_KMESG);
  99.         }
  100.         else
  101.  
  102.         // nkk71: check for kexec support, otherwise use workaround
  103.         if (!multirom_has_kexec())
  104.         {
  105.             if (s.is_second_boot == 0 && ((M(to_boot->type) & MASK_ANDROID) || (to_boot->type == ROM_DEFAULT)))
  106.             {
  107.                 // nkk71: force a full reboot (due to kernel flashing from above), then autoboot the ROM
  108.                 s.is_second_boot = 1;
  109.                 exit = (EXIT_REBOOT | EXIT_UMOUNT);
  110.                 ERROR("nkk71: go for reboot second_boot!\n");
  111.                 ERROR(SECOND_BOOT_KMESG); // go for second_boot = 1
  112.             }
  113.         }
  114.  
  115.         else
  116.             s.is_second_boot = 0;
  117.     }
Advertisement
Add Comment
Please, Sign In to add comment