[grub] switch to the more compatible Grub 2.00-22

* Also enable Old BIOS fixes with Syslinux, Grub installation and fix related UI issues
* Also add a check to confirm that Grub SBR will fit
This commit is contained in:
Pete Batard 2014-11-18 23:49:29 +00:00
parent b3947fc026
commit 8b47e95eb5
7 changed files with 96 additions and 60 deletions

View file

@ -890,7 +890,8 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
}
if (IsChecked(IDC_BOOT)) {
// Set first partition bootable - masquerade as per the DiskID selected
buf[0x1be] = (IsChecked(IDC_RUFUS_MBR))?(BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80;
buf[0x1be] = (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && IsChecked(IDC_RUFUS_MBR)) ?
(BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80;
uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]);
}
@ -947,34 +948,51 @@ out:
*/
static BOOL WriteSBR(HANDLE hPhysicalDrive)
{
BOOL r = FALSE;
DWORD size;
// TODO: Do we need anything special for 4K sectors?
DWORD size, max_size, mbr_size = 0x200;
int dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
unsigned char* buf = NULL;
FILE fake_fd = { 0 };
const char* using_msg = "Using %s SBR\n";
fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
if ((dt == DT_GRUB4DOS) || ((dt == DT_ISO) && (iso_report.has_grub4dos))) {
// Ensure that we have sufficient space for the SBR
max_size = IsChecked(IDC_EXTRA_PARTITION) ?
(DWORD)(SelectedDrive.Geometry.BytesPerSector * SelectedDrive.Geometry.SectorsPerTrack) : 1024 * 1024;
max_size -= mbr_size;
if ((dt == DT_ISO) && (iso_report.has_grub4dos))
dt = DT_GRUB4DOS;
if ((dt == DT_ISO) && (iso_report.has_grub2))
dt = DT_GRUB2;
switch (dt) {
case DT_GRUB4DOS:
buf = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_GR_GRUB_GRLDR_MBR), _RT_RCDATA, "grldr.mbr", &size, FALSE);
if ((buf != NULL) && (size > 0x200)) {
uprintf(using_msg, "Grub4DOS");
// -0x200 to remove the MBR part
r = (write_data(&fake_fd, 512, &buf[0x200], (uint64_t)(size - 0x200)) != 0);
if ((buf == NULL) || (size <= mbr_size)) {
uprintf("grldr.mbr is either not present or too small");
return FALSE;
}
} else if ((dt == DT_GRUB2) || ((dt == DT_ISO) && (iso_report.has_grub2))) {
buf = &buf[mbr_size];
size -= mbr_size;
break;
case DT_GRUB2:
buf = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_GR_GRUB2_CORE_IMG), _RT_RCDATA, "core.img", &size, FALSE);
if (buf != NULL) {
uprintf(using_msg, "Grub 2.0");
// TODO: test what happens for 4096 bytes sectors
r = (write_data(&fake_fd, 512, buf, (uint64_t)size) != 0);
if (buf == NULL) {
uprintf("Could not access core.img");
return FALSE;
}
} else {
break;
default:
// No need to write secondary block
r = TRUE;
return TRUE;
}
return r;
uprintf("Writing SBR (Secondary Boot record)");
if (size > max_size) {
uprintf(" SBR size is too large - You may need to uncheck 'Add fixes for old BIOSes'.");
return FALSE;
}
return (write_data(&fake_fd, mbr_size, buf, (uint64_t)size) != 0);
}
/*
@ -984,7 +1002,7 @@ static __inline const char* dt_to_name(int dt) {
switch (dt) {
case DT_FREEDOS: return "FreeDOS";
case DT_REACTOS: return "ReactOS";
default:
default:
return ((dt==DT_ISO)&&(iso_report.has_kolibrios))?"KolibriOS":"Standard";
}
}

View file

@ -66,8 +66,8 @@
#define IDR_FD_EGA18_CPX 326
#define IDR_SL_LDLINUX_V4_BSS 400
#define IDR_SL_LDLINUX_V4_SYS 401
#define IDR_SL_LDLINUX_V6_BSS 402
#define IDR_SL_LDLINUX_V6_SYS 403
#define IDR_SL_LDLINUX_V6_BSS 402
#define IDR_SL_LDLINUX_V6_SYS 403
#define IDR_SL_MBOOT_C32 404
#define IDR_GR_GRUB_GRLDR_MBR 450
#define IDR_GR_GRUB2_CORE_IMG 451

View file

@ -43,6 +43,7 @@
#include "localization.h"
/* Redefinitions for WDK and MinGW */
// TODO: these would be better in a 'missing.h' file
#ifndef PBM_SETSTATE
#define PBM_SETSTATE (WM_USER+16)
#endif
@ -487,7 +488,7 @@ static void SetMBRProps(void)
int dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
BOOL needs_masquerading = (IS_WINPE(iso_report.winpe) && (!iso_report.uses_minint));
if ((!mbr_selected_by_user) && ((image_path == NULL) || (dt != DT_ISO) || (fs != FS_NTFS))) {
if ((!mbr_selected_by_user) && ((image_path == NULL) || (dt != DT_ISO) || (fs != FS_NTFS) || IS_GRUB(iso_report))) {
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, BST_UNCHECKED);
IGNORE_RETVAL(ComboBox_SetCurSel(hDiskID, 0));
return;
@ -502,25 +503,30 @@ static void SetMBRProps(void)
static void EnableAdvancedBootOptions(BOOL enable, BOOL remove_checkboxes)
{
int bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
BOOL actual_enable = ((bt==BT_UEFI)||(selection_default>=DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
BOOL actual_enable_mbr = ((bt==BT_UEFI)||(selection_default>=DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
BOOL actual_enable_fix = ((bt==BT_UEFI)||(selection_default==DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
static UINT uXPartChecked = BST_UNCHECKED;
if ((selection_default == DT_ISO) && (iso_report.has_kolibrios || IS_GRUB(iso_report) || IS_REACTOS(iso_report) || HAS_SYSLINUX(iso_report))) {
actual_enable_mbr = FALSE;
mbr_selected_by_user = FALSE;
}
if (remove_checkboxes) {
// Store/Restore the checkbox states
if (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && !actual_enable) {
if (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && !actual_enable_mbr) {
uMBRChecked = IsChecked(IDC_RUFUS_MBR);
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, BST_UNCHECKED);
uXPartChecked = IsChecked(IDC_EXTRA_PARTITION);
CheckDlgButton(hMainDialog, IDC_EXTRA_PARTITION, BST_UNCHECKED);
} else if (!IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && actual_enable) {
} else if (!IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && actual_enable_mbr) {
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, uMBRChecked);
CheckDlgButton(hMainDialog, IDC_EXTRA_PARTITION, uXPartChecked);
}
}
EnableWindow(GetDlgItem(hMainDialog, IDC_EXTRA_PARTITION), actual_enable);
EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), actual_enable);
EnableWindow(hDiskID, actual_enable);
EnableWindow(GetDlgItem(hMainDialog, IDC_EXTRA_PARTITION), actual_enable_fix);
EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), actual_enable_mbr);
EnableWindow(hDiskID, actual_enable_mbr);
}
static void EnableBootOptions(BOOL enable, BOOL remove_checkboxes)
@ -556,7 +562,8 @@ static void SetTargetSystem(void)
if (SelectedDrive.PartitionType == PARTITION_STYLE_GPT) {
ts = 2; // GPT/UEFI
} else if (SelectedDrive.has_protective_mbr || SelectedDrive.has_mbr_uefi_marker || (IS_EFI(iso_report) &&
(!HAS_SYSLINUX(iso_report)) && (!iso_report.has_bootmgr) && (!IS_WINPE(iso_report.winpe))) ) {
(!HAS_SYSLINUX(iso_report)) && (!iso_report.has_bootmgr) && (!IS_REACTOS(iso_report)) &&
(!iso_report.has_kolibrios) && (!IS_GRUB(iso_report)) && (!IS_WINPE(iso_report.winpe))) ) {
ts = 1; // MBR/UEFI
} else {
ts = 0; // MBR/BIOS|UEFI
@ -714,7 +721,7 @@ void UpdateProgress(int op, float percent)
return;
}
if (percent > 100.1f) {
duprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
// duprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
return;
}
if ((percent < 0.0f) && (nb_slots[op] <= 0)) {
@ -1556,7 +1563,7 @@ void SetBoot(int fs, int bt)
static_sprintf(tmp, "Syslinux %s", embedded_sl_version_str[1]);
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), DT_SYSLINUX_V6));
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "ReactOS"), DT_REACTOS));
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub 2.0"), DT_GRUB2));
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub 2.00-22"), DT_GRUB2));
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub4DOS"), DT_GRUB4DOS));
}
if ((!advanced_mode) && (selection_default >= DT_SYSLINUX_V4)) {

View file

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 227, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 1.5.0.543"
CAPTION "Rufus 1.5.0.544"
FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
@ -164,7 +164,7 @@ END
IDD_DIALOG_XP DIALOGEX 12, 12, 227, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 1.5.0.543"
CAPTION "Rufus 1.5.0.544"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
@ -297,7 +297,7 @@ END
IDD_DIALOG_RTL DIALOGEX 12, 12, 227, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 1.5.0.543"
CAPTION "Rufus 1.5.0.544"
FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
@ -437,7 +437,7 @@ END
IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 227, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 1.5.0.543"
CAPTION "Rufus 1.5.0.544"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
@ -701,8 +701,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,5,0,543
PRODUCTVERSION 1,5,0,543
FILEVERSION 1,5,0,544
PRODUCTVERSION 1,5,0,544
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -719,13 +719,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.5.0.543"
VALUE "FileVersion", "1.5.0.544"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.5.0.543"
VALUE "ProductVersion", "1.5.0.544"
END
END
BLOCK "VarFileInfo"