605 lines
22 KiB
Bash
605 lines
22 KiB
Bash
diff pkg/mkinitcpio/usr/lib/initcpio/functions /usr/lib/initcpio/functions
|
|
--- pkg/mkinitcpio/usr/lib/initcpio/functions 2024-05-04 13:25:31.000000000 +0300
|
|
+++ /usr/lib/initcpio/functions 2024-03-14 14:58:49.000000000 +0200
|
|
@@ -142,17 +142,10 @@
|
|
kver_x86() {
|
|
local kver
|
|
local -i offset
|
|
- # On x86 (since kernel 1.3.73, 1996), regardless of whether it's
|
|
- # an Image, a zImage, or a bzImage: The file header is the same,
|
|
- # and contains the kernel_version string.
|
|
- #
|
|
# scrape the version out of the kernel image. locate the offset
|
|
# to the version string by reading 2 bytes out of image at at
|
|
# address 0x20E. this leads us to a string of, at most, 128 bytes.
|
|
# read the first word from this string as the kernel version.
|
|
- #
|
|
- # https://www.kernel.org/doc/html/v6.7/arch/x86/boot.html
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/boot/header.S?h=v6.7
|
|
offset="$(od -An -j0x20E -dN2 "$1")" || return
|
|
|
|
read -r kver _ < \
|
|
@@ -162,273 +155,124 @@
|
|
}
|
|
|
|
detect_compression() {
|
|
- # Detect standard compressed files. Not Linux-kernel specific.
|
|
-
|
|
local file="$1" offset="${2:-0}" bytes
|
|
|
|
- # The first 8 bytes are enough to detect most formats.
|
|
- bytes="$(od -An -t x1 -j "$offset" -N 8 "$file" | tr -d ' ')"
|
|
+ bytes="$(od -An -t x1 -N6 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
case "$bytes" in
|
|
- 'fd377a585a00'*)
|
|
- printf 'xz'
|
|
- return
|
|
- ;;
|
|
- '894c5a4f'*)
|
|
- printf 'lzop'
|
|
- return
|
|
- ;;
|
|
- '1f8b'*)
|
|
- printf 'gzip'
|
|
- return
|
|
- ;;
|
|
- '04224d18'*)
|
|
- error 'Newer lz4 stream format detected! This may not boot!'
|
|
- printf 'lz4'
|
|
- return
|
|
- ;;
|
|
- '02214c18'*)
|
|
- printf 'lz4 -l'
|
|
- return
|
|
- ;;
|
|
- '28b52ffd'*)
|
|
- printf 'zstd'
|
|
- return
|
|
- ;;
|
|
- '425a68'*) # 'BZh' in ASCII
|
|
- printf 'bzip2'
|
|
- return
|
|
- ;;
|
|
- '5d0000'*)
|
|
- # lzma detection sucks and there's really no good way to
|
|
- # do it without reading large portions of the stream. this
|
|
- # check is good enough for GNU tar, apparently, so it's good
|
|
- # enough for me.
|
|
- printf 'lzma'
|
|
- return
|
|
- ;;
|
|
- ????????'7a696d67'*) # 4 discarded bytes, then 'zimg' in ASCII
|
|
- # Linux kernel "zboot" self-decompressing EFI images
|
|
- # (since kernel 6.1)
|
|
- # (as of kernel 6.7: only on arm64, loongarch, and riscv)
|
|
-
|
|
- # Read 32 bytes (before 0x38) from address 0x18, which is a
|
|
- # null-terminated string representing the compressed type.
|
|
- #
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/zboot-header.S?h=v6.7
|
|
- read -rd '' bytes < <(od -An -j0x18 -t a -N32 "$1" | sed 's/ nul//g' | tr -dc '[:alnum:]')
|
|
- printf 'zboot %s' "$bytes"
|
|
+ 'fd377a585a00')
|
|
+ echo 'xz'
|
|
return
|
|
;;
|
|
esac
|
|
|
|
- # Try some formats that require us to sniff bytes at other locations.
|
|
-
|
|
- bytes="$(od -An -t x1 -j "$((offset+0x24))" -N4 "$file" | tr -d ' ')"
|
|
- if [[ "$bytes" == '18286f01' || "$bytes" == '016f2818' ]]; then # endian-sensitive
|
|
- # Linux kernel ARM32 self-decompressing "zImage"
|
|
- #
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/compressed/vmlinux.lds.S?h=v6.7#n121
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/compressed/head.S?h=v6.7#n215
|
|
- printf 'ARM zImage'
|
|
+ bytes="$(od -An -t x1 -N4 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
+ if [[ "$bytes" == '894c5a4f' ]]; then
|
|
+ echo 'lzop'
|
|
return
|
|
fi
|
|
|
|
- # out of ideas, assuming uncompressed
|
|
-}
|
|
-
|
|
-decompress_cat() {
|
|
- local file="$1" offset="${2:-0}" size="${3:-}"
|
|
- local comp_type reader
|
|
+ bytes="$(od -An -t x2 -N2 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
+ if [[ "$bytes" == '8b1f' ]]; then
|
|
+ echo 'gzip'
|
|
+ return
|
|
+ fi
|
|
|
|
- comp_type="$(detect_compression "$file" "$offset")"
|
|
- case "$comp_type" in
|
|
- '') reader='cat' ;;
|
|
- 'xz') reader='xzcat' ;;
|
|
- 'lzop') reader='lzop -d' ;;
|
|
- 'gzip') reader='zcat' ;;
|
|
- 'lz4') reader='lz4cat' ;;
|
|
- 'lz4 -l') reader='lz4cat -l' ;;
|
|
- 'zstd') reader='zstdcat' ;;
|
|
- 'bzip2') reader='bzcat' ;;
|
|
- 'lzma') reader='xzcat' ;;
|
|
- 'zboot '*)
|
|
- _zboot_cat "${comp_type#'zboot '}" "$file" "$offset"
|
|
+ bytes="$(od -An -t x4 -N4 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
+ case "$bytes" in
|
|
+ '184d2204')
|
|
+ error 'Newer lz4 stream format detected! This may not boot!'
|
|
+ echo 'lz4'
|
|
return
|
|
;;
|
|
- 'ARM zImage')
|
|
- _arm_zimage_cat "$file" "$offset"
|
|
+ '184c2102')
|
|
+ echo 'lz4 -l'
|
|
return
|
|
;;
|
|
- *)
|
|
- error 'Unknown compression type: %s' "$comp_type"
|
|
- return 1
|
|
+ 'fd2fb528')
|
|
+ echo 'zstd'
|
|
+ return
|
|
;;
|
|
esac
|
|
- if (( offset == 0 )) && [[ -z "$size" ]]; then
|
|
- $reader - <"$file"
|
|
- elif [[ -z "$size" ]]; then
|
|
- tail --bytes=+"$((offset+1))" "$file" | $reader -
|
|
- else
|
|
- tail --bytes=+"$((offset+1))" "$file" | head --bytes="$size" | $reader -
|
|
+
|
|
+ bytes="$(od -An -c -N3 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
+ if [[ "$bytes" == 'BZh' ]]; then
|
|
+ echo 'bzip2'
|
|
+ return
|
|
fi
|
|
-}
|
|
|
|
-_zboot_cat() {
|
|
- # Linux kernel "zboot" self-decompressing EFI images
|
|
- # (since kernel 6.1)
|
|
- # (as of kernel 6.7: only on arm64, loongarch, and riscv)
|
|
+ # lzma detection sucks and there's really no good way to
|
|
+ # do it without reading large portions of the stream. this
|
|
+ # check is good enough for GNU tar, apparently, so it's good
|
|
+ # enough for me.
|
|
+ bytes="$(od -An -t x1 -N3 -j "$offset" "$file" | tr -dc '[:alnum:]')"
|
|
+ if [[ "$bytes" == '5d0000' ]]; then
|
|
+ echo 'lzma'
|
|
+ return
|
|
+ fi
|
|
|
|
- # See zboot-header.S for offsets. See Makefile.zboot for
|
|
- # compression types and size adjustments.
|
|
- #
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/Makefile.zboot?h=v6.7
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/zboot-header.S?h=v6.7
|
|
+ read -rd '' bytes < <(od -An -j $((offset + 0x04)) -t c -N4 "$file" | tr -dc '[:alnum:]')
|
|
+ if [[ "$bytes" == 'zimg' ]]; then
|
|
+ echo 'zimg'
|
|
+ return
|
|
+ fi
|
|
|
|
- local comp_type="$1" file="$2" offset="${3:-0}"
|
|
- local reader start size size_len
|
|
+ # out of ideas, assuming uncompressed
|
|
+}
|
|
|
|
- # Read a pair of u32s from 0x08 (right after the "zimg" magic
|
|
- # identifier) for the starting-offset and size of the compressed
|
|
- # data.
|
|
- start="$(od -An -j "$((offset+0x08))" -t u4 -N4 "$file" | tr -dc '[:alnum:]')"
|
|
- size="$(od -An -j "$((offset+0x0c))" -t u4 -N4 "$file" | tr -dc '[:alnum:]')"
|
|
+kver_zimage() {
|
|
+ # Generic EFI zboot added since kernel 6.1
|
|
+ # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/Makefile.zboot?h=v6.1
|
|
+ # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/zboot-header.S?h=v6.1
|
|
+
|
|
+ local kver='' reader start size comp_type
|
|
+
|
|
+ # Reading 4 bytes from address 0x08 is the starting offset of compressed data
|
|
+ start="$(od -An -j0x08 -t u4 -N4 "$1" | tr -dc '[:alnum:]')"
|
|
+
|
|
+ # Reading 4 bytes from address 0x0c is the size of compressed data,
|
|
+ # but it needs to be corrected according to the compressed type.
|
|
+ size="$(od -An -j0x0c -t u4 -N4 "$1" | tr -dc '[:alnum:]')"
|
|
+
|
|
+ # Read 36 bytes (before 0x3c) from address 0x18,
|
|
+ # which is a nul-terminated string representing the compressed type.
|
|
+ read -rd '' comp_type < <(od -An -j0x18 -t a -N32 "$1" | sed 's/ nul//g' | tr -dc '[:alnum:]')
|
|
|
|
[[ "$start" =~ ^[0-9]+$ ]] || return 1
|
|
[[ "$size" =~ ^[0-9]+$ ]] || return 1
|
|
|
|
- size_len=4 # corresponds to Makefile.zboot:zboot-size-len-y or zboot-header.S:ZBOOT_SIZE_LEN
|
|
case "$comp_type" in
|
|
- 'gzip') reader='zcat'
|
|
- size_len=0
|
|
- ;;
|
|
- 'lz4') reader='lz4cat' ;;
|
|
- 'lzma') reader='xzcat' ;;
|
|
- 'lzo') reader='lzop -d' ;;
|
|
- 'xzkern') reader='xzcat' ;;
|
|
- 'zstd22') reader='zstdcat' ;;
|
|
- *)
|
|
- error 'Unknown zboot compression type: %s' "${comp_type#'zboot '}"
|
|
- return 1
|
|
+ 'gzip')
|
|
+ reader='zcat'
|
|
+ ;;
|
|
+ 'lz4')
|
|
+ reader='lz4cat'
|
|
+ size="$((size + 4))"
|
|
+ ;;
|
|
+ 'lzma')
|
|
+ reader='xzcat'
|
|
+ size="$((size + 4))"
|
|
+ ;;
|
|
+ 'lzo')
|
|
+ reader="lzop -d"
|
|
+ size="$((size + 4))"
|
|
+ ;;
|
|
+ 'xzkern')
|
|
+ reader='xzcat'
|
|
+ size="$((size + 4))"
|
|
+ ;;
|
|
+ 'zstd22')
|
|
+ reader='zstdcat'
|
|
+ size="$((size + 4))"
|
|
;;
|
|
- esac
|
|
-
|
|
- tail --bytes=+"$((offset+start+1))" <"$file" | head --bytes="$((size+size_len))" | $reader -
|
|
-}
|
|
-
|
|
-_arm_zimage_cat() {
|
|
- # Linux kernel ARM32 self-decompressing "zImage"
|
|
-
|
|
- # The end of the file looks like:
|
|
- #
|
|
- # input_data: char []<compressed data>
|
|
- # piggy_size: u32 len(<uncompressed_data>)
|
|
- # padding: char []<zeros> ; <=4096 bytes
|
|
- # got: u32 []<global_offsets>
|
|
- # trailer: char []<whatever> ; <512 bytes
|
|
- #
|
|
- # We can find the location of "piggy_size" from the file header,
|
|
- # and then we can ignore some zeros to find the GOT. It is
|
|
- # reasonable to assume (but still a heuristic) that the largest
|
|
- # value in the GOT that is <0x20000 (128KiB) is the location of
|
|
- # input_data.
|
|
- #
|
|
- # Note that piggy_size is *not* at a 4-byte-aligned location.
|
|
- #
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/compressed/vmlinux.lds.S?h=v6.7
|
|
- #
|
|
- # About that 0x20000 heuristic: input_data is put after the
|
|
- # extraction code, and so its location is basically determined by
|
|
- # the size of the extraction code, which will vary based on a
|
|
- # number of factors. So, this heuristic relies on a few things:
|
|
- #
|
|
- # 1. That ${max_extraction_code_size} is less than ~128KiB
|
|
- # 2. That ${min_compressed_kernel_size}+${min_extraction_code_size}
|
|
- # is more than ~128KiB.
|
|
- #
|
|
- # How safe are those assumptions?
|
|
- #
|
|
- # 1. Using GCC 12.2.0 with kernels 4.15 - 6.8 in a variety of
|
|
- # configurations, I've observed input_data being placed at
|
|
- # addresses in the range 0x152e - 0x10f63 (~5.3KiB - ~68KiB).
|
|
- # This is well within our 128KiB threshold.
|
|
- # 2. Let's just say that at the limit min_extraction_code_size =~
|
|
- # 0; I think it is safe to assume that even compressed,
|
|
- # kernels are measured in MiB, not KiB. (Though, when writing
|
|
- # tests for this code, it means we must be careful to use
|
|
- # files that are large enough!)
|
|
-
|
|
- local file="$1" offset="${2:-0}"
|
|
-
|
|
- # Read magic numbers.
|
|
- local hdr_endian_indicator cpu_endian_indicator have_table_indicator hdr_endian cpu_endian
|
|
- hdr_endian_indicator="$(od -An -t x1 -j "$((offset+0x24))" -N4 "$file" | tr -d ' ')"
|
|
- cpu_endian_indicator="$(od -An -t x1 -j "$((offset+0x30))" -N4 "$file" | tr -d ' ')"
|
|
- have_table_indicator="$(od -An -t x1 -j "$((offset+0x34))" -N4 "$file" | tr -d ' ')"
|
|
- case "$hdr_endian_indicator" in #
|
|
- '18286f01') hdr_endian='little' ;;
|
|
- '016f2818') hdr_endian='big' ;;
|
|
*)
|
|
- error '_arm_zimage_cat called, but file does not look like an ARM zImage'
|
|
- return 1
|
|
+ reader="$comp_type"
|
|
+ size="$((size + 4))"
|
|
;;
|
|
esac
|
|
- case "$cpu_endian_indicator" in
|
|
- # Prior to v3.17, hdr_endian and cpu_endian were the same, and
|
|
- # there was no cpu_endian_indicator.
|
|
- '01020304') cpu_endian='little' ;;
|
|
- '04030201') cpu_endian='big' ;;
|
|
- *) cpu_endian="$hdr_endian" ;;
|
|
- esac
|
|
- if [[ "$have_table_indicator" != '45454545' ]]; then
|
|
- error 'ARM zImage is too old (before v4.15, 2017)'
|
|
- return 1
|
|
- fi
|
|
|
|
- # Read offsets.
|
|
- local zboot_rom_text magic_table_addr piggy_size_addr aligned_after_piggy
|
|
- zboot_rom_text="$(od --endian="$hdr_endian" -An -t u4 -j "$((offset+0x28))" -N4 "$file" | tr -d ' ')"
|
|
- magic_table_addr="$(od --endian="$hdr_endian" -An -t u4 -j "$((offset+0x38))" -N4 "$file" | tr -d ' ')"
|
|
- piggy_size_addr="$(od --endian="$hdr_endian" -An -t u4 -j $((offset+magic_table_addr+8)) -N4 "$file" | tr -d ' ')"
|
|
- aligned_after_piggy=$((((piggy_size_addr+4+3)/4)*4))
|
|
-
|
|
- # Read the padding and GOT.
|
|
- # These values have zboot_rom_text added to them.
|
|
- local -i input_data_addr=0 in_got=0 val size
|
|
- while read -r val; do
|
|
- if (( val == 0 )); then
|
|
- if (( in_got )); then
|
|
- break
|
|
- else
|
|
- continue
|
|
- fi
|
|
- fi
|
|
- in_got=1
|
|
- val="$((val - zboot_rom_text))"
|
|
- if (( val > input_data_addr && val < 0x20000 )); then
|
|
- input_data_addr=$val
|
|
- fi
|
|
- done < <(od --endian="$cpu_endian" -An -v -t u4 -j "$((offset+aligned_after_piggy))" "$file" | xargs printf '%s\n')
|
|
- if (( input_data_addr == 0 )); then
|
|
- error 'Could not find input_data_addr in ARM zImage'
|
|
- return 1
|
|
- fi
|
|
- size="$((piggy_size_addr-input_data_addr))"
|
|
+ read -r _ _ kver _ < <(dd if="$1" bs=1 count="$size" skip="$start" 2>/dev/null | $reader - | grep -m1 -aoE 'Linux version .(\.[-[:alnum:]+]+)+')
|
|
|
|
- # gzip contains a 4-byte uncompressed-size suffix, so for
|
|
- # CONFIG_KERNEL_GZIP it saves 4 bytes by having the input_data
|
|
- # extend into the piggy_size.
|
|
- #
|
|
- # That is: the Makefile says
|
|
- # compress-$(CONFIG_KERNEL_GZIP) = gzip
|
|
- # instead of
|
|
- # compress-$(CONFIG_KERNEL_GZIP) = gzip_with_size
|
|
- #
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/compressed/Makefile?h=v6.7#n79
|
|
- if [[ "$(detect_compression "$file" "$((offset+input_data_addr))")" == 'gzip' ]]; then
|
|
- size=$((size+4))
|
|
- fi
|
|
-
|
|
- decompress_cat "$file" "$((offset+input_data_addr))" "$size"
|
|
+ printf '%s' "$kver"
|
|
}
|
|
|
|
kver_generic() {
|
|
@@ -438,11 +282,24 @@
|
|
# gzipped /boot/vmlinuz-linuz. On other architectures it may be worth trying
|
|
# rather than bailing, and inform the user if none was found.
|
|
|
|
- local kver=''
|
|
-
|
|
# Loosely grep for `linux_banner`:
|
|
- # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/version-timestamp.c?h=v6.7#n28
|
|
- read -r _ _ kver _ < <(decompress_cat "$1" | grep -m1 -aoE 'Linux version .(\.[-[:alnum:]+]+)+')
|
|
+ # https://elixir.bootlin.com/linux/v5.7.2/source/init/version.c#L46
|
|
+ local kver='' reader='cat'
|
|
+ local comp_type=''
|
|
+
|
|
+ comp_type="$(detect_compression "$1")"
|
|
+
|
|
+ if [[ "$comp_type" == 'zimg' ]]; then
|
|
+ # Generic EFI zboot image
|
|
+ kver_zimage "$1"
|
|
+ return 0
|
|
+ elif [[ "$comp_type" == 'gzip' ]]; then
|
|
+ reader='zcat'
|
|
+ fi
|
|
+
|
|
+ [[ "$(detect_compression "$1")" == 'gzip' ]] && reader='zcat'
|
|
+
|
|
+ read -r _ _ kver _ < <($reader "$1" | grep -m1 -aoE 'Linux version .(\.[-[:alnum:]+]+)+')
|
|
|
|
printf '%s' "$kver"
|
|
}
|
|
@@ -820,16 +677,6 @@
|
|
command install -dm"${mode}" "${BUILDROOT}${path}"
|
|
}
|
|
|
|
-add_dir_early() {
|
|
- # add a directory (with parents) to $EARLYROOT
|
|
- # $1: pathname on initcpio
|
|
- # $2: mode (optional)
|
|
-
|
|
- # $EARLYROOT is assigned by mkinitcpio
|
|
- # shellcheck disable=SC2153
|
|
- BUILDROOT="$EARLYROOT" add_dir "$@" || return
|
|
-}
|
|
-
|
|
add_symlink() {
|
|
# Add a symlink to the initcpio image. There is no checking done
|
|
# to ensure that the target of the symlink exists.
|
|
@@ -878,21 +725,7 @@
|
|
# determine source and destination
|
|
local src="$1" dest="${2:-$1}" mode="$3" srcrealpath destrealpath
|
|
|
|
- # Treat '-' as /dev/stdin
|
|
- if [[ "$src" == '-' ]]; then
|
|
- src='/dev/stdin'
|
|
- fi
|
|
-
|
|
- if [[ -c "$src" || -p "$src" ]]; then
|
|
- if [[ "$src" == "$dest" || "$dest" == *'/' ]]; then
|
|
- error "no destination file specified for: '%s'" "$src"
|
|
- return 1
|
|
- fi
|
|
- if [[ -z "$mode" ]]; then
|
|
- error "no file mode specified for: '%s'" "$dest"
|
|
- return 1
|
|
- fi
|
|
- elif [[ ! -f "$src" ]]; then
|
|
+ if [[ ! -f "$src" ]]; then
|
|
error "file not found: '%s'" "$src"
|
|
return 1
|
|
fi
|
|
@@ -912,7 +745,7 @@
|
|
fi
|
|
|
|
# check if $src is a symlink
|
|
- if [[ -L "$src" && ! -c "$src" && ! -p "$src" ]]; then
|
|
+ if [[ -L "$src" ]]; then
|
|
srcrealpath="$(realpath -- "$src")"
|
|
if [[ "$srcrealpath" != "$dest" ]]; then
|
|
# add the target file
|
|
@@ -923,15 +756,13 @@
|
|
fi
|
|
fi
|
|
|
|
- # cp does not create directories leading to the destination and install
|
|
- # does not create the last directory if the destination is a directory.
|
|
- [[ ! -e "${BUILDROOT}${dest%/*}" && ( -z "$mode" || "$dest" == *'/' ) ]] && add_dir "${dest%/*}"
|
|
-
|
|
- # if destination ends with a slash, then use the source file name
|
|
- if [[ -e "${BUILDROOT}${dest/%\//\/${src##*/}}" ]]; then
|
|
- quiet 'overwriting file: %s' "${dest/%\//\/${src##*/}}"
|
|
+ # unlike install, cp does not create directories leading to the destination
|
|
+ [[ -z "$mode" && ! -e "${BUILDROOT}${dest%/*}" ]] && add_dir "${dest%/*}"
|
|
+
|
|
+ if [[ -e "${BUILDROOT}${dest}" ]]; then
|
|
+ quiet 'overwriting file: %s' "$dest"
|
|
else
|
|
- quiet 'adding file: %s' "${dest/%\//\/${src##*/}}"
|
|
+ quiet 'adding file: %s' "$dest"
|
|
fi
|
|
if [[ -z "$mode" ]]; then
|
|
command cp --remove-destination --preserve=mode,ownership "$src" "${BUILDROOT}${dest}"
|
|
@@ -940,18 +771,6 @@
|
|
fi
|
|
}
|
|
|
|
-add_file_early() {
|
|
- # Add a plain file to $EARLYROOT. No parsing is performed and only
|
|
- # the singular file is added.
|
|
- # $1: path to file
|
|
- # $2: destination on initcpio (optional, defaults to same as source)
|
|
- # $3: mode
|
|
-
|
|
- # $EARLYROOT is assigned by mkinitcpio
|
|
- # shellcheck disable=SC2153
|
|
- BUILDROOT="$EARLYROOT" add_file "$@" || return
|
|
-}
|
|
-
|
|
add_runscript() {
|
|
# Adds a runtime script to the initcpio image. The name is derived from the
|
|
# script which calls it as the basename of the caller.
|
|
@@ -1139,7 +958,7 @@
|
|
# creates a temporary directory for the buildroot and initialize it with a
|
|
# basic set of necessary directories and symlinks
|
|
|
|
- local kernver="$1" generatedir="$2" workdir arch buildroot osreleasefile root
|
|
+ local kernver="$1" generatedir="$2" workdir arch buildroot osreleasefile
|
|
arch="$(uname -m)"
|
|
|
|
if ! workdir="$(mktemp -d --tmpdir mkinitcpio.XXXXXX 2>/dev/null)"; then
|
|
@@ -1160,21 +979,19 @@
|
|
echo 1 > "${earlyroot}/early_cpio"
|
|
|
|
# base directory structure
|
|
- for root in "$buildroot" "$earlyroot"; do
|
|
- install -dm755 "$root"/{new_root,proc,sys,dev,run,tmp,var,etc,usr/{local{,/bin,/sbin,/lib},lib,bin}}
|
|
- ln -s "usr/lib" "$root/lib"
|
|
- ln -s "bin" "$root/usr/sbin"
|
|
- ln -s "usr/bin" "$root/bin"
|
|
- ln -s "usr/bin" "$root/sbin"
|
|
- ln -s "../run" "$root/var/run"
|
|
-
|
|
- case "$arch" in
|
|
- x86_64)
|
|
- ln -s "lib" "$root/usr/lib64"
|
|
- ln -s "usr/lib" "$root/lib64"
|
|
- ;;
|
|
- esac
|
|
- done
|
|
+ install -dm755 "$buildroot"/{new_root,proc,sys,dev,run,tmp,var,etc,usr/{local{,/bin,/sbin,/lib},lib,bin}}
|
|
+ ln -s "usr/lib" "$buildroot/lib"
|
|
+ ln -s "bin" "$buildroot/usr/sbin"
|
|
+ ln -s "usr/bin" "$buildroot/bin"
|
|
+ ln -s "usr/bin" "$buildroot/sbin"
|
|
+ ln -s "/run" "$buildroot/var/run"
|
|
+
|
|
+ case "$arch" in
|
|
+ x86_64)
|
|
+ ln -s "lib" "$buildroot/usr/lib64"
|
|
+ ln -s "usr/lib" "$buildroot/lib64"
|
|
+ ;;
|
|
+ esac
|
|
|
|
# mkinitcpio version stamp
|
|
# shellcheck disable=SC2154
|
|
@@ -1354,43 +1171,30 @@
|
|
}
|
|
|
|
add_all_modules_from_symbol() {
|
|
- local symbol="$1"
|
|
- local -a mods paths=("${@:2}")
|
|
-
|
|
- mapfile -t mods < <(find_module_from_symbol "$symbol" "${paths[@]}")
|
|
- if (( ! ${#mods[@]} )); then
|
|
- paths=("${paths[@]#=}") paths=("${paths[@]/#/\'}") paths=("${paths[@]/%/\',}")
|
|
- local path_string="${paths[*]}"
|
|
- warning "No module containing the symbol '%s' found in: %s" "$symbol" "${path_string%,}"
|
|
- return 1
|
|
- fi
|
|
-
|
|
- # add_checked_modules_from_symbol
|
|
- if [[ "${FUNCNAME[1]}" == 'add_checked_modules_from_symbol' ]]; then
|
|
- # _autodetect_cache is declared in mkinitcpio and assigned in install/autodetect
|
|
- # shellcheck disable=SC2154
|
|
- if (( ${#_autodetect_cache[@]} )); then
|
|
- mapfile -t mods < <(printf '%s\n' "${mods[@]}" | grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}"))
|
|
- # Do not fail if no autodetected module has the symbol
|
|
- if (( ! ${#mods[@]} )); then
|
|
- return 0
|
|
- fi
|
|
- fi
|
|
- fi
|
|
+ local -a mods
|
|
|
|
+ mapfile -t mods < <(find_module_from_symbol "$@")
|
|
+ (( ${#mods[@]} )) || return 1
|
|
map add_module "${mods[@]}"
|
|
}
|
|
|
|
-
|
|
add_checked_modules_from_symbol() {
|
|
- if ! add_all_modules_from_symbol "$@"; then
|
|
- return 1
|
|
+ local -a mods
|
|
+
|
|
+ mapfile -t mods < <(find_module_from_symbol "$@")
|
|
+ (( ${#mods[@]} )) || return 1
|
|
+
|
|
+ # _autodetect_cache is declared in mkinitcpio and assigned in install/autodetect
|
|
+ # shellcheck disable=SC2154
|
|
+ if (( ${#_autodetect_cache[@]} )); then
|
|
+ mapfile -t mods < <(grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}") <<<"${mods[@]}")
|
|
+ # Do not fail if no autodetected module has the symbol
|
|
+ if (( ${#mods[@]} )); then
|
|
+ return 0
|
|
+ fi
|
|
fi
|
|
-}
|
|
|
|
-if [[ "$0" == *'/functions' && "$1" == 'run_mkinitcpio_func' ]]; then
|
|
- shift
|
|
- "$@"
|
|
-fi
|
|
+ map add_module "${mods[@]}"
|
|
+}
|
|
|
|
# vim: set ft=sh ts=4 sw=4 et:
|