From daab1372185ead237c61cf92ecc76514acd58fd9 Mon Sep 17 00:00:00 2001 From: Omar Vega Ramos Date: Tue, 4 Sep 2018 11:47:31 -0500 Subject: libre-testing/syslinux-6.03-11.parabola1: rebuild --- .../syslinux/0016-strip-gnu-property.patch | 41 ++ libre-testing/syslinux/PKGBUILD | 150 +++++ .../syslinux/fix_infinite_loop_tests.patch | 16 + libre-testing/syslinux/gnu-efi-git.patch | 28 + libre-testing/syslinux/splash.png | Bin 0 -> 27496 bytes libre-testing/syslinux/splash.svg | 284 ++++++++++ .../syslinux/syslinux-6.02-fix-bios-isolinux.patch | 12 + .../syslinux/syslinux-6.02-fix-chainloading.patch | 47 ++ .../syslinux/syslinux-6.02-fix-efi-ovmf.patch | 621 +++++++++++++++++++++ libre-testing/syslinux/syslinux-install_update | 465 +++++++++++++++ libre-testing/syslinux/syslinux.cfg | 87 +++ libre-testing/syslinux/syslinux.install | 32 ++ 12 files changed, 1783 insertions(+) create mode 100644 libre-testing/syslinux/0016-strip-gnu-property.patch create mode 100644 libre-testing/syslinux/PKGBUILD create mode 100644 libre-testing/syslinux/fix_infinite_loop_tests.patch create mode 100644 libre-testing/syslinux/gnu-efi-git.patch create mode 100644 libre-testing/syslinux/splash.png create mode 100644 libre-testing/syslinux/splash.svg create mode 100644 libre-testing/syslinux/syslinux-6.02-fix-bios-isolinux.patch create mode 100644 libre-testing/syslinux/syslinux-6.02-fix-chainloading.patch create mode 100644 libre-testing/syslinux/syslinux-6.02-fix-efi-ovmf.patch create mode 100644 libre-testing/syslinux/syslinux-install_update create mode 100644 libre-testing/syslinux/syslinux.cfg create mode 100644 libre-testing/syslinux/syslinux.install (limited to 'libre-testing/syslinux') diff --git a/libre-testing/syslinux/0016-strip-gnu-property.patch b/libre-testing/syslinux/0016-strip-gnu-property.patch new file mode 100644 index 000000000..678c7331a --- /dev/null +++ b/libre-testing/syslinux/0016-strip-gnu-property.patch @@ -0,0 +1,41 @@ +Author: Lukas Schwaighofer +Description: Strip the .note.gnu.property section for the mbr. This section is + added since binutils Debian version 2.31.1-2 and causes mbr.bin to grow in + size beyond what can fit into the master boot record. +Forwarded: https://www.syslinux.org/archives/2018-August/026168.html + +--- + mbr/i386/mbr.ld | 6 +++++- + mbr/x86_64/mbr.ld | 6 +++++- + 2 files changed, 10 insertions(+), 2 deletions(-) + +diff --git a/mbr/i386/mbr.ld b/mbr/i386/mbr.ld +index d14ba80..6d48990 100644 +--- a/mbr/i386/mbr.ld ++++ b/mbr/i386/mbr.ld +@@ -69,5 +69,9 @@ SECTIONS + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +- /DISCARD/ : { *(.note.GNU-stack) } ++ /DISCARD/ : ++ { ++ *(.note.GNU-stack) ++ *(.note.gnu.property) ++ } + } +diff --git a/mbr/x86_64/mbr.ld b/mbr/x86_64/mbr.ld +index ae27d49..5b46db6 100644 +--- a/mbr/x86_64/mbr.ld ++++ b/mbr/x86_64/mbr.ld +@@ -68,5 +68,9 @@ SECTIONS + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +- /DISCARD/ : { *(.note.GNU-stack) } ++ /DISCARD/ : ++ { ++ *(.note.GNU-stack) ++ *(.note.gnu.property) ++ } + } diff --git a/libre-testing/syslinux/PKGBUILD b/libre-testing/syslinux/PKGBUILD new file mode 100644 index 000000000..0fd6ad39b --- /dev/null +++ b/libre-testing/syslinux/PKGBUILD @@ -0,0 +1,150 @@ +# Maintainer (Arch): Tobias Powalowski +# Maintainer (Arch): Thomas Bächler +# Maintainer (Arch): Anatol Pomozov +# Contributor (Arch): Keshav Amburay <(the ddoott ridikulus ddoott rat) (aatt) (gemmaeiil) (ddoott) (ccoomm)> +# Maintainer (Hyperbola): André Silva +# Maintainer: Omar Vega Ramos + +pkgname=syslinux +pkgver=6.03 +_tag=syslinux-$pkgver +pkgrel=11.parabola1 +pkgdesc='Collection of boot loaders that boot from FAT, ext2/3/4 and btrfs filesystems, from CDs and via PXE (Parabola rebranded)' +url='http://www.syslinux.org/' +arch=(i686 x86_64) +backup=(boot/syslinux/syslinux.cfg + boot/syslinux/splash.png) +install=syslinux.install +license=(GPL2) +# syslinux build system is a mess of submakes that does not work with -jN +# efi32/com32 do not like Parabola cflags/ldflags, though it would be nice to have the flags for userspace tools +options=(!makeflags !buildflags) +replaces=(${pkgname}-parabola) +conflicts=(${pkgname}-parabola) +makedepends=(git python2 nasm upx asciidoc) +makedepends_x86_64=(lib32-glibc) # efi32 needs it +optdepends=('perl-crypt-passwdmd5: For md5pass' + 'perl-digest-sha1: For sha1pass' + 'mtools: For mkdiskimage and syslinux support' + 'gptfdisk: For GPT support' + 'util-linux: For isohybrid' + 'efibootmgr: For EFI support' + 'dosfstools: For EFI support') + +# The syslinux-install_update script is maintained at https://gist.github.com/pyther/772138 +# Script not yet updated for syslinux-efi +source=(git://git.kernel.org/pub/scm/boot/syslinux/syslinux.git#tag=$_tag + git://git.code.sf.net/p/gnu-efi/code#commit=ab54e2b40e914d0ca01dc3d44c8d4eb8517bf999 + syslinux.cfg + syslinux-install_update + btrfs-fix.patch::http://repo.or.cz/syslinux.git/patch/548386049cd41e887079cdb904d3954365eb28f3?hp=721a0af2f0ba111c31685c5f6c5481eb25346971 + gcc-fix-alignment.patch::http://repo.or.cz/syslinux.git/patch/e5f2b577ded109291c9632dacb6eaa621d8a59fe?hp=8dc6d758b564a1ccc44c3ae11f265d43628219ce + dont-guess-alignment.patch::http://repo.or.cz/syslinux.git/patch/0cc9a99e560a2f52bcf052fd85b1efae35ee812f?hp=e5f2b577ded109291c9632dacb6eaa621d8a59fe + kdb-230.patch::http://repo.or.cz/syslinux.git/patch/138e850fab106b5235178848b3e0d33e25f4d3a2 + correct_base_type.patch::http://repo.or.cz/syslinux.git/patch/83aad4f + set_mode_base.patch::http://repo.or.cz/syslinux.git/patch/0a2dbb3 + fix_return_pointer.patch::http://repo.or.cz/syslinux.git/patch/8dc6d758b564a1ccc44c3ae11f265d43628219ce + support-ext4-64bit.patch::http://repo.or.cz/syslinux.git/patch/af7e95c32cea40c1e443ae301e64b27f068b4915 + efi_no_kbd.patch::http://repo.or.cz/syslinux.git/patch/73bb3701a19a9eeb30b6f77ff7612ca2a9cd3f38 + fix_infinite_loop_tests.patch + syslinux-sysmacros.patch + gnu-efi-git.patch + 0016-strip-gnu-property.patch + splash.png) +sha1sums=('SKIP' + 'SKIP' + 'e40acf4cf9d05ec000c59284f959d1540b35a3be' + 'df5160a138ca8c6502d67fe1a64fec78b50e82c2' + '6ebf77bf028c928a6ef33dadeee7402b3113b6d3' + 'eaa9f5cd82b501f076ece4812d2d37f49d02caae' + 'c6a6e96e233b2f8105503725cd614abc1bac2845' + 'f50e0a92c65536ef73a84614d489e52d9d1db329' + 'e24bf5b1617bab4a3f46925c5a8ee6079f4686bf' + '500c174fce91133d40024b28f6f5cedb144b84c2' + 'b3d2196aaec154749c5b796c6d9bfd605a918cf8' + 'fe3ab41235aa57259bb6af8cc30c5877c1d8fb57' + '26d9596fd2b2fd92c30b8a441c18176c6b4e0f4d' + '7ecb02550666dfafeb0b22a67dcc34caa4b79767' + '52c5233da147acd41d542b1673835be966b561e3' + '324af118594e6fb0864ef4905ce47d95c4d8e6ef' + 'd85d3a2c237472cecf68aee493ee2028ebab349b' + 'aab1c7789e0d7290fe87538abad181abac069d40') + +_targets='bios efi32' +case "$CARCH" in + x86_64) _targets+=' efi64' ;; +esac + +prepare() { + cd syslinux + + # FS#48253 + patch -p1 < ../gcc-fix-alignment.patch + patch -p1 < ../dont-guess-alignment.patch + + # FS#48214 + patch -p1 < ../btrfs-fix.patch + + # FS#49046 + patch -p1 < ../kdb-230.patch + + # FS#53083 + patch -p1 < ../correct_base_type.patch + patch -p1 < ../set_mode_base.patch + + # FS#49250 + patch -p1 < ../fix_return_pointer.patch + + # fix infinite loop in load_linux + patch -p1 < ../fix_infinite_loop_tests.patch + + # FS#58137 + patch -p1 < ../support-ext4-64bit.patch + + # FS#59450 + patch -p1 < ../efi_no_kbd.patch + + patch -p1 < ../syslinux-sysmacros.patch + + patch -p1 < ../gnu-efi-git.patch + + patch -p1 < ../0016-strip-gnu-property.patch + + # do not swallow efi compilation output to make debugging easier + sed 's|> /dev/null 2>&1||' -i efi/check-gnu-efi.sh + + # disable debug and development flags to reduce bootloader size + truncate --size 0 mk/devel.mk + + mkdir -p gnu-efi + cp -rv $srcdir/code/gnu-efi-3.0 gnu-efi +} + +build() { + cd syslinux + export LDFLAGS+=--no-dynamic-linker # workaround for binutils 2.28 http://www.syslinux.org/wiki/index.php?title=Building + export EXTRA_CFLAGS=-fno-PIE # to fix gpxe build + make PYTHON=python2 $_targets +} + +check() { + cd syslinux + make unittest +} + +package() { + cd syslinux + make $_targets install INSTALLROOT="$pkgdir" SBINDIR=/usr/bin MANDIR=/usr/share/man AUXDIR=/usr/lib/syslinux + + rm -r "$pkgdir"/usr/lib/syslinux/{com32,dosutil,syslinux.com} + install -D -m644 COPYING "$pkgdir"/usr/share/licenses/syslinux/COPYING + install -d "$pkgdir"/usr/share/doc + cp -ar doc "$pkgdir"/usr/share/doc/syslinux + + install -d "$pkgdir"/usr/lib/syslinux/bios + mv "$pkgdir"/usr/lib/syslinux/{*.bin,*.c32,*.0,memdisk} "$pkgdir"/usr/lib/syslinux/bios + + install -D -m0644 ../syslinux.cfg "$pkgdir"/boot/syslinux/syslinux.cfg + install -D -m0755 ../syslinux-install_update "$pkgdir"/usr/bin/syslinux-install_update + install -D -m0644 ../splash.png "$pkgdir"/boot/syslinux/splash.png +} diff --git a/libre-testing/syslinux/fix_infinite_loop_tests.patch b/libre-testing/syslinux/fix_infinite_loop_tests.patch new file mode 100644 index 000000000..a86c842dd --- /dev/null +++ b/libre-testing/syslinux/fix_infinite_loop_tests.patch @@ -0,0 +1,16 @@ +diff --git a/com32/lib/syslinux/tests/load_linux.c b/com32/lib/syslinux/tests/load_linux.c +index ed973841..751b8b24 100644 +--- a/com32/lib/syslinux/tests/load_linux.c ++++ b/com32/lib/syslinux/tests/load_linux.c +@@ -38,8 +38,10 @@ int syslinux_shuffle_boot_rm(struct syslinux_movelist *fraglist, + while (ml) { + addr_t cmdline_addr, last_lowmem_addr; + +- if (ml->src != __test_cmdline) ++ if (ml->src != __test_cmdline) { ++ ml = ml->next; + continue; ++ } + + last_lowmem_addr = __test_cmdline_addr; + cmdline_addr = ml->dst; diff --git a/libre-testing/syslinux/gnu-efi-git.patch b/libre-testing/syslinux/gnu-efi-git.patch new file mode 100644 index 000000000..974a49c41 --- /dev/null +++ b/libre-testing/syslinux/gnu-efi-git.patch @@ -0,0 +1,28 @@ +--- a/efi/build-gnu-efi.sh 2014-10-06 11:27:44.000000000 -0500 ++++ b/efi/build-gnu-efi.sh 2018-02-05 04:53:03.458264480 -0500 +@@ -27,11 +27,6 @@ + exit 1 + fi + +-( +- cd ../.. +- git submodule update --init +-) +- + mkdir -p "$objdir/gnu-efi" + cd "$objdir/gnu-efi" + +--- a/efi/clean-gnu-efi.sh 2014-10-06 11:27:44.000000000 -0500 ++++ b/efi/clean-gnu-efi.sh 2018-02-05 04:54:39.959105784 -0500 +@@ -21,11 +21,6 @@ + ARCH="$1" + objdir=$(readlink -f "$2") + +-( +- cd ../.. +- git submodule update --init +-) +- + if [ -d "$objdir/gnu-efi" ];then + cd "$objdir/gnu-efi" + EFIDIR="$(readlink -f "$objdir/../gnu-efi/gnu-efi-3.0")" diff --git a/libre-testing/syslinux/splash.png b/libre-testing/syslinux/splash.png new file mode 100644 index 000000000..03e9f194b Binary files /dev/null and b/libre-testing/syslinux/splash.png differ diff --git a/libre-testing/syslinux/splash.svg b/libre-testing/syslinux/splash.svg new file mode 100644 index 000000000..c1b225e1b --- /dev/null +++ b/libre-testing/syslinux/splash.svg @@ -0,0 +1,284 @@ + + + Parabola GNU/Linux-libre + + + + image/svg+xml + + Parabola GNU/Linux-libre + + 2015/02/28 + + + Jorge Araya Navarro + José Miguel Silva Lara + + + + + Márcio Alexandre Silva Delgado + + + + + CC BY-SA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libre-testing/syslinux/syslinux-6.02-fix-bios-isolinux.patch b/libre-testing/syslinux/syslinux-6.02-fix-bios-isolinux.patch new file mode 100644 index 000000000..48df46f12 --- /dev/null +++ b/libre-testing/syslinux/syslinux-6.02-fix-bios-isolinux.patch @@ -0,0 +1,12 @@ +diff --git a/core/isolinux.asm b/core/isolinux.asm +index bd4e9556922d..c4db4133e274 100644 +--- a/core/isolinux.asm ++++ b/core/isolinux.asm +@@ -420,7 +420,7 @@ MaxLMA equ 384*1024 ; Reasonable limit (384K) + call getlinsec + pop eax + pop cx +- mov dx,cx ++ movzx edx,cx + pop bp + pop bx diff --git a/libre-testing/syslinux/syslinux-6.02-fix-chainloading.patch b/libre-testing/syslinux/syslinux-6.02-fix-chainloading.patch new file mode 100644 index 000000000..6fd7ef4a8 --- /dev/null +++ b/libre-testing/syslinux/syslinux-6.02-fix-chainloading.patch @@ -0,0 +1,47 @@ +Reported-by: Dark Raven +Signed-off-by: Raphael S. Carvalho +--- + com32/lib/syslinux/disk.c | 22 ++++++++++++++-------- + 1 files changed, 14 insertions(+), 8 deletions(-) + +diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c +index 0b0c737..47ecb52 100644 +--- a/com32/lib/syslinux/disk.c ++++ b/com32/lib/syslinux/disk.c +@@ -171,22 +171,28 @@ out: + static void *ebios_setup(const struct disk_info *const diskinfo, com32sys_t *inreg, + uint64_t lba, uint8_t count, uint8_t op_code) + { +- static __lowmem struct disk_ebios_dapa dapa; ++ static struct disk_ebios_dapa *dapa = NULL; + void *buf; + ++ if (!dapa) { ++ dapa = lmalloc(sizeof *dapa); ++ if (!dapa) ++ return NULL; ++ } ++ + buf = lmalloc(count * diskinfo->bps); + if (!buf) + return NULL; + +- dapa.len = sizeof(dapa); +- dapa.count = count; +- dapa.off = OFFS(buf); +- dapa.seg = SEG(buf); +- dapa.lba = lba; ++ dapa->len = sizeof(*dapa); ++ dapa->count = count; ++ dapa->off = OFFS(buf); ++ dapa->seg = SEG(buf); ++ dapa->lba = lba; + + inreg->eax.b[1] = op_code; +- inreg->esi.w[0] = OFFS(&dapa); +- inreg->ds = SEG(&dapa); ++ inreg->esi.w[0] = OFFS(dapa); ++ inreg->ds = SEG(dapa); + inreg->edx.b[0] = diskinfo->disk; + + return buf; diff --git a/libre-testing/syslinux/syslinux-6.02-fix-efi-ovmf.patch b/libre-testing/syslinux/syslinux-6.02-fix-efi-ovmf.patch new file mode 100644 index 000000000..f33f4c1de --- /dev/null +++ b/libre-testing/syslinux/syslinux-6.02-fix-efi-ovmf.patch @@ -0,0 +1,621 @@ +The value of the field rva_and_sizes_nr is used by OVMF to check the +consistency of the PE file with respect to the field optional_hdr_sz. It +now have the right value. + +Signed-off-by: Celelibi +--- + efi/wrapper.c | 6 +++--- + efi/wrapper.h | 28 ++++++++++++++++------------ + 2 files changed, 19 insertions(+), 15 deletions(-) + +diff --git a/efi/wrapper.c b/efi/wrapper.c +index 04c895f..ec77271 100644 +--- a/efi/wrapper.c ++++ b/efi/wrapper.c +@@ -102,7 +102,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + e_hdr.image_sz = total_sz; + e_hdr.headers_sz = 512; + e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; +- e_hdr.rva_and_sizes_nr = 1; ++ e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t); + fwrite(&e_hdr, sizeof(e_hdr), 1, f); + } + else if (class == ELFCLASS64) { +@@ -130,7 +130,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + e_hdr_pe32p.image_sz = total_sz; + e_hdr_pe32p.headers_sz = 512; + e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; +- e_hdr_pe32p.rva_and_sizes_nr = 1; ++ e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t); + fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f); + } + +@@ -237,7 +237,7 @@ int main(int argc, char **argv) + fprintf(stderr, "Unsupported architecture\n"); + exit(EXIT_FAILURE); + } +- ++ + if (id[EI_MAG0] != ELFMAG0 || + id[EI_MAG1] != ELFMAG1 || + id[EI_MAG2] != ELFMAG2 || +diff --git a/efi/wrapper.h b/efi/wrapper.h +index 4f76991..0e6b38e 100644 +--- a/efi/wrapper.h ++++ b/efi/wrapper.h +@@ -102,12 +102,14 @@ struct extra_hdr { + __uint32_t heap_commit_sz; + __uint32_t loader_flags; + __uint32_t rva_and_sizes_nr; +- __uint64_t export_table; +- __uint64_t import_table; +- __uint64_t resource_table; +- __uint64_t exception_table; +- __uint64_t certification_table; +- __uint64_t base_relocation_table; ++ struct { ++ __uint64_t export_table; ++ __uint64_t import_table; ++ __uint64_t resource_table; ++ __uint64_t exception_table; ++ __uint64_t certification_table; ++ __uint64_t base_relocation_table; ++ } data_directory; + } __packed; + + /* Extra header for PE32+ format +@@ -136,12 +138,14 @@ struct extra_hdr_pe32p { + __uint64_t heap_commit_sz; + __uint32_t loader_flags; + __uint32_t rva_and_sizes_nr; +- __uint64_t export_table; +- __uint64_t import_table; +- __uint64_t resource_table; +- __uint64_t exception_table; +- __uint64_t certification_table; +- __uint64_t base_relocation_table; ++ struct { ++ __uint64_t export_table; ++ __uint64_t import_table; ++ __uint64_t resource_table; ++ __uint64_t exception_table; ++ __uint64_t certification_table; ++ __uint64_t base_relocation_table; ++ } data_directory; + } __packed; + + struct section { +In the generated PE file, the section header for the .text section used +to address more than the whole file. Starting at offset 0 (before the +end of the headers) is illegal and is rejected by OVMF. Giving a size +greater than the actual file size is also illegal and rejected. + +Moreover, the actual data inside the PE file have to be aligned to at +least 512 bytes. Hence, .text need to be aligned as well. + +Signed-off-by: Celelibi +--- + efi/wrapper.c | 44 +++++++++++++++++++++++++------------------- + 1 file changed, 25 insertions(+), 19 deletions(-) + +diff --git a/efi/wrapper.c b/efi/wrapper.c +index ec77271..bd2c175 100644 +--- a/efi/wrapper.c ++++ b/efi/wrapper.c +@@ -54,11 +54,15 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + struct coff_hdr c_hdr; + struct header hdr; + struct coff_reloc c_rel; +- __uint32_t total_sz = so_size; ++ __uint32_t total_sz = data_size; + __uint32_t dummy = 0; + __uint32_t hdr_sz; + __uint32_t reloc_start, reloc_end; + ++ hdr_sz = 512; ++ total_sz += hdr_sz; ++ entry += hdr_sz; ++ + memset(&hdr, 0, sizeof(hdr)); + hdr.msdos_signature = MSDOS_SIGNATURE; + +@@ -77,11 +81,6 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + c_hdr.nr_sections = 2; + c_hdr.nr_syms = 1; + if (class == ELFCLASS32) { +- hdr_sz = sizeof(o_hdr) + sizeof(t_sec) + sizeof(e_hdr) + +- sizeof(r_sec) + sizeof(c_hdr) + sizeof(hdr) + sizeof(c_rel) +- + sizeof(dummy); +- total_sz += hdr_sz; +- entry += hdr_sz; + c_hdr.arch = IMAGE_FILE_MACHINE_I386; + c_hdr.characteristics = IMAGE_FILE_32BIT_MACHINE | + IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | +@@ -92,25 +91,20 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + o_hdr.format = PE32_FORMAT; + o_hdr.major_linker_version = 0x02; + o_hdr.minor_linker_version = 0x14; +- o_hdr.code_sz = total_sz; ++ o_hdr.code_sz = data_size; + o_hdr.entry_point = entry; + o_hdr.initialized_data_sz = data_size; + fwrite(&o_hdr, sizeof(o_hdr), 1, f); + memset(&e_hdr, 0, sizeof(e_hdr)); + e_hdr.section_align = 4096; + e_hdr.file_align = 512; +- e_hdr.image_sz = total_sz; +- e_hdr.headers_sz = 512; ++ e_hdr.image_sz = hdr_sz + so_size; ++ e_hdr.headers_sz = hdr_sz; + e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; + e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t); + fwrite(&e_hdr, sizeof(e_hdr), 1, f); + } + else if (class == ELFCLASS64) { +- hdr_sz = sizeof(o_hdr_pe32p) + sizeof(t_sec) + sizeof(e_hdr_pe32p) + +- sizeof(r_sec) + sizeof(c_hdr) + sizeof(hdr) + sizeof(c_rel) +- + sizeof(dummy); +- total_sz += hdr_sz; +- entry += hdr_sz; + c_hdr.arch = IMAGE_FILE_MACHINE_X86_64; + c_hdr.characteristics = IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | + IMAGE_FILE_LINE_NUMBERS_STRIPPED; +@@ -120,15 +114,15 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + o_hdr_pe32p.format = PE32P_FORMAT; + o_hdr_pe32p.major_linker_version = 0x02; + o_hdr_pe32p.minor_linker_version = 0x14; +- o_hdr_pe32p.code_sz = total_sz; ++ o_hdr_pe32p.code_sz = data_size; + o_hdr_pe32p.entry_point = entry; + o_hdr.initialized_data_sz = data_size; + fwrite(&o_hdr_pe32p, sizeof(o_hdr_pe32p), 1, f); + memset(&e_hdr_pe32p, 0, sizeof(e_hdr)); + e_hdr_pe32p.section_align = 4096; + e_hdr_pe32p.file_align = 512; +- e_hdr_pe32p.image_sz = total_sz; +- e_hdr_pe32p.headers_sz = 512; ++ e_hdr_pe32p.image_sz = hdr_sz + so_size; ++ e_hdr_pe32p.headers_sz = hdr_sz; + e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; + e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t); + fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f); +@@ -136,8 +130,10 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + + memset(&t_sec, 0, sizeof(t_sec)); + strcpy((char *)t_sec.name, ".text"); +- t_sec.virtual_sz = total_sz; +- t_sec.raw_data_sz = total_sz; ++ t_sec.virtual_sz = data_size; ++ t_sec.virtual_address = hdr_sz; ++ t_sec.raw_data_sz = t_sec.virtual_sz; ++ t_sec.raw_data = t_sec.virtual_address; + t_sec.characteristics = IMAGE_SCN_CNT_CODE | + IMAGE_SCN_ALIGN_16BYTES | IMAGE_SCN_MEM_EXECUTE | + IMAGE_SCN_MEM_READ; +@@ -163,6 +159,16 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + fwrite(&c_rel, sizeof(c_rel), 1, f); + fwrite(&dummy, sizeof(dummy), 1, f); + ++ /* ++ * Add some padding to align the ELF as needed ++ */ ++ if (ftell(f) > t_sec.virtual_address) { ++ // A fseek that rewind would be a bug hard to track ++ fprintf(stderr, "PE+ headers are too large.\n"); ++ exit(EXIT_FAILURE); ++ } ++ ++ fseek(f, t_sec.virtual_address, SEEK_SET); + } + + static void usage(char *progname) +There is no need to have a relocation section that nothing points at. +The image is still seen as relocatable as long as the Characteristics of +the FileHeader do not say otherwise. + +Moreover, the field base_relocation_table wasn't initialized properly +leading to unpredictable bugs. + +Signed-off-by: Celelibi +--- + +I'm not 100% positive about the uselessness of the relocation section. However: +1) it works on my real hardware; +2) OVMF doesn't check the section headers at all; +3) all the docs I could find say that the section names are arbitrary; +4) the only way to make the relocation actually happen is by setting the +base_relocation_table field of the extra headers to point to this section; +5) The right way to indicate the image is not relocatable would be by setting +the characteristics IMAGE_FILE_RELOCS_STRIPPED in the coff header. + +Moreover, the relocation entry cannot be inserted before the end of the headers +(512 bytes), this mean we would have to push everything a few bytes further. +And I think it's better if it can be avoided. :) + + efi/wrapper.c | 28 +++------------------------- + 1 file changed, 3 insertions(+), 25 deletions(-) + +diff --git a/efi/wrapper.c b/efi/wrapper.c +index bd2c175..9652368 100644 +--- a/efi/wrapper.c ++++ b/efi/wrapper.c +@@ -48,14 +48,12 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + { + struct optional_hdr o_hdr; + struct optional_hdr_pe32p o_hdr_pe32p; +- struct section t_sec, r_sec; ++ struct section t_sec; + struct extra_hdr e_hdr; + struct extra_hdr_pe32p e_hdr_pe32p; + struct coff_hdr c_hdr; + struct header hdr; +- struct coff_reloc c_rel; + __uint32_t total_sz = data_size; +- __uint32_t dummy = 0; + __uint32_t hdr_sz; + __uint32_t reloc_start, reloc_end; + +@@ -78,7 +76,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + fwrite(&hdr, sizeof(hdr), 1, f); + + memset(&c_hdr, 0, sizeof(c_hdr)); +- c_hdr.nr_sections = 2; ++ c_hdr.nr_sections = 1; + c_hdr.nr_syms = 1; + if (class == ELFCLASS32) { + c_hdr.arch = IMAGE_FILE_MACHINE_I386; +@@ -118,7 +116,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + o_hdr_pe32p.entry_point = entry; + o_hdr.initialized_data_sz = data_size; + fwrite(&o_hdr_pe32p, sizeof(o_hdr_pe32p), 1, f); +- memset(&e_hdr_pe32p, 0, sizeof(e_hdr)); ++ memset(&e_hdr_pe32p, 0, sizeof(e_hdr_pe32p)); + e_hdr_pe32p.section_align = 4096; + e_hdr_pe32p.file_align = 512; + e_hdr_pe32p.image_sz = hdr_sz + so_size; +@@ -140,26 +138,6 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + fwrite(&t_sec, sizeof(t_sec), 1, f); + + /* +- * Write our dummy relocation and reloc section. +- */ +- memset(&r_sec, 0, sizeof(r_sec)); +- strcpy((char *)r_sec.name, ".reloc"); +- r_sec.virtual_sz = sizeof(c_rel); +- r_sec.virtual_address = ftell(f) + sizeof(r_sec); +- r_sec.raw_data_sz = r_sec.virtual_sz; +- r_sec.raw_data = r_sec.virtual_address; +- r_sec.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | +- IMAGE_SCN_ALIGN_1BYTES | IMAGE_SCN_MEM_DISCARDABLE | +- IMAGE_SCN_MEM_READ; +- fwrite(&r_sec, sizeof(r_sec), 1, f); +- +- memset(&c_rel, 0, sizeof(c_rel)); +- c_rel.virtual_address = ftell(f) + sizeof(c_rel); +- c_rel.symtab_index = 10; +- fwrite(&c_rel, sizeof(c_rel), 1, f); +- fwrite(&dummy, sizeof(dummy), 1, f); +- +- /* + * Add some padding to align the ELF as needed + */ + if (ftell(f) > t_sec.virtual_address) { +PE headers code_sz and image_sz indicate more or less, the size of the +file and the size of the in-memory image. They are now given the right +value. + +In the ELF format, only the program headers are reliable to determine +the actually needed part of the file and the in-memory size. + +The .bss section should always be marked as NOLOAD for ld since its +content shouldn't be included into the binary file. + +Signed-off-by: Celelibi +--- + +Again, I'm not 100% positive about the semantics of NOLOAD in a linker script. +However I found this make things work better. +Actually the file core/fs/fs.o have a .bss16 section that is not empty. If I +understood correctly, only .bss can be empty in a .o. Thus ld generates the +zeros that belong to that section in the .o. Then, when merging the section +.bss16 into the .bss of syslinux.so, ld is forced to generate ALL the zeros +that belong to the .bss section. Marking this section as NOLOAD make ld to +ignore its content but still produce a PT_LOAD program header with the right +memory size, as needed for the bss. + + efi/i386/syslinux.ld | 4 +- + efi/wrapper.c | 138 +++++++++++++++---------------------------------- + efi/x86_64/syslinux.ld | 4 +- + 3 files changed, 45 insertions(+), 101 deletions(-) + +diff --git a/efi/i386/syslinux.ld b/efi/i386/syslinux.ld +index 523a9b9..bab3fc7 100644 +--- a/efi/i386/syslinux.ld ++++ b/efi/i386/syslinux.ld +@@ -136,7 +136,7 @@ SECTIONS + *(.strtab) + } + +- .bss : { ++ .bss (NOLOAD) : { + /* the EFI loader doesn't seem to like a .bss section, + so we stick it all into .data: */ + __bss_start = .; +@@ -153,7 +153,7 @@ SECTIONS + __bss_dwords = (__bss_len + 3) >> 2; + + . = ALIGN(128); +- ++ + /* Very large objects which don't need to be zeroed */ + + .hugebss : { +diff --git a/efi/wrapper.c b/efi/wrapper.c +index 9652368..a5247ae 100644 +--- a/efi/wrapper.c ++++ b/efi/wrapper.c +@@ -35,7 +35,7 @@ typedef Elf64_Addr Elf_Addr; + #endif + + /* +- * 'so_size' is the file size of the ELF shared object. ++ * 'so_memsz' is the size of the ELF shared object once loaded. + * 'data_size' is the size of initialised data in the shared object. + * 'class' dictates how the header is written + * For 32bit machines (class == ELFCLASS32), the optional +@@ -44,7 +44,7 @@ typedef Elf64_Addr Elf_Addr; + * header includes PE32+header fields + */ + static void write_header(FILE *f, __uint32_t entry, size_t data_size, +- __uint32_t so_size, __uint8_t class) ++ __uint32_t so_memsz, __uint8_t class) + { + struct optional_hdr o_hdr; + struct optional_hdr_pe32p o_hdr_pe32p; +@@ -96,7 +96,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + memset(&e_hdr, 0, sizeof(e_hdr)); + e_hdr.section_align = 4096; + e_hdr.file_align = 512; +- e_hdr.image_sz = hdr_sz + so_size; ++ e_hdr.image_sz = hdr_sz + so_memsz; + e_hdr.headers_sz = hdr_sz; + e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; + e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t); +@@ -119,7 +119,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, + memset(&e_hdr_pe32p, 0, sizeof(e_hdr_pe32p)); + e_hdr_pe32p.section_align = 4096; + e_hdr_pe32p.file_align = 512; +- e_hdr_pe32p.image_sz = hdr_sz + so_size; ++ e_hdr_pe32p.image_sz = hdr_sz + so_memsz; + e_hdr_pe32p.headers_sz = hdr_sz; + e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; + e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t); +@@ -157,17 +157,16 @@ static void usage(char *progname) + + int main(int argc, char **argv) + { +- struct stat st; + Elf32_Ehdr e32_hdr; + Elf64_Ehdr e64_hdr; + __uint32_t entry; + __uint8_t class; +- __uint64_t shoff; +- __uint16_t shnum, shentsize, shstrndx; ++ __uint64_t phoff = 0; ++ __uint16_t phnum = 0, phentsize = 0; + unsigned char *id; + FILE *f_in, *f_out; + void *buf; +- size_t datasz, rv; ++ size_t datasz, memsz, rv; + + if (argc < 3) { + usage(argv[0]); +@@ -180,11 +179,6 @@ int main(int argc, char **argv) + exit(EXIT_FAILURE); + } + +- if (stat(argv[1], &st) != 0) { +- perror("stat"); +- exit(EXIT_FAILURE); +- } +- + f_out = fopen(argv[2], "w"); + if (!f_out) { + perror("fopen"); +@@ -194,15 +188,14 @@ int main(int argc, char **argv) + /* + * Parse the ELF header and find the entry point. + */ +- fread((void *)&e32_hdr, sizeof(e32_hdr), 1, f_in); ++ fread((void *)&e32_hdr, sizeof(e32_hdr), 1, f_in); + if (e32_hdr.e_ident[EI_CLASS] == ELFCLASS32) { + id = e32_hdr.e_ident; + class = ELFCLASS32; + entry = e32_hdr.e_entry; +- shoff = e32_hdr.e_shoff; +- shnum = e32_hdr.e_shnum; +- shstrndx = e32_hdr.e_shstrndx; +- shentsize = e32_hdr.e_shentsize; ++ phoff = e32_hdr.e_phoff; ++ phnum = e32_hdr.e_phnum; ++ phentsize = e32_hdr.e_phentsize; + } + else if (e32_hdr.e_ident[EI_CLASS] == ELFCLASS64) { + /* read the header again for x86_64 +@@ -213,10 +206,9 @@ int main(int argc, char **argv) + fread((void *)&e64_hdr, sizeof(e64_hdr), 1, f_in); + id = e64_hdr.e_ident; + entry = e64_hdr.e_entry; +- shoff = e64_hdr.e_shoff; +- shnum = e64_hdr.e_shnum; +- shstrndx = e64_hdr.e_shstrndx; +- shentsize = e64_hdr.e_shentsize; ++ phoff = e64_hdr.e_phoff; ++ phnum = e64_hdr.e_phnum; ++ phentsize = e64_hdr.e_phentsize; + } else { + fprintf(stderr, "Unsupported architecture\n"); + exit(EXIT_FAILURE); +@@ -230,98 +222,47 @@ int main(int argc, char **argv) + exit(EXIT_FAILURE); + } + +- if (!shoff || !shnum || (shstrndx == SHN_UNDEF)) { +- fprintf(stderr, "Cannot find section table\n"); ++ if (!phoff || !phnum) { ++ fprintf(stderr, "Cannot find segment table\n"); + exit(EXIT_FAILURE); + } + + /* +- * Find the beginning of the .bss section. Everything preceding +- * it is copied verbatim to the output file. ++ * Find the LOAD program header. Everything in this segment ++ * is copied verbatim to the output file. ++ * Although there may be several LOAD program headers, only ++ * one is currently copied. + */ + if (e32_hdr.e_ident[EI_CLASS] == ELFCLASS32) { +- const char *shstrtab, *name; +- Elf32_Shdr shdr; ++ Elf32_Phdr phdr; + int i; +- void *strtab; +- +- fseek(f_in, shoff, SEEK_SET); +- +- /* First find the strtab section */ +- fseek(f_in, shstrndx * shentsize, SEEK_CUR); +- fread(&shdr, sizeof(shdr), 1, f_in); + +- strtab = malloc(shdr.sh_size); +- if (!strtab) { +- fprintf(stderr, "Failed to malloc strtab\n"); +- exit(EXIT_FAILURE); +- } +- +- fseek(f_in, shdr.sh_offset, SEEK_SET); +- fread(strtab, shdr.sh_size, 1, f_in); +- +- /* Now search for the .bss section */ +- fseek(f_in, shoff, SEEK_SET); +- for (i = 0; i < shnum; i++) { +- rv = fread(&shdr, sizeof(shdr), 1, f_in); +- if (!rv) { +- fprintf(stderr, "Failed to read section table\n"); +- exit(EXIT_FAILURE); +- } ++ /* Find the first LOAD program header */ ++ for (i = 0; i < phnum; i++) { ++ fseek(f_in, phoff + i * phentsize, SEEK_SET); ++ fread(&phdr, sizeof(phdr), 1, f_in); + +- name = strtab + shdr.sh_name; +- if (!strcmp(name, ".bss")) ++ if (phdr.p_type == PT_LOAD) + break; + } + +- if (i == shnum) { +- fprintf(stderr, "Failed to find .bss section\n"); +- exit(EXIT_FAILURE); +- } +- +- datasz = shdr.sh_offset; +- } +- else if (e32_hdr.e_ident[EI_CLASS] == ELFCLASS64) { +- const char *shstrtab, *name; +- Elf64_Shdr shdr; ++ datasz = phdr.p_filesz; ++ memsz = phdr.p_memsz; ++ } else if (e32_hdr.e_ident[EI_CLASS] == ELFCLASS64) { ++ Elf64_Phdr phdr; + int i; +- void *strtab; +- +- fseek(f_in, shoff, SEEK_SET); + +- /* First find the strtab section */ +- fseek(f_in, shstrndx * shentsize, SEEK_CUR); +- fread(&shdr, sizeof(shdr), 1, f_in); +- +- strtab = malloc(shdr.sh_size); +- if (!strtab) { +- fprintf(stderr, "Failed to malloc strtab\n"); +- exit(EXIT_FAILURE); +- } ++ /* Find the first LOAD program header */ ++ for (i = 0; i < phnum; i++) { ++ fseek(f_in, phoff + i * phentsize, SEEK_SET); ++ fread(&phdr, sizeof(phdr), 1, f_in); + +- fseek(f_in, shdr.sh_offset, SEEK_SET); +- fread(strtab, shdr.sh_size, 1, f_in); +- +- /* Now search for the .bss section */ +- fseek(f_in, shoff, SEEK_SET); +- for (i = 0; i < shnum; i++) { +- rv = fread(&shdr, sizeof(shdr), 1, f_in); +- if (!rv) { +- fprintf(stderr, "Failed to read section table\n"); +- exit(EXIT_FAILURE); +- } +- +- name = strtab + shdr.sh_name; +- if (!strcmp(name, ".bss")) ++ if (phdr.p_type == PT_LOAD) + break; + } + +- if (i == shnum) { +- fprintf(stderr, "Failed to find .bss section\n"); +- exit(EXIT_FAILURE); +- } +- +- datasz = shdr.sh_offset; ++ datasz = phdr.p_filesz; ++ memsz = phdr.p_memsz; + } + + buf = malloc(datasz); +@@ -330,7 +271,7 @@ int main(int argc, char **argv) + exit(EXIT_FAILURE); + } + +- write_header(f_out, entry, datasz, st.st_size, class); ++ write_header(f_out, entry, datasz, memsz, class); + + /* Write out the entire ELF shared object */ + rewind(f_in); +@@ -341,5 +282,8 @@ int main(int argc, char **argv) + } + + fwrite(buf, datasz, rv, f_out); ++ free(buf); ++ fclose(f_out); ++ fclose(f_in); + return 0; + } +diff --git a/efi/x86_64/syslinux.ld b/efi/x86_64/syslinux.ld +index 95160bd..450641c 100644 +--- a/efi/x86_64/syslinux.ld ++++ b/efi/x86_64/syslinux.ld +@@ -136,7 +136,7 @@ SECTIONS + *(.strtab) + } + +- .bss : { ++ .bss (NOLOAD) : { + /* the EFI loader doesn't seem to like a .bss section, + so we stick it all into .data: */ + __bss_start = .; +@@ -153,7 +153,7 @@ SECTIONS + __bss_dwords = (__bss_len + 3) >> 2; + + . = ALIGN(128); +- ++ + /* Very large objects which don't need to be zeroed */ + + .hugebss : { diff --git a/libre-testing/syslinux/syslinux-install_update b/libre-testing/syslinux/syslinux-install_update new file mode 100644 index 000000000..63bbd03c6 --- /dev/null +++ b/libre-testing/syslinux/syslinux-install_update @@ -0,0 +1,465 @@ +#!/usr/bin/bash +# +# Syslinux Installer / Updater Script (for BIOS only) +# Copyright (C) 2011-2013 Matthew Gyurgyik +# Copyright (C) 2013 Keshav Padram Amburay <(the) (ddoott) (ridikulus) (ddoott) (rat) (aatt) (gemmaeiil) (ddoott) (ccoomm)> +# +# This program is free software; you can redistribute it and/or +# modify it 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#----------------- +# ChangeLog: +# 2013-10-23 : Keshav Padram Amburay : Updated script to work with Syslinux 6.02 Arch Linux pkg +#----------------- +# Exit Codes: +# 1 - get_boot_device or other function failed +# 2 - install/update failed +# 3 - set_active failed +# 4 - install_mbr failed +#----------------- + +shopt -s nullglob + +bios_libpath="/usr/lib/syslinux/bios" +bios_bootpath="/boot/syslinux" +EXTLINUX="/usr/bin/extlinux" + +bios_autoupdate_file="/boot/syslinux/SYSLINUX_AUTOUPDATE" +pciids_file="/usr/share/hwdata/pci.ids" + +## Helper functions ## +# Taken from libui-sh +# $1 needle +# $2 set (array) haystack +check_is_in() { + local needle="$1" element + shift + for element; do + [[ $element = $needle ]] && return 0 + done + return 1 +} + +get_disk() { + local part=$1 + if [[ ! -b "${part}" ]]; then + echo >&2 "error: '$part' is not a valid block device!" + exit 1 + fi + + case "$part" in + # catch cases like mmcblk0p1 and loop0p3 + *[[:digit:]]p[[:digit:]]*) + local disk="${part%p[[:digit:]]}" # get everything before p1 + ;; + *) + local disk="${part%%[[:digit:]]*}" + ;; + esac + if [[ ! -b "${disk}" ]]; then + echo >&2 "error: '$disk' is not a valid block device!" + exit 1 + fi + echo $disk +} + +# return true when blockdevice is an md raid, otherwise return a unset value +# get all devices that are part of raid device $1 +device_is_raid() { + [[ $1 && -f /proc/mdstat ]] || return 1 + local devmajor=$(stat -c %t "$1") + (( devmajor == 9 )) +} + +mdraid_all_slaves() { + local slave slaves + for slave in /sys/class/block/${1##*/}/slaves/*; do + source "$slave/uevent" + slaves="$slaves/dev/$DEVNAME " + unset DEVNAME + done + echo $slaves +} + +# Check /sys/block to see if device is partitioned +# If we have a partitioned block device (sda1) /sys/block/sda1/dev will not exist +# However, if we have an unpartitioned block device (sda) /sys/block/sda/dev will exist +dev_is_part() { + # $1 - blockdevice + local dev=$1 + + # If block device uevent file should be found + # If a partition is passed in path shouldn't exist + if [[ $dev = *cciss* ]]; then + [[ -f /sys/block/cciss\!${dev##*/}/dev ]] && return 1 + elif [[ $dev = *ida* ]]; then + [[ -f /sys/block/ida\!${dev##*/}/dev ]] && return 1 + else + [[ -f /sys/block/${dev##*/}/dev ]] && return 1 + fi + + return 0 +} + +# If EFI PART is present in the first 8 bytes then it must be a GPT disk +device_is_gpt() { + local partsig=$(dd if="$1" skip=64 bs=8 count=1 2>/dev/null) + [[ $partsig = "EFI PART" ]] +} + +clear_gpt_attr2() { + # $1 - Block Device, no partitions + local disk=$1 + + # Special Exception for cciss controllers + if [[ $disk = *cciss* ]]; then + for part in /dev/cciss/${disk##*/}*p*; do + local partnum="${part##*[[:alpha:]]}" + sgdisk "$disk" --attributes="$partnum":clear:2 &>/dev/null + done + # Smart 2 Controllers + elif [[ $disk = *ida* ]]; then + for part in /dev/ida/${disk##*/}*p*; do + local partnum="${part##*[[:alpha:]]}" + sgdisk "$disk" --attributes="$partnum":clear:2 &>/dev/null + done + else + for part in /sys/block/${disk##*/}/${disk##*/}*; do + local partnum="${part##*[[:alpha:]]}" + sgdisk "$disk" --attributes="$partnum":clear:2 &>/dev/null + done + fi + return 0 +} + +usage() { +cat << EOF +usage: $0 options + +This script will install or upgrade Syslinux (for BIOS only) + +OPTIONS: + -h Show this message + -i Install Syslinux + -u Update Syslinux + -a Set Boot flag on boot partiton + -m Install Syslinux MBR + -s Updates Syslinux if /boot/syslinux/SYSLINUX_AUTOUPDATE exists + + Arguments Required: + -c Chroot install (ex: -c /mnt) + +Example Usage: $0 -i -a -m # (install, set boot flag, install mbr) + $0 -u # (update) +EOF +} + +# Trys to find the partition that /boot resides on +# This will either be on /boot or / (root) +getBoot() { + if [[ ! -d "$bios_bootpath" ]]; then + echo "Could not find $bios_bootpath" + echo "Is boot mounted? Is Syslinux installed?" + exit 1 + fi + + syslinux_fs=(ext2 ext3 ext4 btrfs vfat xfs) + + # Use DATA from findmnt see rc.sysint for more info + if [[ -f /proc/self/mountinfo ]]; then + read rootdev rootfs < <(findmnt -run -t noautofs -o SOURCE,FSTYPE "$CHROOT/") + read bootdev bootfs < <(findmnt -run -t noautofs -o SOURCE,FSTYPE "$CHROOT/boot") + else + echo "Could not find /proc/self/mountinfo" + echo "Are you running a kernel greater than 2.6.24?" + exit 1 + fi + + if [[ $bootfs ]]; then + if ! check_is_in "$bootfs" "${syslinux_fs[@]}"; then + echo "/boot file system is not supported by Syslinux" + exit 1 + fi + boot="boot" + bootpart="$(readlink -f "$bootdev")" + elif [[ $rootfs ]]; then + if ! check_is_in "$rootfs" "${syslinux_fs[@]}"; then + echo "/ (root) file system is not supported by Syslinux" + exit 1 + fi + boot="root" + bootpart="$(readlink -f "$rootdev")" + else + echo "Could not find filesystem on / (root) or /boot." + exit 1 + fi +} + +# We store the partition table type either gpt or mbr in var ptb +# In rare cases a user could have one raid disk using mbr and another using gpt +# In such cases we accept that the output may be incomplete + +# Calls get_ptb() for $bootpart or for all device in RAID +declare -A bootdevs +get_boot_devices() { + if device_is_raid "$bootpart"; then + slaves=$(mdraid_all_slaves "$bootpart") + + for slave in ${slaves[@]}; do + local disk=$(get_disk "$slave") + device_is_gpt "$disk" && local ptb="GPT" || local ptb="MBR" + bootdevs[$slave]="$ptb" + done + else + local disk=$(get_disk "$bootpart") + device_is_gpt "$disk" && local ptb="GPT" || local ptb="MBR" + bootdevs[$bootpart]="$ptb" + fi +} + +# Function Assumes the boot partition should be marked as active +# All other partitions should not have the boot flag set +set_active() { + # If any bootdev is a block device without partitions bail + # we want to set the boot flag on partitioned disk + for dev in "${!bootdevs[@]}"; do + dev_is_part $dev || { echo "$dev does not contain partition table. Aborting set_active!"; return 1; } + done + + # Clear BIOS Bootable Legacy Attribute for GPT drives + # In rare cases where a RAID device has slaves on the same block device + # Attribute 2 will be cleared for each partition multiple times + for dev in "${!bootdevs[@]}"; do + local ptb="${bootdevs[$dev]}" + if [[ "$ptb" = GPT ]]; then + local disk=$(get_disk "$dev") + clear_gpt_attr2 "$disk" + fi + done + + # Set the boot flag on bootdevs (generated from get_boot_devices) + for part in "${!bootdevs[@]}"; do + local ptb="${bootdevs[$part]}" + local partnum="${part##*[[:alpha:]]}" + local disk=$(get_disk "$part") + + if [[ "$ptb" = MBR ]]; then + if sfdisk "$disk" --activate "$partnum" &>/dev/null; then + echo "Boot Flag Set - $part" + else + echo "FAILED to Set the boot flag on $part" + exit 3 + fi + elif [[ "$ptb" = GPT ]]; then + if [[ ! -e /usr/bin/sgdisk ]]; then + echo "FAILED to set attribute Legacy BIOS Bootable. sgdisk is not found - please install 'gptfdisk' package." + exit 3 + fi + + if sgdisk "$disk" --attributes="$partnum":set:2 &>/dev/null; then + echo "Attribute Legacy Bios Bootable Set - $part" + else + echo "FAILED to set attribute Legacy BIOS Bootable on $part" + exit 3 + fi + fi + done + return 0 +} + +install_mbr() { + # If any bootdev is a block device without partitions bail + # we want to install the mbr to a partitioned disk + for dev in "${!bootdevs[@]}"; do + dev_is_part "$dev" || { echo "$dev does not contain partition table. Aborting MBR install."; return 1; } + done + + for part in "${!bootdevs[@]}"; do + local partnum="${part##*[[:alpha:]]}" + local disk=$(get_disk "$part") + local ptb="${bootdevs[$part]}" + + # We want to install to the root of the block device + # If the device is a partition - ABORT! + dev_is_part "$disk" && \ + { echo "ABORT! MBR installation to partition ($disk)!"; exit 4;} + + if [[ "$ptb" = MBR ]]; then + mbrfile="$bios_libpath/mbr.bin" + elif [[ "$ptb" = GPT ]]; then + mbrfile="$bios_libpath/gptmbr.bin" + fi + + if dd bs=440 count=1 conv=notrunc if="$mbrfile" of="$disk" &> /dev/null; then + echo "Installed MBR ($mbrfile) to $disk" + else + echo "Error Installing MBR ($mbrfile) to $disk" + exit 4 + fi + done + return 0 +} + +install_modules() { + # Copy all syslinux *.c32 modules to /boot + rm "$bios_bootpath"/*.c32 &> /dev/null + cp "$bios_libpath"/*.c32 "$bios_bootpath"/ &> /dev/null + + # Copy / Symlink pci.ids if pci.ids exists on the FS + if [[ -f "$pciids_file" ]]; then + rm "$bios_bootpath/pci.ids" &> /dev/null + cp "$pciids_file" "$bios_bootpath/pci.ids" &> /dev/null + fi +} + +_install() { + install_modules + + if device_is_raid "$bootpart" ; then + echo "Detected RAID on /boot - installing Syslinux with --raid" + "$EXTLINUX" --install "$bios_bootpath" --raid &> /dev/null + else + "$EXTLINUX" --install "$bios_bootpath" &> /dev/null + fi + + if (( $? )); then + echo "Syslinux BIOS install failed" + exit 2 + else + echo "Syslinux BIOS install successful" + fi + + touch "$CHROOT/$bios_autoupdate_file" +} + +update() { + install_modules + + if device_is_raid "$bootpart" ; then + echo "Detected RAID on /boot - updating Syslinux with --raid" + "$EXTLINUX" --update "$bios_bootpath" --raid &> /dev/null + else + "$EXTLINUX" --update "$bios_bootpath" &> /dev/null + fi + + if (($?)); then + echo "Syslinux BIOS update failed" + exit 2 + else + echo "Syslinux BIOS update successful" + fi +} + +if (( $# == 0 )); then + usage + exit 1 +fi + +while getopts "c:uihmas" opt; do + case $opt in + c) + CHROOT=$(readlink -e "$OPTARG") + if [[ -z $CHROOT ]]; then + echo "error: chroot path ``$OPTARG does not exist"; + exit 1 + fi + ;; + h) + USAGE="True" + ;; + i) + INSTALL="True" + ;; + u) + UPDATE="True" + ;; + m) + MBR="True" + ;; + a) + SET_ACTIVE="True" + ;; + s) + # If AUTOUPDATE_FILE does not exist exit the script + if [[ -f $bios_autoupdate_file ]]; then + UPDATE="True" + else + exit 0 + fi + ;; + *) + usage + exit 1 + ;; + esac +done + +if [[ $USAGE ]]; then + usage + exit 0 +fi + +# Display Usage Information if both Install and Update are passed +if [[ $INSTALL && $UPDATE ]]; then + usage + exit 1 +fi + +# Make sure only root can run our script +if (( $(id -u) != 0 )); then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +# If a chroot dir is path set variables to reflect chroot +if [[ "$CHROOT" ]]; then + bios_libpath="$CHROOT$bios_libpath" + bios_bootpath="$CHROOT$bios_bootpath" + EXTLINUX="$CHROOT$EXTLINUX" +fi + +# Exit if no /boot path exists +if ( f=("$bios_bootpath"/*); (( ! ${#f[@]} )) ); then + echo "Error: $bios_bootpath is empty!" + echo "Is /boot mounted?" + exit 1 +fi + +# Get the boot device if any of these options are passed +if [[ $INSTALL || $UPDATE || $SET_ACTIVE || $MBR ]]; then + getBoot +fi + +# Install or Update +if [[ $INSTALL ]]; then + _install || exit +elif [[ $UPDATE ]]; then + update || exit +fi + + +# SET_ACTIVE and MBR +if [[ $SET_ACTIVE ]] || [[ $MBR ]]; then + get_boot_devices + + if [[ $SET_ACTIVE ]]; then + set_active || exit + fi + + if [[ $MBR ]]; then + install_mbr || exit + fi +fi + +exit 0 diff --git a/libre-testing/syslinux/syslinux.cfg b/libre-testing/syslinux/syslinux.cfg new file mode 100644 index 000000000..8400d2179 --- /dev/null +++ b/libre-testing/syslinux/syslinux.cfg @@ -0,0 +1,87 @@ +# Config file for Syslinux - +# /boot/syslinux/syslinux.cfg +# +# Comboot modules: +# * menu.c32 - provides a text menu +# * vesamenu.c32 - provides a graphical menu +# * chain.c32 - chainload MBRs, partition boot sectors, Windows bootloaders +# * hdt.c32 - hardware detection tool +# * reboot.c32 - reboots the system +# +# To Use: Copy the respective files from /usr/lib/syslinux to /boot/syslinux. +# If /usr and /boot are on the same file system, symlink the files instead +# of copying them. +# +# If you do not use a menu, a 'boot:' prompt will be shown and the system +# will boot automatically after 5 seconds. +# +# Please review the wiki: https://wiki.parabola.nu/index.php/Syslinux +# The wiki provides further configuration examples + +DEFAULT parabola +PROMPT 0 # Set to 1 if you always want to display the boot: prompt +TIMEOUT 50 +# You can create syslinux keymaps with the keytab-lilo tool +#KBDMAP de.ktl + +# Menu Configuration +# Either menu.c32 or vesamenu32.c32 must be copied to /boot/syslinux +#UI menu.c32 +UI vesamenu.c32 + +# Refer to http://syslinux.zytor.com/wiki/index.php/Doc/menu +MENU TITLE Parabola GNU/Linux-libre +MENU BACKGROUND splash.png +MENU COLOR border 35;40 #ff777caa #a0000000 std +MENU COLOR title 1;35;40 #ff777caa #a0000000 std +MENU COLOR sel 7;35;47 #e0ffffff #20777caa all +MENU COLOR unsel 35;40 #ff777caa #a0000000 std +MENU COLOR help 35;40 #c0b2b2b2 #a0000000 std +MENU COLOR timeout_msg 35;40 #ff777caa #00000000 std +MENU COLOR timeout 1;35;40 #ff777caa #00000000 std +MENU COLOR msg07 35;40 #ff777caa #a0000000 std +MENU COLOR tabmsg 35;40 #ff777caa #00000000 std + +MENU WIDTH 78 +MENU MARGIN 4 +MENU ROWS 7 +MENU VSHIFT 10 +MENU TABMSGROW 14 +MENU CMDLINEROW 14 +MENU HELPMSGROW 16 +MENU HELPMSGENDROW 29 + +# boot sections follow +# +# TIP: If you want a 1024x768 framebuffer, add "vga=773" to your kernel line. +# +#-* + +LABEL parabola + MENU LABEL Parabola GNU/Linux-libre + LINUX ../vmlinuz-linux-libre + APPEND root=/dev/sda3 rw + INITRD ../initramfs-linux-libre.img + +LABEL parabolafallback + MENU LABEL Parabola GNU/Linux-libre Fallback + LINUX ../vmlinuz-linux-libre + APPEND root=/dev/sda3 rw + INITRD ../initramfs-linux-libre-fallback.img + +# If you want Memtest on syslinux, use this LABEL section to launch it (install the memtest86+ package) +# LABEL memtest +# MENU LABEL Memtest86+ +# LINUX ../memtest86+/memtest.bin + +LABEL hdt + MENU LABEL HDT (Hardware Detection Tool) + COM32 hdt.c32 + +LABEL reboot + MENU LABEL Reboot + COM32 reboot.c32 + +LABEL poweroff + MENU LABEL Poweroff + COM32 poweroff.c32 diff --git a/libre-testing/syslinux/syslinux.install b/libre-testing/syslinux/syslinux.install new file mode 100644 index 000000000..9125b6ef7 --- /dev/null +++ b/libre-testing/syslinux/syslinux.install @@ -0,0 +1,32 @@ +show_efi_msg() { + cat << EOF + +==> For setting up Syslinux EFI follow + https://wiki.parabola.nu/index.php/Syslinux#UEFI_Systems + +==> The syslinux-install_update script does not currently support EFI install + +EOF +} + +show_bios_autoupdate_msg() { + cat << EOF + +==> For setting up Syslinux BIOS using the syslinux-install_update script follow + https://wiki.parabola.nu/index.php/Syslinux#Automatic_Install +EOF +} + +post_install() { + [ -f /boot/syslinux/SYSLINUX_AUTOUPDATE ] || show_bios_autoupdate_msg + [ -d /sys/firmware/efi ] && show_efi_msg + + true +} + +post_upgrade() { + ## auto-update syslinux if /boot/syslinux/SYSLINUX_AUTOUPDATE exists + /usr/bin/syslinux-install_update -s + + post_install +} -- cgit v1.2.3