示例#1
0
EFI_STATUS
SettingsMenuShow (
  VOID
)
{
  MENU_ENTRY *Entry;
  MENU_OPTION* Menu;

  // create menu
  Menu = MenuCreate();
  Menu->Title = AsciiStrDup("Settings");
  Menu->BackCallback = SettingsMenuBackCallback;

  // UEFI options
  Entry = MenuCreateEntry();
  Entry->Name = AsciiStrDup("Show UEFI boot options");
  Entry->ShowToggle = TRUE;
  Entry->ToggleEnabled = SettingBoolGet("ui-show-uefi-options");
  Entry->HideBootMessage = TRUE;
  Entry->Callback = ShowUEFIOptionsCallback;
  MenuAddEntry(Menu, Entry);

  // file explorer
  Entry = MenuCreateEntry();
  Entry->Name = AsciiStrDup("Show File Explorer");
  Entry->ShowToggle = TRUE;
  Entry->ToggleEnabled = SettingBoolGet("ui-show-file-explorer");
  Entry->HideBootMessage = TRUE;
  Entry->Callback = ShowFileExplorerCallback;
  MenuAddEntry(Menu, Entry);

  // fastboot
  Entry = MenuCreateEntry();
  Entry->Name = AsciiStrDup("Show Fastboot");
  Entry->ShowToggle = TRUE;
  Entry->ToggleEnabled = SettingBoolGet("ui-show-fastboot");
  Entry->HideBootMessage = TRUE;
  Entry->Callback = ShowFastbootCallback;
  MenuAddEntry(Menu, Entry);

  // fastboot
  Entry = MenuCreateEntry();
  Entry->Name = AsciiStrDup("Force selinux to permissive");
  Entry->ShowToggle = TRUE;
  Entry->ToggleEnabled = SettingBoolGet("boot-force-permissive");
  Entry->HideBootMessage = TRUE;
  Entry->Callback = ShowPermissiveCallback;
  MenuAddEntry(Menu, Entry);

  MenuStackPush(Menu);
  return EFI_SUCCESS;
}
VOID
FastbootAddInternalROM (
  VOID
)
{
  LIBAROMA_STREAMP      Icon;
  CONST CHAR8           *InternalROMIconPath;

  // get icon
  InternalROMIconPath = AndroidLocatorGetInternalROMIconPath();
  if(InternalROMIconPath)
    Icon = libaroma_stream_ramdisk(InternalROMIconPath);
  else
    Icon = libaroma_stream_ramdisk("icons/android.png");

  // create entry
  MENU_ENTRY* NewEntry = MenuCreateEntry();
  if(NewEntry==NULL)
    return;
  NewEntry->Name = AllocateZeroPool(4096);
  if(NewEntry->Name)
    AsciiSPrint(NewEntry->Name, 4096, "%a (Internal)", AndroidLocatorGetInternalROMName()?:"Android");
  NewEntry->Icon = Icon;
  NewEntry->Callback = FastbootStartCallback;
  NewEntry->HideBootMessage = TRUE;

  MenuAddEntry(mFastbootMenu, NewEntry);
}
示例#3
0
EFI_STATUS
SettingsMenuShow (
  VOID
)
{
  MENU_ENTRY *Entry;
  MENU_OPTION* Menu;

  // create menu
  Menu = MenuCreate();
  Menu->Title = AsciiStrDup("Settings");
  Menu->BackCallback = SettingsMenuBackCallback;

  // file explorer
  Entry = MenuCreateEntry();
  Entry->Name = AsciiStrDup("Show File Explorer");
  Entry->ShowToggle = TRUE;
  Entry->ToggleEnabled = SettingBoolGet("ui-show-file-explorer");
  Entry->HideBootMessage = TRUE;
  Entry->Callback = ShowFileExplorerCallback;
  MenuAddEntry(Menu, Entry);

  MenuStackPush(Menu);
  return EFI_SUCCESS;
}
VOID
AddSystemToFastbootMenu (
  MENU_ENTRY         *Entry,
  multiboot_handle_t *mbhandle
)
{

  MENU_ENTRY* NewEntry = MenuCreateEntry();
  if(NewEntry==NULL)
    return;

  NewEntry->Private = mbhandle;
  NewEntry->Name = AsciiStrDup(mbhandle->Name);
  if(mbhandle->Description)
    NewEntry->Description = AsciiStrDup(mbhandle->Description);
  if(Entry->Icon)
    NewEntry->Icon = Entry->Icon;
  NewEntry->Callback = FastbootStartCallback;
  NewEntry->HideBootMessage = TRUE;

  MenuAddEntry(mFastbootMenu, NewEntry);
}
STATIC VOID
AddEfiBootOptions (
  VOID
)
{
  UINTN                         Index;
  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption;
  UINTN                         BootOptionCount;
  BOOLEAN                       First = TRUE;
  MENU_ENTRY                    *Entry;
  EFI_DEVICE_PATH*              DevicePathNode;

  BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

  for (Index = 0; Index < BootOptionCount; Index++) {
    //
    // Don't display the hidden/inactive boot option
    //
    if (((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) {
      continue;
    }

    if (First) {
      // GROUP: UEFI
      Entry = MenuCreateGroupEntry();
      Entry->Name = AsciiStrDup("UEFI");
      Entry->Update = UefiMenuEntryUpdate;
      MenuAddEntry(mBootMenuMain, Entry);
      First = FALSE;
    }

    Entry = MenuCreateEntry();
    if(Entry == NULL) {
      break;
    }

    CONST CHAR8* IconPath = "icons/uefi.png";

    DevicePathNode = BootOption[Index].FilePath;
    while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {

      // detect shell
      if (IS_DEVICE_PATH_NODE (DevicePathNode, MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP)) {
        CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH* FvDevicePathNode =  ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevicePathNode);
        if (FvDevicePathNode != NULL && CompareGuid (&FvDevicePathNode->FvFileName, &mUefiShellFileGuid)) {
          IconPath = "icons/efi_shell.png";
          break;
        }
      }

      // next
      DevicePathNode     = NextDevicePathNode (DevicePathNode);
    }

    Entry->Icon = libaroma_stream_ramdisk(IconPath);
    Entry->Name = Unicode2Ascii(BootOption[Index].Description);
    Entry->Callback = BootOptionEfiOption;
    Entry->Private = &BootOption[Index];
    Entry->ResetGop = TRUE;
    Entry->Update = UefiMenuEntryUpdate;
    MenuAddEntry(mBootMenuMain, Entry);
  }
}
INT32
main (
  IN INT32  Argc,
  IN CHAR8  **Argv
  )
{
  EFI_STATUS                          Status;
  MENU_ENTRY                          *Entry;

  // get LKAPi
  mLKApi = GetLKApi();

  // init fastboot
#if defined (MDE_CPU_ARM)
  FastbootCommandsAdd();
#endif

  // init libboot
  libboot_init();

  Status = gBS->LocateProtocol (
                  &gEfiDevicePathToTextProtocolGuid,
                  NULL,
                  (VOID **)&gEfiDevicePathToTextProtocol
                  );
  if (EFI_ERROR (Status)) {
    return -1;
  }

  Status = gBS->LocateProtocol (
                  &gEfiDevicePathFromTextProtocolGuid,
                  NULL,
                  (VOID **)&gEfiDevicePathFromTextProtocol
                  );
  if (EFI_ERROR (Status)) {
    return -1;
  }

  // set default values
  if(!UtilVariableExists(L"multiboot-debuglevel", &gEFIDroidVariableGuid))
    UtilSetEFIDroidVariable("multiboot-debuglevel", "4");
  if(!UtilVariableExists(L"fastboot-enable-boot-patch", &gEFIDroidVariableGuid))
    UtilSetEFIDroidVariable("fastboot-enable-boot-patch", "1");
  if(!UtilVariableExists(L"ui-show-file-explorer", &gEFIDroidVariableGuid))
    SettingBoolSet("ui-show-file-explorer", FALSE);
  if(!UtilVariableExists(L"ui-show-uefi-options", &gEFIDroidVariableGuid))
    SettingBoolSet("ui-show-uefi-options", FALSE);
  if(!UtilVariableExists(L"ui-show-fastboot", &gEFIDroidVariableGuid))
    SettingBoolSet("ui-show-fastboot", TRUE);
  if(!UtilVariableExists(L"boot-force-permissive", &gEFIDroidVariableGuid))
    SettingBoolSet("boot-force-permissive", FALSE);

  // init UI
  Status = MenuInit();
  if (EFI_ERROR (Status)) {
#if defined (MDE_CPU_ARM)
    FastbootInit();
#endif
    return -1;
  }

  // create menus
  mBootMenuMain = MenuCreate();

  mPowerMenu = MenuCreate();
  mPowerMenu->BackCallback = PowerMenuBackCallback;
  mPowerMenu->HideBackIcon = TRUE;

#if defined (MDE_CPU_ARM)
  mFastbootMenu = MenuCreate();
  mFastbootMenu->Title = AsciiStrDup("Please Select OS");
  mFastbootMenu->BackCallback = FastbootBackCallback;
#endif

  mBootMenuMain->Title = AsciiStrDup("Please Select OS");
  mBootMenuMain->ActionIcon = libaroma_stream_ramdisk("icons/ic_settings_black_24dp.png");
  mBootMenuMain->ActionCallback = MainMenuActionCallback;
  mBootMenuMain->ItemFlags = MENU_ITEM_FLAG_SEPARATOR_ALIGN_TEXT;

#if defined (MDE_CPU_ARM)
  // add android options
  AndroidLocatorInit();
  AndroidLocatorAddItems();
#endif

  // add default EFI options
  AddEfiBootOptions();

  // GROUP: Tools
  Entry = MenuCreateGroupEntry();
  Entry->Name = AsciiStrDup("Tools");
  MenuAddEntry(mBootMenuMain, Entry);

  // add file explorer option
  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/fileexplorer.png");
  Entry->Name = AsciiStrDup("File Explorer");
  Entry->Callback = FileExplorerCallback;
  Entry->HideBootMessage = TRUE;
  Entry->Update = FileExplorerUpdate;
  MenuAddEntry(mBootMenuMain, Entry);

#if defined (MDE_CPU_ARM)
  // add fastboot option
  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/android.png");
  Entry->Name = AsciiStrDup("Fastboot");
  Entry->Callback = FastbootCallback;
  Entry->HideBootMessage = TRUE;
  Entry->Update = FastbootMenuEntryUpdate;
  MenuAddEntry(mBootMenuMain, Entry);
#endif

  // add reboot option
  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/reboot.png");
  Entry->Name = AsciiStrDup("Reboot");
  Entry->Callback = RebootCallback;
  Entry->Private = NULL;
  Entry->LongPressCallback = RebootLongPressCallback;
  MenuAddEntry(mBootMenuMain, Entry);

  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/power_off.png");
  Entry->Name = AsciiStrDup("Power Off");
  Entry->Callback = PowerOffCallback;
  MenuAddEntry(mPowerMenu, Entry);

  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/reboot.png");
  Entry->Name = AsciiStrDup("Reboot");
  Entry->Callback = RebootCallback;
  Entry->Private = NULL;
  MenuAddEntry(mPowerMenu, Entry);

  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/reboot_recovery.png");
  Entry->Name = AsciiStrDup("Reboot to Recovery");
  Entry->Callback = RebootCallback;
  Entry->Private = UnicodeStrDup(L"recovery");
  MenuAddEntry(mPowerMenu, Entry);

  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/reboot_bootloader.png");
  Entry->Name = AsciiStrDup("Reboot to Bootloader");
  Entry->Callback = RebootCallback;
  Entry->Private = UnicodeStrDup(L"bootloader");
  MenuAddEntry(mPowerMenu, Entry);

  Entry = MenuCreateEntry();
  Entry->Icon = libaroma_stream_ramdisk("icons/download_mode.png");
  Entry->Name = AsciiStrDup("Enter Download Mode");
  Entry->Callback = RebootCallback;
  Entry->Private = UnicodeStrDup(L"download");
  MenuAddEntry(mPowerMenu, Entry);

  // show previous boot error
  CHAR8* EFIDroidErrorStr = UtilGetEFIDroidVariable("EFIDroidErrorStr");
  if (EFIDroidErrorStr != NULL) {
    MenuShowMessage("Previous boot failed", EFIDroidErrorStr);

    // delete variable
    UtilSetEFIDroidVariable("EFIDroidErrorStr", NULL);

    // backup variable
    UtilSetEFIDroidVariable("EFIDroidErrorStrPrev", EFIDroidErrorStr);

    // free pool
    FreePool(EFIDroidErrorStr);
  }

  // get last boot entry
  LAST_BOOT_ENTRY* LastBootEntry = UtilGetEFIDroidDataVariable(L"LastBootEntry");
  if(LastBootEntry)
   UtilSetEFIDroidDataVariable(L"LastBootEntry", NULL, 0);

#if defined (MDE_CPU_ARM)
  // run recovery mode handler
  if (mLKApi) {
    if(!AsciiStrCmp(mLKApi->platform_get_uefi_bootpart(), "recovery") || mLKApi->platform_get_uefi_bootmode()==LKAPI_UEFI_BM_RECOVERY) {
      AndroidLocatorHandleRecoveryMode(LastBootEntry);
    }
  }
#endif

  // free last boot entry
  if(LastBootEntry)
    FreePool(LastBootEntry);

  // clear the watchdog timer
  gBS->SetWatchdogTimer (0, 0, 0, NULL);

  // first boot?
  UINTN* LastBootVersion = UtilGetEFIDroidDataVariable(L"last-boot-version");
  if(LastBootVersion==NULL) {
    UINTN NewValue = 1;
    UtilSetEFIDroidDataVariable(L"last-boot-version", &NewValue, sizeof(NewValue));
    MenuShowTutorial();
  }

  // show main menu
  MenuStackPush(mBootMenuMain);
  MenuEnter (0, TRUE);
  MenuDeInit();

  return 0;
}