load_kernel_tests.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. #
  6. # End-to-end test for vboot2 kernel verification
  7. # Load common constants and variables.
  8. . "$(dirname "$0")/common.sh"
  9. set -e
  10. CGPT=${BIN_DIR}/cgpt
  11. echo 'Creating test kernel'
  12. # Run tests in a dedicated directory for easy cleanup or debugging.
  13. DIR="${TEST_DIR}/load_kernel_test_dir"
  14. [ -d "$DIR" ] || mkdir -p "$DIR"
  15. echo "Testing kernel verification in $DIR"
  16. cd "$DIR"
  17. # Dummy kernel data
  18. echo "hi there" > "dummy_config.txt"
  19. dd if=/dev/urandom bs=16384 count=1 of="dummy_bootloader.bin"
  20. dd if=/dev/urandom bs=32768 count=1 of="dummy_kernel.bin"
  21. # Pack kernel data key using original vboot utilities.
  22. ${FUTILITY} vbutil_key --pack datakey.test \
  23. --key ${TESTKEY_DIR}/key_rsa2048.keyb --algorithm 4
  24. # Keyblock with kernel data key is signed by kernel subkey
  25. # Flags=5 means dev=0 rec=0
  26. ${FUTILITY} vbutil_keyblock --pack keyblock.test \
  27. --datapubkey datakey.test \
  28. --flags 5 \
  29. --signprivate ${SCRIPT_DIR}/devkeys/kernel_subkey.vbprivk
  30. # Kernel preamble is signed with the kernel data key
  31. ${FUTILITY} vbutil_kernel \
  32. --pack "kernel.test" \
  33. --keyblock "keyblock.test" \
  34. --signprivate ${TESTKEY_DIR}/key_rsa2048.sha256.vbprivk \
  35. --version 1 \
  36. --arch arm \
  37. --vmlinuz "dummy_kernel.bin" \
  38. --bootloader "dummy_bootloader.bin" \
  39. --config "dummy_config.txt"
  40. echo 'Verifying test kernel'
  41. # Verify the kernel
  42. ${FUTILITY} vbutil_kernel \
  43. --verify "kernel.test" \
  44. --signpubkey ${SCRIPT_DIR}/devkeys/kernel_subkey.vbpubk
  45. happy 'Kernel verification succeeded'
  46. # Now create a dummy disk image
  47. echo 'Creating test disk image'
  48. dd if=/dev/zero of=disk.test bs=1024 count=1024
  49. ${CGPT} create disk.test
  50. ${CGPT} add -i 1 -S 1 -P 1 -b 64 -s 960 -t kernel -l kernelA disk.test
  51. ${CGPT} show disk.test
  52. # And insert the kernel into it
  53. dd if=kernel.test of=disk.test bs=512 seek=64 conv=notrunc
  54. # And verify it using futility
  55. echo 'Verifying test disk image'
  56. ${BUILD_RUN}/tests/verify_kernel disk.test \
  57. ${SCRIPT_DIR}/devkeys/kernel_subkey.vbpubk
  58. happy 'Image verification succeeded'