-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove hardcoded architecture-dependend strings from EFI code #3157
Conversation
Use them for various EFI bootloader suffixes instead of hardcoding strings like BOOTX64.EFI. EFI_ARCH is "x64" and EFI_ARCH_UPPER is "X64" on x86_64 architecture. Should make it easier to port the code to e.g. Arm. See e.g. https://github.com/rhboot/shim/blob/main/Make.defaults for possible values.
Thank you a lot, @pcahyna! This will make the EFI support on |
@pcahyna Could you generalise the rear/usr/share/rear/lib/uefi-functions.sh Lines 39 to 126 in 8564a7b
It hardcodes the edit: typos |
There is still one instance of
|
Use it as the argument of the -O option to grub-mkstandalone/grub-mkimage instead of the hardcoded x86_64-efi. For easier porting to non-x86_64 EFI platforms.
Mostly for completeness and documentation of the possible values.
|
I have not touched the name though |
Change the name of the function to build_boot_efi, not functional change intended.
I changed also the name now |
@@ -28,7 +28,7 @@ if test -f "$SECURE_BOOT_BOOTLOADER" ; then | |||
# (cf. rescue/default/850_save_sysfs_uefi_vars.sh) | |||
# then Shim (usually shim.efi) was copied above as efi_boot_tmp_dir/BOOTX64.efi | |||
# and Shim's second stage bootloader must be also copied where Shim already is. | |||
DebugPrint "Using Shim '$SECURE_BOOT_BOOTLOADER' as first stage UEFI bootloader BOOTX64.efi" | |||
DebugPrint "Using Shim '$SECURE_BOOT_BOOTLOADER' as first stage UEFI bootloader BOOT${EFI_ARCH_UPPER}.efi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ${VAR} is not needed here so
BOOT$EFI_ARCH_UPPER.efi
is sufficient and that is used some lines above in
cp ... $efi_boot_tmp_dir/BOOT$EFI_ARCH_UPPER.efi ...
Reasoning:
I get on command line with openSUSE Leap 15.5
# foo=foo
# bar=bar$foo.baz
# echo "'$bar'"
'barfoo.baz'
This matches "man bash" (for bash version 4.4.23)
DEFINITIONS
...
name A word consisting only of alphanumeric characters
and underscores, and beginning with an alphabetic
character or an underscore. Also referred to as an
identifier.
...
PARAMETERS
...
A variable may be assigned to by a statement of the form
name=[value]
So all non-alphanumeric characters and non-underscores
should be delimiters of variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ${VAR} is not needed here so
BOOT$EFI_ARCH_UPPER.efi
is sufficient
It is certainly not needed for the shell, but I find that variable expansion in the middle of a longer string is hard to read without the curly braces. My judgement of what is hard enough to read and what is not yet is subjective, hence some inconsistency in the usage of the curly braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcahyna
this inconsistency is perfectly fine with me,
see my comment below
#3157 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But shouldn't then for a specific prefix$VARIABLE.suffix
one of the two forms either prefix$VARIABLE.suffix
or prefix${VARIABLE}.suffix
be used consistently everywhere in the code
to have same readability everywhere in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for
- concise
- legible
variable names. So by default short without braces but in places where the eye has a hard time reading better with braces.
@@ -35,7 +35,7 @@ local efi_boot_directory="$RAWDISK_BOOT_EFI_STAGING_ROOT/BOOT" | |||
|
|||
mkdir $v -p "$efi_boot_directory" || Error "Could not create $efi_boot_directory" | |||
|
|||
cp $v "$syslinux_efi" "$efi_boot_directory/BOOTX64.EFI" >&2 | |||
cp $v "$syslinux_efi" "$efi_boot_directory/BOOT${EFI_ARCH_UPPER}.EFI" >&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
https://github.com/rear/rear/pull/3157/files#r1511412487
and >&2
should be usually no longer needed
since stdout and stderr are handled same, cf.
https://github.com/rear/rear/wiki/Coding-Style#what-to-do-with-stdin-stdout-and-stderr
usr/share/rear/output/RAWDISK/Linux-i386/270_create_grub2_efi_bootloader.sh
Show resolved
Hide resolved
usr/share/rear/output/RAWDISK/Linux-i386/270_create_grub2_efi_bootloader.sh
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From plain looking at the code it looks good to me
so I approve it "bona fide".
I only made some nitpicking comments.
It is questionable what code is easier to read
PREFIX${VARIABLE}.suffix
or
PREFIX$VARIABLE.suffix
To me both don't appear really easy to read.
In particular when the prefix is uppercase
and even more when there are uppercase 'S'
like in this artificial example
SCISSORS${SHAPE}.suffix
versus
SCISSORS$SHAPE.suffix
that almost hurts the eyes.
@pcahyna
feel free to keep in particular things like
BOOT${EFI_ARCH_UPPER}.EFI
when you think this is easier to read than
BOOT$EFI_ARCH_UPPER.EFI
cf.
"learn the rules so you know how to break them properly"
https://github.com/rear/rear/wiki/Coding-Style#why
According to
|
I see now that this "hard to read" problem is partly my fault. I am using emacs and and syntax highlighting of strings like PREFIX$FOO.SUFFIX works, so this is readable without curly braces, but "PREFIX$FOO.SUFFIX" does not (the highlighting of the content of "..." overrides the highlighting of @rear/contributors what do you think? What does count as readable and what does count as unreadable for you? |
It is your code so in general you have In particular when an issue is basically |
@jsmeix sure, but I want to make my code readable for others. Therefore, I am genuinely curious what is the aesthetic judgement of other contributors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! There are comments that still use explicit architecture but that is not critical.
yeah I have thought that the comments will be better readable if they contain concrete examples, even if this makes them incorrect for non-x64 architectures |
I also prefer explicit real-world examples in my comments |
@rear/contributors I am still curious how readable longer quoted strings with embedded variable expansions and curly braces vs. no curly braces are for you - most likely it will depend on the syntax highlighting capabilities of your favorite editor. |
@@ -68,7 +68,7 @@ if test "ebiso" = "$( basename $ISO_MKISOFS_BIN )" ; then | |||
fi | |||
|
|||
if [[ -n "$(type -p grub)" ]]; then | |||
cat > $efi_boot_tmp_dir/BOOTX64.conf << EOF | |||
cat > $efi_boot_tmp_dir/BOOT$EFI_ARCH_UPPER.conf << EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this kind of situation I wouldn't mind adding braces, to make it simpler to read. But again, 80% personal preference and I would accept PRs also without
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my subjective choice, but not entirely arbitrary - emacs would highlight variable expansion in BOOT$EFI_ARCH_UPPER.conf
but not in "BOOT$EFI_ARCH_UPPER.conf"
, that's why I am adding curly braces to the latter and not the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'd suggest not being overly strict about quoting style and optimise for short and legible, adding braces where helpful to the reader.
thank you all for the reviews - merging! |
my bad, I forgot to squash all the fixups ... |
Type: Enhancement
Impact: Normal
Reference to related issue (URL):
How was this pull request tested?
Description of the changes in this pull request:
Introduce variables EFI_ARCH{_UPPER} and GRUB2_IMAGE_FORMAT. Use them for various EFI bootloader suffixes, parameters and paths instead of hardcoding strings like BOOTX64.EFI. EFI_ARCH is "x64" and EFI_ARCH_UPPER is "X64" and GRUB2_IMAGE_FORMAT is "x86_64-efi" on x86_64 architecture.
Should make it easier to port the code to e.g. Arm.
See e.g.
https://github.com/rhboot/shim/blob/main/Make.defaults
for possible values.