Fix build on riscv64

This commit is contained in:
misaka00251 2023-07-18 16:15:54 +08:00
parent 6a79745d50
commit fddb1534d2
No known key found for this signature in database
GPG Key ID: 1F50F0319B8BAFCB
4 changed files with 288 additions and 6 deletions

136
crt0-efi-riscv64.S Normal file
View File

@ -0,0 +1,136 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
* Copright (C) 2018 Alexander Graf <agraf@suse.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice and this list of conditions, without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later version.
*/
#ifndef EFI_SUBSYSTEM
#define EFI_SUBSYSTEM 10
#endif
.section .text.head
/*
* Magic "MZ" signature for PE/COFF
*/
.globl ImageBase
ImageBase:
.ascii "MZ"
.skip 58 // 'MZ' + pad + offset == 64
.long pe_header - ImageBase // Offset to the PE header.
pe_header:
.ascii "PE"
.short 0
coff_header:
.short 0x5064 // riscv64
.short 2 // nr_sections
.long 0 // TimeDateStamp
.long 0 // PointerToSymbolTable
.long 0 // NumberOfSymbols
.short section_table - optional_header // SizeOfOptionalHeader
.short 0x206 // Characteristics.
// IMAGE_FILE_DEBUG_STRIPPED |
// IMAGE_FILE_EXECUTABLE_IMAGE |
// IMAGE_FILE_LINE_NUMS_STRIPPED
optional_header:
.short 0x20b // PE32+ format
.byte 0x02 // MajorLinkerVersion
.byte 0x14 // MinorLinkerVersion
.long _data - _start // SizeOfCode
.long _data_size // SizeOfInitializedData
.long 0 // SizeOfUninitializedData
.long _start - ImageBase // AddressOfEntryPoint
.long _start - ImageBase // BaseOfCode
extra_header_fields:
.quad 0 // ImageBase
.long 0x1000 // SectionAlignment
.long 0x200 // FileAlignment
.short 0 // MajorOperatingSystemVersion
.short 0 // MinorOperatingSystemVersion
.short 0 // MajorImageVersion
.short 0 // MinorImageVersion
.short 0 // MajorSubsystemVersion
.short 0 // MinorSubsystemVersion
.long 0 // Win32VersionValue
.long _edata - ImageBase // SizeOfImage
// Everything before the kernel image is considered part of the header
.long _start - ImageBase // SizeOfHeaders
.long 0 // CheckSum
.short EFI_SUBSYSTEM // Subsystem
.short 0 // DllCharacteristics
.quad 0 // SizeOfStackReserve
.quad 0 // SizeOfStackCommit
.quad 0 // SizeOfHeapReserve
.quad 0 // SizeOfHeapCommit
.long 0 // LoaderFlags
.long 0x6 // NumberOfRvaAndSizes
.quad 0 // ExportTable
.quad 0 // ImportTable
.quad 0 // ResourceTable
.quad 0 // ExceptionTable
.quad 0 // CertificationTable
.quad 0 // BaseRelocationTable
// Section table
section_table:
/*
* The EFI application loader requires a relocation section
* because EFI applications must be relocatable. This is a
* dummy section as far as we are concerned.
*/
.ascii ".reloc\0\0"
.long 0
.long 0
.long 0 // SizeOfRawData
.long 0 // PointerToRawData
.long 0 // PointerToRelocations
.long 0 // PointerToLineNumbers
.short 0 // NumberOfRelocations
.short 0 // NumberOfLineNumbers
.long 0x42100040 // Characteristics (section flags)
.ascii ".text\0\0\0"
.long _edata - _start // VirtualSize
.long _start - ImageBase // VirtualAddress
.long _edata - _start // SizeOfRawData
.long _start - ImageBase // PointerToRawData
.long 0 // PointerToRelocations (0 for executables)
.long 0 // PointerToLineNumbers (0 for executables)
.short 0 // NumberOfRelocations (0 for executables)
.short 0 // NumberOfLineNumbers (0 for executables)
.long 0xe0500020 // Characteristics (section flags)
.align 12
.globl _start
_start:
addi sp, sp, -24
sd a0, 0(sp)
sd a1, 8(sp)
sd ra, 16(sp)
lla a0, ImageBase
lla a1, _DYNAMIC
call _relocate
bne a0, zero, 0f
ld a1, 8(sp)
ld a0, 0(sp)
call efi_main
ld ra, 16(sp)
0: addi sp, sp, 24
ret

77
elf_riscv64_efi.lds Normal file
View File

@ -0,0 +1,77 @@
/* SPDX-License-Identifier: GPL-2.0+ */
OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv")
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS {
.text 0x0 :
{
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
}
_etext = .;
_text_size = . - _text;
.dynamic :
{ *(.dynamic) }
.data :
ALIGN(4096)
{
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
. = ALIGN(16);
_bss_end = .;
}
.rela.text :
{ *(.rela.text) *(.rela.text*) }
.rela.dyn :
{ *(.rela.dyn) }
.rela.plt :
{ *(.rela.plt) }
.rela.got :
{ *(.rela.got) }
.rela.data :
{ *(.rela.data) *(.rela.data*) }
. = ALIGN(512);
_edata = .;
_data_size = . - _data;
. = ALIGN(4096);
.dynsym :
{ *(.dynsym) }
. = ALIGN(4096);
.dynstr :
{ *(.dynstr) }
. = ALIGN(4096);
.note.gnu.build-id :
{ *(.note.gnu.build-id) }
/DISCARD/ :
{
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 :
{ *(.comment) }
}

View File

@ -12,17 +12,17 @@
%global enable_dummy 1
# fwupd.efi is only available on these arches
%ifarch x86_64 aarch64
%ifarch x86_64 aarch64 riscv64
%global have_uefi 1
%endif
# gpio.h is only available on these arches
%ifarch x86_64 aarch64
%ifarch x86_64 aarch64 riscv64
%global have_gpio 1
%endif
# flashrom is only available on these arches
%ifarch i686 x86_64 armv7hl aarch64 ppc64le
%ifarch i686 x86_64 armv7hl aarch64 ppc64le riscv64
%global have_flashrom 0
%endif
@ -43,7 +43,7 @@
Name: fwupd
Version: 1.8.6
Release: 5
Release: 6
License: LGPLv2+
Summary: Make updating firmware on Linux automatic, safe and reliable
URL: https://github.com/fwupd/fwupd
@ -59,9 +59,13 @@ Source9: http://people.redhat.com/rhughes/dbx/DBXUpdate-20160809-x64.cab
Source10: http://people.redhat.com/rhughes/dbx/DBXUpdate-20200729-aa64.cab
Source11: http://people.redhat.com/rhughes/dbx/DBXUpdate-20200729-ia32.cab
Source12: http://people.redhat.com/rhughes/dbx/DBXUpdate-20200729-x64.cab
Source13: https://sourceforge.net/p/gnu-efi/code/ci/3.0.14/tree/gnuefi/crt0-efi-riscv64.S?format=raw#/crt0-efi-riscv64.S
Source14: https://sourceforge.net/p/gnu-efi/code/ci/3.0.14/tree/gnuefi/elf_riscv64_efi.lds?format=raw#/elf_riscv64_efi.lds
Patch0: fwupd-efi.patch
%ifarch riscv64
Patch1: https://raw.githubusercontent.com/GNOME/gnome-build-meta/37bc8931517261e359e02b2b14bffab0501e79d9/files/fwupd/riscv64.patch
%endif
BuildRequires: libcbor libcbor-devel
BuildRequires: efi-srpm-macros
@ -163,11 +167,18 @@ Provides: dbxtool-help
Man pages and other related documents for fwupd.
%prep
%autosetup -p1
%setup -q -n %{name}-%{version}
%patch0 -p1
mkdir -p subprojects/fwupd-efi
tar xfs %{SOURCE2} -C subprojects/fwupd-efi --strip-components=1
%ifarch riscv64
%patch1 -p1
cp %{SOURCE13} subprojects/fwupd-efi/efi/crt0
cp %{SOURCE14} subprojects/fwupd-efi/efi/lds
%endif
sed -ri '1s=^#!/usr/bin/(env )?python3=#!%{__python3}=' \
contrib/ci/*.py \
contrib/firmware_packager/*.py \
@ -330,9 +341,14 @@ done
%endif
%dir %{_libexecdir}/fwupd
%{_libexecdir}/fwupd/fwupd
# depending on compiler behavior
# currently skipped from building if compiled by llvm
%if "%toolchain" == "llvm"
%else
%ifarch i686 x86_64
%{_libexecdir}/fwupd/fwupd-detect-cet
%endif
%endif
%{_libexecdir}/fwupd/fwupdoffline
%if 0%{?have_uefi}
%{_bindir}/fwupdate
@ -458,6 +474,10 @@ done
%{_datadir}/man/man1/*
%changelog
* Mon Jul 10 2023 misaka00251 <liuxin@iscas.ac.cn> - 1.8.6-6
- Fix build on riscv64
- from @jchzhou: skip packaging fwupd-detect-cet if compiled with llvm
* Fri Mar 10 2023 zhouwenpei <zhouwenpei1@h-partners.com> - 1.8.6-5
- remove bluez require

49
riscv64.patch Normal file
View File

@ -0,0 +1,49 @@
diff --git a/subprojects/fwupd-efi/efi/generate_binary.py b/subprojects/fwupd-efi/efi/generate_binary.py
index a8a4437..9af5853 100755
--- a/subprojects/fwupd-efi/efi/generate_binary.py
+++ b/subprojects/fwupd-efib/efi/generate_binary.py
@@ -36,7 +36,7 @@ def _run_objcopy(args):
# aarch64 and arm32 don't have an EFI capable objcopy
# Use 'binary' instead, and add required symbols manually
- if args.arch in ["aarch64", "arm"]:
+ if args.arch in ["aarch64", "arm", "riscv64"]:
argv.extend(["-O", "binary"])
elif args.os == "freebsd":
# `--target` option is missing and --input-target doesn't recognize
diff --git a/subprojects/fwupd-efi/efi/meson.build b/subprojects/fwupd-efi/efi/meson.build
index 68ea4aa..26ba42c 100644
--- a/subprojects/fwupd-efi/efi/meson.build
+++ b/subprojects/fwupd-efi/efi/meson.build
@@ -18,7 +18,7 @@ endif
efi_libdir = get_option('efi-libdir')
if efi_libdir == ''
- cmd = 'cd /usr/lib/$(@0@ -print-multi-os-directory) && pwd'.format(efi_cc)
+ cmd = 'cd /usr/lib64/$(@0@ -print-multi-os-directory) && pwd'.format(efi_cc)
ret = run_command('sh', '-c', cmd)
if ret.returncode() == 0
efi_libdir = ret.stdout().strip()
@@ -79,7 +79,7 @@ if get_option('efi_sbat_distro_id') != ''
endif
# is the system crt0 for arm and aarch64 new enough to know about SBAT?
-if host_cpu == 'aarch64' or host_cpu == 'arm'
+if host_cpu == 'aarch64' or host_cpu == 'arm' or host_cpu == 'riscv64'
if get_option('efi_sbat_distro_id') != ''
arch_crt_source = 'crt0-efi-@0@.S'.format(gnu_efi_path_arch)
cmd = run_command('grep', '-q', 'sbat', join_paths(efi_crtdir, arch_crt_source))
diff --git a/subprojects/fwupd-efi/meson.build b/subprojects/fwupd-efi/meson.build
index 1753411..8d23a50 100644
--- a/subprojects/fwupd-efi/meson.build
+++ b/subprojects/fwupd-efi/meson.build
@@ -27,6 +27,9 @@ elif host_cpu == 'arm'
elif host_cpu == 'aarch64'
EFI_MACHINE_TYPE_NAME = 'aa64'
gnu_efi_arch = 'aarch64'
+elif host_cpu == 'riscv64'
+ EFI_MACHINE_TYPE_NAME = 'riscv64'
+ gnu_efi_arch = 'riscv64'
else
error('Unknown host_cpu ' + host_cpu)
endif