Skip to content
Snippets Groups Projects
Verified Commit 305ec59e authored by Morten Linderud's avatar Morten Linderud :surfer:
Browse files

Merge remote-tracking branch 'origin/merge-requests/233'

* origin/merge-requests/233:
  Quoting assignments
  Automating mask and align calculation
  Refactoring to SectionAlignment
  Aligning to the next byte
parents 0bf44773 62fd1256
Branches master
No related tags found
No related merge requests found
......@@ -295,7 +295,7 @@ build_image() {
build_uki() {
local out="$1" initramfs="$2" cmdline="$3" osrelease="$4" splash="$5" kernelimg="$6" uefistub="$7" microcode=("${@:8}") errmsg=''
local -i offset=0
local -i offset=0 align=0 mask=0
OBJCOPYARGS=()
# reproducibility, preserve dates of used files
......@@ -317,7 +317,11 @@ build_uki() {
return 1
fi
align="$(objdump -p "${uefistub}" | awk '/SectionAlignment/ {print strtonum("0x"$2)}')"
mask="$((-align))"
offset="$(objdump -h "${uefistub}" | awk 'NF==7 {size=strtonum("0x"$3); offset=strtonum("0x"$4)} END {print size + offset}')"
offset="$(((offset & mask) + align))"
if [[ -z "$osrelease" ]]; then
if [[ -f "/etc/os-release" ]]; then
......@@ -334,6 +338,7 @@ build_uki() {
OBJCOPYARGS+=(--add-section ".osrel=${osrelease}" --change-section-vma ".osrel=$(printf 0x%x "$offset")")
offset="$((offset + $(stat -Lc%s "$osrelease")))"
offset="$(((offset & mask) + align))"
if [[ -z "$cmdline" ]]; then
if [[ -f "/etc/kernel/cmdline" ]]; then
......@@ -359,10 +364,12 @@ build_uki() {
OBJCOPYARGS+=(--add-section ".cmdline=${cmdline_tmp}" --change-section-vma .cmdline="$(printf 0x%x "$offset")")
offset="$((offset + $(stat -Lc%s "$cmdline_tmp")))"
offset="$(((offset & mask) + align))"
if [[ -n "$splash" ]]; then
OBJCOPYARGS+=(--add-section ".splash=${splash}" --change-section-vma ".splash=$(printf 0x%x "$offset")")
offset="$((offset + $(stat -Lc%s "$splash")))"
offset="$(((offset & mask) + align))"
msg2 "Using splash image: '%s'" "$splash"
fi
......@@ -384,6 +391,7 @@ build_uki() {
OBJCOPYARGS+=(--add-section ".linux=${kernelimg}" --change-section-vma ".linux=$(printf 0x%x "$offset")")
offset="$((offset + $(stat -Lc%s "$kernelimg")))"
offset="$(((offset & mask) + align))"
if [[ -z "$initramfs" ]]; then
error "Initramfs '%s' not found" "$initramfs"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment