1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[efi] add RISC-V support

* Also fix Coverity warnings
This commit is contained in:
Pete Batard 2020-07-29 19:32:32 +01:00
parent 34b1d8a3ca
commit 6f5ea5f88f
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
7 changed files with 42 additions and 18 deletions

View file

@ -89,8 +89,9 @@ static const char* ldlinux_c32 = "ldlinux.c32";
static const char* md5sum_name[] = { "MD5SUMS", "md5sum.txt" }; static const char* md5sum_name[] = { "MD5SUMS", "md5sum.txt" };
static const char* casper_dirname = "/casper"; static const char* casper_dirname = "/casper";
static const char* efi_dirname = "/efi/boot"; static const char* efi_dirname = "/efi/boot";
static const char* efi_bootname[MAX_ARCHS] = static const char* efi_bootname[MAX_ARCHS] = {
{ "bootia32.efi", "bootia64.efi", "bootx64.efi", "bootarm.efi", "bootaa64.efi", "bootebc.efi" }; "bootia32.efi", "bootia64.efi", "bootx64.efi", "bootarm.efi", "bootaa64.efi",
"bootebc.efi", "bootriscv32.efi", "bootriscv64.efi", "bootriscv128.efi" };
static const char* sources_str = "/sources"; static const char* sources_str = "/sources";
static const char* wininst_name[] = { "install.wim", "install.esd", "install.swm" }; static const char* wininst_name[] = { "install.wim", "install.esd", "install.swm" };
// We only support GRUB/BIOS (x86) that uses a standard config dir (/boot/grub/i386-pc/) // We only support GRUB/BIOS (x86) that uses a standard config dir (/boot/grub/i386-pc/)
@ -1020,7 +1021,7 @@ out:
} }
} }
if (!IS_EFI_BOOTABLE(img_report) && HAS_EFI_IMG(img_report) && HasEfiImgBootLoaders()) { if (!IS_EFI_BOOTABLE(img_report) && HAS_EFI_IMG(img_report) && HasEfiImgBootLoaders()) {
img_report.has_efi = 0x80; img_report.has_efi = 0x8000;
} }
if (HAS_WINPE(img_report)) { if (HAS_WINPE(img_report)) {
// In case we have a WinPE 1.x based iso, we extract and parse txtsetup.sif // In case we have a WinPE 1.x based iso, we extract and parse txtsetup.sif
@ -1045,6 +1046,7 @@ out:
if (img_report.has_grub2) { if (img_report.has_grub2) {
// In case we have a GRUB2 based iso, we extract boot/grub/i386-pc/normal.mod to parse its version // In case we have a GRUB2 based iso, we extract boot/grub/i386-pc/normal.mod to parse its version
img_report.grub2_version[0] = 0; img_report.grub2_version[0] = 0;
// coverity[swapped_arguments]
if (GetTempFileNameU(temp_dir, APPLICATION_NAME, 0, path) != 0) { if (GetTempFileNameU(temp_dir, APPLICATION_NAME, 0, path) != 0) {
size = (size_t)ExtractISOFile(src_iso, "boot/grub/i386-pc/normal.mod", path, FILE_ATTRIBUTE_NORMAL); size = (size_t)ExtractISOFile(src_iso, "boot/grub/i386-pc/normal.mod", path, FILE_ATTRIBUTE_NORMAL);
buf = (char*)calloc(size, 1); buf = (char*)calloc(size, 1);
@ -1071,7 +1073,7 @@ out:
SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0); SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0);
} else { } else {
// Solus and other ISOs only provide EFI boot files in a FAT efi.img // Solus and other ISOs only provide EFI boot files in a FAT efi.img
if (img_report.has_efi == 0x80) if (img_report.has_efi == 0x8000)
DumpFatDir(dest_dir, 0); DumpFatDir(dest_dir, 0);
if (HAS_SYSLINUX(img_report)) { if (HAS_SYSLINUX(img_report)) {
static_sprintf(path, "%s\\syslinux.cfg", dest_dir); static_sprintf(path, "%s\\syslinux.cfg", dest_dir);

View file

@ -125,3 +125,14 @@ static __inline void *_reallocf(void *ptr, size_t size) {
/* The following is used for native ISO mounting in Windows 8 or later */ /* The following is used for native ISO mounting in Windows 8 or later */
#define VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT \ #define VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT \
{ 0xEC984AECL, 0xA0F9, 0x47e9, { 0x90, 0x1F, 0x71, 0x41, 0x5A, 0x66, 0x34, 0x5B } } { 0xEC984AECL, 0xA0F9, 0x47e9, { 0x90, 0x1F, 0x71, 0x41, 0x5A, 0x66, 0x34, 0x5B } }
/* RISC-V is still bleeding edge */
#ifndef IMAGE_FILE_MACHINE_RISCV32
#define IMAGE_FILE_MACHINE_RISCV32 0x5032
#endif
#ifndef IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_FILE_MACHINE_RISCV64 0x5064
#endif
#ifndef IMAGE_FILE_MACHINE_RISCV128
#define IMAGE_FILE_MACHINE_RISCV128 0x5128
#endif

View file

@ -62,7 +62,8 @@ enum bootcheck_return {
static const char* cmdline_hogger = "rufus.com"; static const char* cmdline_hogger = "rufus.com";
static const char* ep_reg = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"; static const char* ep_reg = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
static const char* vs_reg = "Software\\Microsoft\\VisualStudio"; static const char* vs_reg = "Software\\Microsoft\\VisualStudio";
static const char* arch_name[MAX_ARCHS] = { "x86_32", "Itanic", "x86_64", "ARM", "ARM64", "EBC" }; static const char* arch_name[MAX_ARCHS] = {
"x86_32", "Itanic", "x86_64", "ARM", "ARM64", "EBC","Risc-V 32", "Risc-V 64", "Risc-V 128" };
static BOOL existing_key = FALSE; // For LGP set/restore static BOOL existing_key = FALSE; // For LGP set/restore
static BOOL size_check = TRUE; static BOOL size_check = TRUE;
static BOOL log_displayed = FALSE; static BOOL log_displayed = FALSE;
@ -1167,6 +1168,15 @@ static uint8_t FindArch(const char* filename)
case IMAGE_FILE_MACHINE_EBC: case IMAGE_FILE_MACHINE_EBC:
ret = 6; ret = 6;
break; break;
case IMAGE_FILE_MACHINE_RISCV32:
ret = 7;
break;
case IMAGE_FILE_MACHINE_RISCV64:
ret = 8;
break;
case IMAGE_FILE_MACHINE_RISCV128:
ret = 9;
break;
} }
out: out:
@ -1212,12 +1222,13 @@ DWORD WINAPI ImageScanThread(LPVOID param)
if (img_report.is_windows_img) { if (img_report.is_windows_img) {
selection_default = BT_IMAGE; selection_default = BT_IMAGE;
// coverity[swapped_arguments]
if (GetTempFileNameU(temp_dir, APPLICATION_NAME, 0, tmp_path) != 0) { if (GetTempFileNameU(temp_dir, APPLICATION_NAME, 0, tmp_path) != 0) {
// Only look at index 1 for now. If people complain, we may look for more. // Only look at index 1 for now. If people complain, we may look for more.
if (WimExtractFile(image_path, 1, "Windows\\Boot\\EFI\\bootmgr.efi", tmp_path, TRUE)) { if (WimExtractFile(image_path, 1, "Windows\\Boot\\EFI\\bootmgr.efi", tmp_path, TRUE)) {
arch = FindArch(tmp_path); arch = FindArch(tmp_path);
if (arch != 0) { if (arch != 0) {
uprintf(" Image contains an %s EFI boot manager", arch_name[arch - 1]); uprintf(" Image contains a%s %s EFI boot manager", arch_name[arch - 1], (arch < 7) ? "n" : "");
img_report.has_efi = 1 | (1 << arch); img_report.has_efi = 1 | (1 << arch);
img_report.has_bootmgr_efi = TRUE; img_report.has_bootmgr_efi = TRUE;
img_report.wininst_index = 1; img_report.wininst_index = 1;
@ -1727,7 +1738,7 @@ static void InitDialog(HWND hDlg)
// Count on Microsoft for making it more attractive to read a // Count on Microsoft for making it more attractive to read a
// version using strtok() than using GetFileVersionInfo() // version using strtok() than using GetFileVersionInfo()
token = strtok(tmp, " "); token = strtok(tmp, " ");
for (i=0; (i<3) && ((token = strtok(NULL, ".")) != NULL); i++) for (i = 0; (i < 3) && ((token = strtok(NULL, ".")) != NULL); i++)
rufus_version[i] = (uint16_t)atoi(token); rufus_version[i] = (uint16_t)atoi(token);
// Redefine the title to be able to add "Alpha" or "Beta" // Redefine the title to be able to add "Alpha" or "Beta"
@ -1738,7 +1749,7 @@ static void InitDialog(HWND hDlg)
dialog_handle = FindWindowA(NULL, tmp); dialog_handle = FindWindowA(NULL, tmp);
uprintf(APPLICATION_NAME " " APPLICATION_ARCH " v%d.%d.%d%s%s", rufus_version[0], rufus_version[1], rufus_version[2], uprintf(APPLICATION_NAME " " APPLICATION_ARCH " v%d.%d.%d%s%s", rufus_version[0], rufus_version[1], rufus_version[2],
IsAlphaOrBeta(), (ini_file != NULL)?"(Portable)":""); IsAlphaOrBeta(), (ini_file != NULL)?"(Portable)":"");
for (i=0; i<ARRAYSIZE(resource); i++) { for (i = 0; i < ARRAYSIZE(resource); i++) {
len = 0; len = 0;
buf = (char*)GetResource(hMainInstance, resource[i], _RT_RCDATA, "ldlinux_sys", &len, TRUE); buf = (char*)GetResource(hMainInstance, resource[i], _RT_RCDATA, "ldlinux_sys", &len, TRUE);
if (buf == NULL) { if (buf == NULL) {

View file

@ -62,7 +62,7 @@
#define DRIVE_INDEX_MAX 0x000000C0 #define DRIVE_INDEX_MAX 0x000000C0
#define MIN_DRIVE_SIZE 8 // Minimum size a drive must have, to be formattable (in MB) #define MIN_DRIVE_SIZE 8 // Minimum size a drive must have, to be formattable (in MB)
#define MIN_EXTRA_PART_SIZE (1024*1024) // Minimum size of the extra partition, in bytes #define MIN_EXTRA_PART_SIZE (1024*1024) // Minimum size of the extra partition, in bytes
#define MAX_ARCHS 6 // Number of arhitectures we recognize #define MAX_ARCHS 9 // Number of arhitectures we recognize
#define MAX_DRIVES (DRIVE_INDEX_MAX - DRIVE_INDEX_MIN) #define MAX_DRIVES (DRIVE_INDEX_MAX - DRIVE_INDEX_MIN)
#define MAX_TOOLTIPS 128 #define MAX_TOOLTIPS 128
#define MAX_SIZE_SUFFIXES 6 // bytes, KB, MB, GB, TB, PB #define MAX_SIZE_SUFFIXES 6 // bytes, KB, MB, GB, TB, PB
@ -308,7 +308,7 @@ enum checksum_type {
#define HAS_BOOTMGR_BIOS(r) (r.has_bootmgr) #define HAS_BOOTMGR_BIOS(r) (r.has_bootmgr)
#define HAS_BOOTMGR_EFI(r) (r.has_bootmgr_efi) #define HAS_BOOTMGR_EFI(r) (r.has_bootmgr_efi)
#define HAS_BOOTMGR(r) (HAS_BOOTMGR_BIOS(r) || HAS_BOOTMGR_EFI(r)) #define HAS_BOOTMGR(r) (HAS_BOOTMGR_BIOS(r) || HAS_BOOTMGR_EFI(r))
#define HAS_REGULAR_EFI(r) (r.has_efi & 0x7E) #define HAS_REGULAR_EFI(r) (r.has_efi & 0x7FFE)
#define HAS_WININST(r) (r.wininst_index != 0) #define HAS_WININST(r) (r.wininst_index != 0)
#define HAS_WINPE(r) (((r.winpe & WINPE_I386) == WINPE_I386)||((r.winpe & WINPE_AMD64) == WINPE_AMD64)||((r.winpe & WINPE_MININT) == WINPE_MININT)) #define HAS_WINPE(r) (((r.winpe & WINPE_I386) == WINPE_I386)||((r.winpe & WINPE_AMD64) == WINPE_AMD64)||((r.winpe & WINPE_MININT) == WINPE_MININT))
#define HAS_WINDOWS(r) (HAS_BOOTMGR(r) || (r.uses_minint) || HAS_WINPE(r)) #define HAS_WINDOWS(r) (HAS_BOOTMGR(r) || (r.uses_minint) || HAS_WINPE(r))
@ -342,7 +342,7 @@ typedef struct {
BOOLEAN is_windows_img; BOOLEAN is_windows_img;
BOOLEAN disable_iso; BOOLEAN disable_iso;
uint16_t winpe; uint16_t winpe;
uint8_t has_efi; uint16_t has_efi;
uint8_t has_md5sum; uint8_t has_md5sum;
uint8_t wininst_index; uint8_t wininst_index;
uint8_t has_symlinks; uint8_t has_symlinks;

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.12.1691" CAPTION "Rufus 3.12.1692"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,12,1691,0 FILEVERSION 3,12,1692,0
PRODUCTVERSION 3,12,1691,0 PRODUCTVERSION 3,12,1692,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.12.1691" VALUE "FileVersion", "3.12.1692"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.12.exe" VALUE "OriginalFilename", "rufus-3.12.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.12.1691" VALUE "ProductVersion", "3.12.1692"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -76,7 +76,7 @@ void SetAccessibleName(HWND hCtrl, const char* name)
SetWindowTextW(hCtrl, wname); SetWindowTextW(hCtrl, wname);
if (pfaps == NULL) if (pfaps == NULL)
CoCreateInstance(&CLSID_AccPropServices, NULL, CLSCTX_INPROC, &IID_IAccPropServices, (LPVOID)&pfaps); IGNORE_RETVAL(CoCreateInstance(&CLSID_AccPropServices, NULL, CLSCTX_INPROC, &IID_IAccPropServices, (LPVOID)&pfaps));
if (pfaps != NULL) { if (pfaps != NULL) {
IAccPropServices_ClearHwndProps(pfaps, hCtrl, OBJID_CLIENT, CHILDID_SELF, props, ARRAYSIZE(props)); IAccPropServices_ClearHwndProps(pfaps, hCtrl, OBJID_CLIENT, CHILDID_SELF, props, ARRAYSIZE(props));
IAccPropServices_SetHwndPropStr(pfaps, hCtrl, OBJID_CLIENT, CHILDID_SELF, Name_Property_GUID, wname); IAccPropServices_SetHwndPropStr(pfaps, hCtrl, OBJID_CLIENT, CHILDID_SELF, Name_Property_GUID, wname);

View file

@ -307,7 +307,7 @@ BOOL IsBootableImage(const char* path)
} }
img_report.image_size = (uint64_t)liImageSize.QuadPart; img_report.image_size = (uint64_t)liImageSize.QuadPart;
size = sizeof(wim_magic); size = sizeof(wim_magic);
SetFilePointerEx(handle, ptr, NULL, FILE_BEGIN); IGNORE_RETVAL(SetFilePointerEx(handle, ptr, NULL, FILE_BEGIN));
img_report.is_windows_img = ReadFile(handle, &wim_magic, size, &size, NULL) && (wim_magic == WIM_MAGIC); img_report.is_windows_img = ReadFile(handle, &wim_magic, size, &size, NULL) && (wim_magic == WIM_MAGIC);
if (img_report.is_windows_img) if (img_report.is_windows_img)
goto out; goto out;