Skip to contentSkip to conversation

board/pc/post-build.sh: allow to use grub config file

PATCH In review AndreiCherniaev 2 participants 2 messages Jan 9, 2023 – Oct 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 board/pc/post-build.sh: allow to use grub config file

Allow to use grub config file with set timeout not default. Before this set timeout always was 5s and can't be changed, any set timeout from BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC was ignored

---
 board/pc/post-build.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
board/pc/post-build.sh +16 -1
index c76dee2676..8538faa7eb 100755
@@ -9,7 +9,22 @@ if [ -d "$BINARIES_DIR/efi-part/" ]; then
     cp -f "$BOARD_DIR/grub-efi.cfg" "$BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg"
 else
     cp -f "$BOARD_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg"
-
     # Copy grub 1st stage to binaries, required for genimage
     cp -f "$TARGET_DIR/lib/grub/i386-pc/boot.img" "$BINARIES_DIR"
 fi
+
+# When post-build script is runing $BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC is unset, so parce Buildroot .config file again
+GRUB2_BUILTIN_CONFIG_PC="`grep --only-matching --perl-regex "(?<=BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC\=).*" $BR2_CONFIG`"
+# Using the native shell prefix/suffix removal feature (see also qstrip)
+GRUB2_BUILTIN_CONFIG_PC="${GRUB2_BUILTIN_CONFIG_PC%\"}"
+GRUB2_BUILTIN_CONFIG_PC="${GRUB2_BUILTIN_CONFIG_PC#\"}"
+if [ -z "$GRUB2_BUILTIN_CONFIG_PC" ]; then #if user doesn't use his .config for grub
+    # Set time to wait 5 s for keyboard input before booting by default
+    sed -i -e '1 s/^/set default="0"\nset timeout="5"\n\n/;' "$TARGET_DIR/boot/grub/grub.cfg"
+#else if user use his .config for grub
+# to configure bootloader put something like
+#  set default="0"
+#  set timeout="5"
+# to your file located $BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC 
+# More info https://www.gnu.org/software/grub/manual/grub
+fi
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Andrei, All,

Sorry to come back so alte on that patch...

On 2023-01-09 16:42 +0900, AndreiCherniaev spake thusly:

Quoted 1 line

Allow to use grub config file with set timeout not default. Before this set timeout always was 5s and can't be changed, any set timeout from BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC was ignored

Please properly format your commit log, wrapped at ~72 chars wide lines.

The files in board/ are meant to be used with the defconfigs in Buildroot, and together are meant as examples and startkng point for frther custmisations.

We can't add support for everything up to the kitchen sink in those scripts; we want to keep them simple so that it is easy to see what they are doing on how they can be extended.

It is your responsibility to adapt those files to match your use-case, potentially duplicating them on hyour side to create a new board definition.

As such, I've maked this patch as rejected.

Regards,
Yann E. MORIN.

Quoted 40 lines
---
 board/pc/post-build.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
board/pc/post-build.sh +16 -1
index c76dee2676..8538faa7eb 100755
@@ -9,7 +9,22 @@ if [ -d "$BINARIES_DIR/efi-part/" ]; then
     cp -f "$BOARD_DIR/grub-efi.cfg" "$BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg"
 else
     cp -f "$BOARD_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg"
-
     # Copy grub 1st stage to binaries, required for genimage
     cp -f "$TARGET_DIR/lib/grub/i386-pc/boot.img" "$BINARIES_DIR"
 fi
+
+# When post-build script is runing $BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC is unset, so parce Buildroot .config file again
+GRUB2_BUILTIN_CONFIG_PC="`grep --only-matching --perl-regex "(?<=BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC\=).*" $BR2_CONFIG`"
+# Using the native shell prefix/suffix removal feature (see also qstrip)
+GRUB2_BUILTIN_CONFIG_PC="${GRUB2_BUILTIN_CONFIG_PC%\"}"
+GRUB2_BUILTIN_CONFIG_PC="${GRUB2_BUILTIN_CONFIG_PC#\"}"
+if [ -z "$GRUB2_BUILTIN_CONFIG_PC" ]; then #if user doesn't use his .config for grub
+    # Set time to wait 5 s for keyboard input before booting by default
+    sed -i -e '1 s/^/set default="0"\nset timeout="5"\n\n/;' "$TARGET_DIR/boot/grub/grub.cfg"
+#else if user use his .config for grub
+# to configure bootloader put something like
+#  set default="0"
+#  set timeout="5"
+# to your file located $BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC 
+# More info https://www.gnu.org/software/grub/manual/grub
+fi
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot