test_vbe.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright 2022 Google LLC
  3. #
  4. # Test addition of VBE
  5. import pytest
  6. import fit_util
  7. # Define a base ITS which we can adjust using % and a dictionary
  8. base_its = '''
  9. /dts-v1/;
  10. / {
  11. description = "Example kernel";
  12. images {
  13. kernel-1 {
  14. data = /incbin/("%(kernel)s");
  15. type = "kernel";
  16. arch = "sandbox";
  17. os = "linux";
  18. load = <0x40000>;
  19. entry = <0x8>;
  20. compression = "%(compression)s";
  21. random {
  22. compatible = "vbe,random-rand";
  23. vbe,size = <0x40>;
  24. vbe,required;
  25. };
  26. aslr1 {
  27. compatible = "vbe,aslr-move";
  28. vbe,align = <0x100000>;
  29. };
  30. aslr2 {
  31. compatible = "vbe,aslr-rand";
  32. };
  33. efi-runtime {
  34. compatible = "vbe,efi-runtime-rand";
  35. };
  36. wibble {
  37. compatible = "vbe,wibble";
  38. };
  39. };
  40. fdt-1 {
  41. description = "snow";
  42. data = /incbin/("%(fdt)s");
  43. type = "flat_dt";
  44. arch = "sandbox";
  45. load = <%(fdt_addr)#x>;
  46. compression = "%(compression)s";
  47. };
  48. };
  49. configurations {
  50. default = "conf-1";
  51. conf-1 {
  52. kernel = "kernel-1";
  53. fdt = "fdt-1";
  54. };
  55. };
  56. };
  57. '''
  58. # Define a base FDT - currently we don't use anything in this
  59. base_fdt = '''
  60. /dts-v1/;
  61. / {
  62. chosen {
  63. };
  64. };
  65. '''
  66. # This is the U-Boot script that is run for each test. First load the FIT,
  67. # then run the 'bootm' command, then run the unit test which checks that the
  68. # working tree has the required things filled in according to the OS requests
  69. # above (random, aslr2, etc.)
  70. base_script = '''
  71. host load hostfs 0 %(fit_addr)x %(fit)s
  72. fdt addr %(fit_addr)x
  73. bootm start %(fit_addr)x
  74. bootm loados
  75. bootm prep
  76. fdt addr
  77. fdt print
  78. ut bootstd -f vbe_test_fixup_norun
  79. '''
  80. @pytest.mark.boardspec('sandbox_flattree')
  81. @pytest.mark.requiredtool('dtc')
  82. def test_vbe(u_boot_console):
  83. cons = u_boot_console
  84. kernel = fit_util.make_kernel(cons, 'vbe-kernel.bin', 'kernel')
  85. fdt = fit_util.make_dtb(cons, base_fdt, 'vbe-fdt')
  86. fdt_out = fit_util.make_fname(cons, 'fdt-out.dtb')
  87. params = {
  88. 'fit_addr' : 0x1000,
  89. 'kernel' : kernel,
  90. 'fdt' : fdt,
  91. 'fdt_out' : fdt_out,
  92. 'fdt_addr' : 0x80000,
  93. 'fdt_size' : 0x1000,
  94. 'compression' : 'none',
  95. }
  96. mkimage = cons.config.build_dir + '/tools/mkimage'
  97. fit = fit_util.make_fit(cons, mkimage, base_its, params, 'test-vbe.fit',
  98. base_fdt)
  99. params['fit'] = fit
  100. cmd = base_script % params
  101. with cons.log.section('Kernel load'):
  102. output = cons.run_command_list(cmd.splitlines())
  103. assert 'Failures: 0' in output[-1]