Extend modify_kernel_command_line() feature to grub and syslinux.

For grub and syslinux this feature is a bit inferior to depthcharge
since it requires a full ./build_image, whereas for depthcharge a much
faster bin/cros_make_image_bootable build shortcut is enough.  Initial
attempts to implement at bin/cros_make_image_bootable time proved too
complex and brittle, involving: sed-wrangling, inconsistencies between
grub and syslinux in the installer, etc.

Some more background information in chromium:461595 #c20

BUG=chrome-os-partner:28714
TEST=Two systems are required to test both GRUB and syslinux:
- one with EFI to test GRUB
- one with SeaBIOS and depthcharge to test:
   - syslinux
   - Verified Boot (unaffected)

By choosing two systems compatible enough with each other, a single
${BOARD} can be used and build time saved.

Firstly, make sure this does not introduce any regression: images before
and after this CL both boot with the exact same /proc/cmdline and config
files (assuming they have no build_kernel_image.sh customization)

Next, actually use the feature: before building the image(s), create
one build_kernel_image.sh file per BOARD used. For instance:

cat <<"EOF" >src/overlays/overlay-${BOARD}/scripts/build_kernel_image.sh
modify_kernel_command_line() {
  # Use special characters to try to trigger quoting bugs if any.
 printf '%s\n' 'HELLO_ * " &_TEST_0003" '  >> "$1"
}
EOF

Board overlays can be defined in various places. The second most common
location is: src/private-overlays/overlay-${BOARD}-private/scripts/.
You may need to create the scripts/ directory.

Build and boot the image from USB (or SD). Make sure /proc/cmdline has:
- "cros_legacy" when booting USB with SeaBIOS (Ctrl-L)
- "cros_efi" when booting USB with EFI
- the HELLO_... test content above in both cases.

Inspect the /boot directory and make sure content is as expected.
Mount ESP partition 12 and inspect it too. This command is useful:
  diff -ru /boot/ /tmp/sdb12/

Next test the installer. Do NOT proceed and test the installer if any
previous testing above failed in any way no matter how small.  To
install run either:
  chromeos-install --dst /dev/sdX --target_bios efi
or:
  chromeos-install --dst /dev/sdX --target_bios legacy
depending on the BOARD (/dev/sdX is usually: /dev/sda)

Reboot without the USB stick and run the same inspections above again,
now on the just installed hard drive. On the ${BOARD} with
depthcharge test with and without SeaBIOS.

Change-Id: I207bed7b71f92c39229f218364c1dee63c4dcad2
Reviewed-on: https://chromium-review.googlesource.com/263024
Reviewed-by: James Ausmus <james.ausmus@intel.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Commit-Queue: Marc Herbert <marc.herbert@intel.com>
Tested-by: Marc Herbert <marc.herbert@intel.com>
Tested-by: Thuan T Tran <thuan.t.tran@intel.com>
Trybot-Ready: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
2 files changed