build-gem5 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  2. import glob
  3. import multiprocessing
  4. import os
  5. import pathlib
  6. import shutil
  7. import subprocess
  8. import common
  9. parser = common.get_argparse()
  10. common.add_build_arguments(parser)
  11. parser.add_argument(
  12. 'extra_scons_args',
  13. default=[],
  14. metavar='extra-scons-args',
  15. nargs='*'
  16. )
  17. args = common.setup(parser)
  18. binaries_dir = os.path.join(common.gem5_system_dir, 'binaries')
  19. disks_dir = os.path.join(common.gem5_system_dir, 'disks')
  20. if args.clean:
  21. common.rmrf(common.gem5_build_dir)
  22. else:
  23. os.makedirs(binaries_dir, exist_ok=True)
  24. os.makedirs(disks_dir, exist_ok=True)
  25. if not os.path.exists(os.path.join(common.gem5_src_dir, '.git')):
  26. subprocess.check_call([
  27. 'git',
  28. '-C', common.gem5_default_src_dir,
  29. 'worktree', 'add',
  30. '-b', os.path.join('wt', args.gem5_build_id),
  31. common.gem5_src_dir
  32. ])
  33. if args.arch == 'x86_64':
  34. dummy_img_path = os.path.join(disks_dir, 'linux-bigswap2.img')
  35. with open(dummy_img_path, 'wb') as dummy_img_file:
  36. zeroes = b'\x00' * (2 ** 16)
  37. for i in range(2 ** 10):
  38. dummy_img_file.write(zeroes)
  39. subprocess.check_call(['mkswap', dummy_img_path])
  40. with open(os.path.join(binaries_dir, 'x86_64-vmlinux-2.6.22.9'), 'w'):
  41. # This file must always be present, despite --kernel overriding that default and selecting the kernel.
  42. # I'm not even joking. No one has ever built x86 gem5 without the magic dist dir present.
  43. pass
  44. elif args.arch == 'arm' or args.arch == 'aarch64':
  45. gem5_system_src_dir = os.path.join(common.gem5_src_dir, 'system')
  46. # dtb
  47. dt_src_dir = os.path.join(gem5_system_src_dir, 'arm', 'dt')
  48. dt_build_dir = os.path.join(common.gem5_system_dir, 'arm', 'dt')
  49. subprocess.check_call(['make', '-C', dt_src_dir])
  50. os.makedirs(dt_build_dir, exist_ok=True)
  51. for dt in glob.glob(os.path.join(dt_src_dir, '*.dtb')):
  52. shutil.copy2(dt, dt_build_dir)
  53. # Bootloader 32.
  54. bootloader32_dir = os.path.join(gem5_system_src_dir, 'arm', 'simple_bootloader')
  55. # TODO use the buildroot cross compiler here, and remove the dependencies from configure.
  56. subprocess.check_call(['make', '-C', bootloader32_dir])
  57. # bootloader
  58. shutil.copy2(os.path.join(bootloader32_dir, 'boot_emm.arm'), binaries_dir)
  59. # Bootloader 64.
  60. bootloader64_dir = os.path.join(gem5_system_src_dir, 'arm', 'aarch64_bootloader')
  61. # TODO cross_compile is ignored because the make does not use CC...
  62. subprocess.check_call(['make', '-C', bootloader64_dir])
  63. shutil.copy2(os.path.join(bootloader64_dir, 'boot_emm.arm64'), binaries_dir)
  64. assert common.run_cmd([
  65. 'scons',
  66. # TODO factor with build.
  67. '-j', str(multiprocessing.cpu_count()),
  68. '--ignore-style',
  69. common.gem5_executable
  70. ] +
  71. args.extra_scons_args,
  72. cwd=common.gem5_src_dir,
  73. extra_env={'PATH': '/usr/lib/ccache:' + os.environ['PATH']},
  74. ) == 0
  75. term_src_dir = os.path.join(common.gem5_src_dir, 'util/term')
  76. subprocess.check_call(['make', '-C', term_src_dir])
  77. shutil.copy2(os.path.join(term_src_dir, 'm5term'), common.gem5_m5term)