genrandconfig 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2014 by Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. # This script generates a random configuration for testing Buildroot.
  18. from binascii import hexlify
  19. import contextlib
  20. import csv
  21. import os
  22. from random import randint
  23. import subprocess
  24. import sys
  25. import traceback
  26. from distutils.version import StrictVersion
  27. import platform
  28. if sys.hexversion >= 0x3000000:
  29. import urllib.request as _urllib
  30. else:
  31. import urllib2 as _urllib
  32. def urlopen_closing(uri):
  33. return contextlib.closing(_urllib.urlopen(uri))
  34. class SystemInfo:
  35. DEFAULT_NEEDED_PROGS = ["make", "git", "gcc", "timeout"]
  36. DEFAULT_OPTIONAL_PROGS = ["bzr", "java", "javac", "jar", "diffoscope"]
  37. def __init__(self):
  38. self.needed_progs = list(self.__class__.DEFAULT_NEEDED_PROGS)
  39. self.optional_progs = list(self.__class__.DEFAULT_OPTIONAL_PROGS)
  40. self.progs = {}
  41. def find_prog(self, name, flags=os.X_OK, env=os.environ):
  42. if not name or name[0] == os.sep:
  43. raise ValueError(name)
  44. prog_path = env.get("PATH", None)
  45. # for windows compatibility, we'd need to take PATHEXT into account
  46. if prog_path:
  47. for prog_dir in filter(None, prog_path.split(os.pathsep)):
  48. # os.join() not necessary: non-empty prog_dir
  49. # and name[0] != os.sep
  50. prog = prog_dir + os.sep + name
  51. if os.access(prog, flags):
  52. return prog
  53. # --
  54. return None
  55. def has(self, prog):
  56. """Checks whether a program is available.
  57. Lazily evaluates missing entries.
  58. Returns: None if prog not found, else path to the program [evaluates
  59. to True]
  60. """
  61. try:
  62. return self.progs[prog]
  63. except KeyError:
  64. pass
  65. have_it = self.find_prog(prog)
  66. # java[c] needs special care
  67. if have_it and prog in ('java', 'javac'):
  68. with open(os.devnull, "w") as devnull:
  69. if subprocess.call("%s -version | grep gcj" % prog,
  70. shell=True,
  71. stdout=devnull, stderr=devnull) != 1:
  72. have_it = False
  73. # --
  74. self.progs[prog] = have_it
  75. return have_it
  76. def check_requirements(self):
  77. """Checks program dependencies.
  78. Returns: True if all mandatory programs are present, else False.
  79. """
  80. do_check_has_prog = self.has
  81. missing_requirements = False
  82. for prog in self.needed_progs:
  83. if not do_check_has_prog(prog):
  84. print("ERROR: your system lacks the '%s' program" % prog)
  85. missing_requirements = True
  86. # check optional programs here,
  87. # else they'd get checked by each worker instance
  88. for prog in self.optional_progs:
  89. do_check_has_prog(prog)
  90. return not missing_requirements
  91. def get_toolchain_configs(toolchains_csv, buildrootdir):
  92. """Fetch and return the possible toolchain configurations
  93. This function returns an array of toolchain configurations. Each
  94. toolchain configuration is itself an array of lines of the defconfig.
  95. """
  96. with open(toolchains_csv) as r:
  97. # filter empty lines and comments
  98. lines = [t for t in r.readlines() if len(t.strip()) > 0 and t[0] != '#']
  99. toolchains = lines
  100. configs = []
  101. (_, _, _, _, hostarch) = os.uname()
  102. # ~2015 distros report x86 when on a 32bit install
  103. if hostarch == 'i686' or hostarch == 'i386' or hostarch == 'x86':
  104. hostarch = 'x86'
  105. for row in csv.reader(toolchains):
  106. config = {}
  107. configfile = row[0]
  108. config_hostarch = row[1]
  109. keep = False
  110. # Keep all toolchain configs that work regardless of the host
  111. # architecture
  112. if config_hostarch == "any":
  113. keep = True
  114. # Keep all toolchain configs that can work on the current host
  115. # architecture
  116. if hostarch == config_hostarch:
  117. keep = True
  118. # Assume that x86 32 bits toolchains work on x86_64 build
  119. # machines
  120. if hostarch == 'x86_64' and config_hostarch == "x86":
  121. keep = True
  122. if not keep:
  123. continue
  124. if not os.path.isabs(configfile):
  125. configfile = os.path.join(buildrootdir, configfile)
  126. with open(configfile) as r:
  127. config = r.readlines()
  128. configs.append(config)
  129. return configs
  130. def is_toolchain_usable(configfile, config):
  131. """Check if the toolchain is actually usable."""
  132. with open(configfile) as configf:
  133. configlines = configf.readlines()
  134. # Check that the toolchain configuration is still present
  135. for toolchainline in config:
  136. if toolchainline not in configlines:
  137. print("WARN: toolchain can't be used", file=sys.stderr)
  138. print(" Missing: %s" % toolchainline.strip(), file=sys.stderr)
  139. return False
  140. # The latest Linaro toolchains on x86-64 hosts requires glibc
  141. # 2.14+ on the host.
  142. if platform.machine() == 'x86_64':
  143. if 'BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM=y\n' in configlines or \
  144. 'BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64=y\n' in configlines or \
  145. 'BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64_BE=y\n' in configlines or \
  146. 'BR2_TOOLCHAIN_EXTERNAL_LINARO_ARMEB=y\n' in configlines:
  147. ldd_version_output = subprocess.check_output(['ldd', '--version'])
  148. glibc_version = ldd_version_output.decode().splitlines()[0].split()[-1]
  149. if StrictVersion('2.14') > StrictVersion(glibc_version):
  150. print("WARN: ignoring the Linaro ARM toolchains because too old host glibc", file=sys.stderr)
  151. return False
  152. return True
  153. def fixup_config(sysinfo, configfile):
  154. """Finalize the configuration and reject any problematic combinations
  155. This function returns 'True' when the configuration has been
  156. accepted, and 'False' when the configuration has not been accepted because
  157. it is known to fail (in which case another random configuration will be
  158. generated).
  159. """
  160. with open(configfile) as configf:
  161. configlines = configf.readlines()
  162. ROOTFS_SIZE = '5G'
  163. BR2_TOOLCHAIN_EXTERNAL_URL = 'BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/'
  164. if "BR2_NEEDS_HOST_JAVA=y\n" in configlines and not sysinfo.has("java"):
  165. return False
  166. # The ctng toolchain is affected by PR58854
  167. if 'BR2_PACKAGE_LTTNG_TOOLS=y\n' in configlines and \
  168. BR2_TOOLCHAIN_EXTERNAL_URL + 'armv5-ctng-linux-gnueabi.tar.xz"\n' in configlines:
  169. return False
  170. # The ctng toolchain tigger an assembler error with guile package when compiled with -Os (same issue as for CS ARM 2014.05-29)
  171. if 'BR2_PACKAGE_GUILE=y\n' in configlines and \
  172. 'BR2_OPTIMIZE_S=y\n' in configlines and \
  173. BR2_TOOLCHAIN_EXTERNAL_URL + 'armv5-ctng-linux-gnueabi.tar.xz"\n' in configlines:
  174. return False
  175. # The ctng toolchain is affected by PR58854
  176. if 'BR2_PACKAGE_LTTNG_TOOLS=y\n' in configlines and \
  177. BR2_TOOLCHAIN_EXTERNAL_URL + 'armv6-ctng-linux-uclibcgnueabi.tar.xz"\n' in configlines:
  178. return False
  179. # The ctng toolchain is affected by PR58854
  180. if 'BR2_PACKAGE_LTTNG_TOOLS=y\n' in configlines and \
  181. BR2_TOOLCHAIN_EXTERNAL_URL + 'armv7-ctng-linux-gnueabihf.tar.xz"\n' in configlines:
  182. return False
  183. # The ctng toolchain is affected by PR60155
  184. if 'BR2_PACKAGE_SDL=y\n' in configlines and \
  185. BR2_TOOLCHAIN_EXTERNAL_URL + 'powerpc-ctng-linux-uclibc.tar.xz"\n' in configlines:
  186. return False
  187. # The ctng toolchain is affected by PR60155
  188. if 'BR2_PACKAGE_LIBMPEG2=y\n' in configlines and \
  189. BR2_TOOLCHAIN_EXTERNAL_URL + 'powerpc-ctng-linux-uclibc.tar.xz"\n' in configlines:
  190. return False
  191. # This MIPS toolchain uses eglibc-2.18 which lacks SYS_getdents64
  192. if 'BR2_PACKAGE_STRONGSWAN=y\n' in configlines and \
  193. BR2_TOOLCHAIN_EXTERNAL_URL + 'mips64el-ctng_n64-linux-gnu.tar.xz"\n' in configlines:
  194. return False
  195. # This MIPS toolchain uses eglibc-2.18 which lacks SYS_getdents64
  196. if 'BR2_PACKAGE_PYTHON3=y\n' in configlines and \
  197. BR2_TOOLCHAIN_EXTERNAL_URL + 'mips64el-ctng_n64-linux-gnu.tar.xz"\n' in configlines:
  198. return False
  199. # libffi not available on ARMv7-M, but propagating libffi arch
  200. # dependencies in Buildroot is really too much work, so we handle
  201. # this here.
  202. if 'BR2_ARM_CPU_ARMV7M=y\n' in configlines and \
  203. 'BR2_PACKAGE_LIBFFI=y\n' in configlines:
  204. return False
  205. if 'BR2_PACKAGE_SUNXI_BOARDS=y\n' in configlines:
  206. configlines.remove('BR2_PACKAGE_SUNXI_BOARDS_FEX_FILE=""\n')
  207. configlines.append('BR2_PACKAGE_SUNXI_BOARDS_FEX_FILE="a10/hackberry.fex"\n')
  208. # This MIPS uClibc toolchain fails to build the gdb package
  209. if 'BR2_PACKAGE_GDB=y\n' in configlines and \
  210. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  211. return False
  212. # This MIPS uClibc toolchain fails to build the rt-tests package
  213. if 'BR2_PACKAGE_RT_TESTS=y\n' in configlines and \
  214. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  215. return False
  216. # This MIPS uClibc toolchain fails to build the civetweb package
  217. if 'BR2_PACKAGE_CIVETWEB=y\n' in configlines and \
  218. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  219. return False
  220. # This MIPS ctng toolchain fails to build the python3 package
  221. if 'BR2_PACKAGE_PYTHON3=y\n' in configlines and \
  222. BR2_TOOLCHAIN_EXTERNAL_URL + 'mips64el-ctng_n64-linux-gnu.tar.xz"\n' in configlines:
  223. return False
  224. # This MIPS uClibc toolchain fails to build the strace package
  225. if 'BR2_PACKAGE_STRACE=y\n' in configlines and \
  226. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  227. return False
  228. # This MIPS uClibc toolchain fails to build the cdrkit package
  229. if 'BR2_PACKAGE_CDRKIT=y\n' in configlines and \
  230. 'BR2_STATIC_LIBS=y\n' in configlines and \
  231. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  232. return False
  233. # uClibc vfork static linking issue
  234. if 'BR2_PACKAGE_ALSA_LIB=y\n' in configlines and \
  235. 'BR2_STATIC_LIBS=y\n' in configlines and \
  236. BR2_TOOLCHAIN_EXTERNAL_URL + 'i486-ctng-linux-uclibc.tar.xz"\n' in configlines:
  237. return False
  238. # This MIPS uClibc toolchain fails to build the weston package
  239. if 'BR2_PACKAGE_WESTON=y\n' in configlines and \
  240. BR2_TOOLCHAIN_EXTERNAL_URL + 'mipsel-ctng-linux-uclibc.tar.xz"\n' in configlines:
  241. return False
  242. # The cs nios2 2017.02 toolchain is affected by binutils PR19405
  243. if 'BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII=y\n' in configlines and \
  244. 'BR2_PACKAGE_BOOST=y\n' in configlines:
  245. return False
  246. # The cs nios2 2017.02 toolchain is affected by binutils PR19405
  247. if 'BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII=y\n' in configlines and \
  248. 'BR2_PACKAGE_QT5BASE_GUI=y\n' in configlines:
  249. return False
  250. # The cs nios2 2017.02 toolchain is affected by binutils PR19405
  251. if 'BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII=y\n' in configlines and \
  252. 'BR2_PACKAGE_FLANN=y\n' in configlines:
  253. return False
  254. if 'BR2_PACKAGE_AUFS_UTIL=y\n' in configlines and \
  255. 'BR2_PACKAGE_AUFS_UTIL_VERSION=""\n' in configlines:
  256. return False
  257. if 'BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE=y\n' in configlines and \
  258. 'BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE=""\n' in configlines and \
  259. 'BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE=""\n' in configlines:
  260. bootenv = os.path.join(args.outputdir, "boot_env.txt")
  261. with open(bootenv, "w+") as bootenvf:
  262. bootenvf.write("prop=value")
  263. configlines.remove('BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE=""\n')
  264. configlines.append('BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE="%s"\n' % bootenv)
  265. configlines.remove('BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE=""\n')
  266. configlines.append('BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE="0x1000"\n')
  267. if 'BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT=y\n' in configlines and \
  268. 'BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT_SOURCE=""\n' in configlines:
  269. bootscr = os.path.join(args.outputdir, "boot_script.txt")
  270. with open(bootscr, "w+") as bootscrf:
  271. bootscrf.write("prop=value")
  272. configlines.remove('BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT_SOURCE=""\n')
  273. configlines.append('BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT_SOURCE="%s"\n' % bootscr)
  274. if 'BR2_ROOTFS_SKELETON_CUSTOM=y\n' in configlines and \
  275. 'BR2_ROOTFS_SKELETON_CUSTOM_PATH=""\n' in configlines:
  276. configlines.remove('BR2_ROOTFS_SKELETON_CUSTOM=y\n')
  277. configlines.remove('BR2_ROOTFS_SKELETON_CUSTOM_PATH=""\n')
  278. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  279. 'BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y\n' in configlines and \
  280. 'BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=""\n' in configlines:
  281. configlines.remove('BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y\n')
  282. configlines.append('BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y\n')
  283. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=""\n')
  284. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  285. 'BR2_LINUX_KERNEL_USE_DEFCONFIG=y\n' in configlines and \
  286. 'BR2_LINUX_KERNEL_DEFCONFIG=""\n' in configlines:
  287. configlines.remove('BR2_LINUX_KERNEL_USE_DEFCONFIG=y\n')
  288. configlines.append('BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y\n')
  289. configlines.remove('BR2_LINUX_KERNEL_DEFCONFIG=""\n')
  290. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  291. 'BR2_LINUX_KERNEL_CUSTOM_GIT=y\n' in configlines and \
  292. 'BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n' in configlines:
  293. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_GIT=y\n')
  294. configlines.append('BR2_LINUX_KERNEL_LATEST_VERSION=y\n')
  295. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n')
  296. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  297. 'BR2_LINUX_KERNEL_CUSTOM_HG=y\n' in configlines and \
  298. 'BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n' in configlines:
  299. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_HG=y\n')
  300. configlines.append('BR2_LINUX_KERNEL_LATEST_VERSION=y\n')
  301. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n')
  302. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  303. 'BR2_LINUX_KERNEL_CUSTOM_SVN=y\n' in configlines and \
  304. 'BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n' in configlines:
  305. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_SVN=y\n')
  306. configlines.append('BR2_LINUX_KERNEL_LATEST_VERSION=y\n')
  307. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_REPO_URL=""\n')
  308. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  309. 'BR2_LINUX_KERNEL_CUSTOM_TARBALL=y\n' in configlines and \
  310. 'BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION=""\n' in configlines:
  311. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_TARBALL=y\n')
  312. configlines.append('BR2_LINUX_KERNEL_LATEST_VERSION=y\n')
  313. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION=""\n')
  314. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  315. 'BR2_LINUX_KERNEL_CUSTOM_VERSION=y\n' in configlines and \
  316. 'BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE=""\n' in configlines:
  317. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_VERSION=y\n')
  318. configlines.append('BR2_LINUX_KERNEL_LATEST_VERSION=y\n')
  319. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE=""\n')
  320. if 'BR2_LINUX_KERNEL=y\n' in configlines and \
  321. 'BR2_LINUX_KERNEL_DTS_SUPPORT=y\n' in configlines and \
  322. 'BR2_LINUX_KERNEL_INTREE_DTS_NAME=""\n' in configlines and \
  323. 'BR2_LINUX_KERNEL_CUSTOM_DTS_PATH=""\n' in configlines:
  324. configlines.remove('BR2_LINUX_KERNEL_DTS_SUPPORT=y\n')
  325. configlines.remove('BR2_LINUX_KERNEL_INTREE_DTS_NAME=""\n')
  326. configlines.remove('BR2_LINUX_KERNEL_CUSTOM_DTS_PATH=""\n')
  327. if 'BR2_LINUX_KERNEL_APPENDED_UIMAGE=y\n' in configlines:
  328. configlines.remove('BR2_LINUX_KERNEL_APPENDED_UIMAGE=y\n')
  329. configlines.append('BR2_LINUX_KERNEL_UIMAGE=y\n')
  330. if 'BR2_LINUX_KERNEL_APPENDED_ZIMAGE=y\n' in configlines:
  331. configlines.remove('BR2_LINUX_KERNEL_APPENDED_ZIMAGE=y\n')
  332. configlines.append('BR2_LINUX_KERNEL_ZIMAGE=y\n')
  333. if 'BR2_LINUX_KERNEL_CUIMAGE=y\n' in configlines:
  334. configlines.remove('BR2_LINUX_KERNEL_CUIMAGE=y\n')
  335. configlines.append('BR2_LINUX_KERNEL_UIMAGE=y\n')
  336. if 'BR2_LINUX_KERNEL_SIMPLEIMAGE=y\n' in configlines:
  337. configlines.remove('BR2_LINUX_KERNEL_SIMPLEIMAGE=y\n')
  338. configlines.append('BR2_LINUX_KERNEL_VMLINUX=y\n')
  339. if 'BR2_LINUX_KERNEL_EXT_AUFS=y\n' in configlines and \
  340. 'BR2_LINUX_KERNEL_EXT_AUFS_VERSION=""\n' in configlines:
  341. configlines.remove('BR2_LINUX_KERNEL_EXT_AUFS=y\n')
  342. configlines.remove('BR2_LINUX_KERNEL_EXT_AUFS_VERSION=""\n')
  343. if 'BR2_PACKAGE_LINUX_BACKPORTS=y\n' in configlines and \
  344. 'BR2_PACKAGE_LINUX_BACKPORTS_USE_CUSTOM_CONFIG=y\n' in configlines and \
  345. 'BR2_PACKAGE_LINUX_BACKPORTS_CUSTOM_CONFIG_FILE=""\n' in configlines:
  346. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS=y\n')
  347. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS_USE_CUSTOM_CONFIG=y\n')
  348. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS_CUSTOM_CONFIG_FILE=""\n')
  349. if 'BR2_PACKAGE_LINUX_BACKPORTS=y\n' in configlines and \
  350. 'BR2_PACKAGE_LINUX_BACKPORTS_USE_DEFCONFIG=y\n' in configlines and \
  351. 'BR2_PACKAGE_LINUX_BACKPORTS_DEFCONFIG=""\n' in configlines:
  352. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS=y\n')
  353. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS_USE_DEFCONFIG=y\n')
  354. configlines.remove('BR2_PACKAGE_LINUX_BACKPORTS_DEFCONFIG=""\n')
  355. if 'BR2_KERNEL_HEADERS_VERSION=y\n' in configlines and \
  356. 'BR2_DEFAULT_KERNEL_VERSION=""\n' in configlines:
  357. configlines.remove('BR2_KERNEL_HEADERS_VERSION=y\n')
  358. configlines.remove('BR2_DEFAULT_KERNEL_VERSION=""\n')
  359. if 'BR2_KERNEL_HEADERS_CUSTOM_GIT=y\n' in configlines and \
  360. 'BR2_KERNEL_HEADERS_CUSTOM_REPO_URL=""\n':
  361. configlines.remove('BR2_KERNEL_HEADERS_CUSTOM_GIT=y\n')
  362. configlines.remove('BR2_KERNEL_HEADERS_CUSTOM_REPO_URL=""\n')
  363. if 'BR2_KERNEL_HEADERS_CUSTOM_TARBALL=y\n' in configlines and \
  364. 'BR2_KERNEL_HEADERS_CUSTOM_TARBALL_LOCATION=""\n' in configlines:
  365. configlines.remove('BR2_KERNEL_HEADERS_CUSTOM_TARBALL=y\n')
  366. configlines.remove('BR2_KERNEL_HEADERS_CUSTOM_TARBALL_LOCATION=""\n')
  367. if 'BR2_TARGET_ARM_TRUSTED_FIRMWARE=y\n' in configlines and \
  368. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_PLATFORM=""\n' in configlines:
  369. return False;
  370. if 'BR2_TARGET_ARM_TRUSTED_FIRMWARE=y\n' in configlines and \
  371. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION=y\n' in configlines and \
  372. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION_VALUE=""\n' in configlines:
  373. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION=y\n')
  374. configlines.append('BR2_TARGET_ARM_TRUSTED_FIRMWARE_LATEST_VERSION=y\n')
  375. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION_VALUE=""\n')
  376. if 'BR2_TARGET_ARM_TRUSTED_FIRMWARE=y\n' in configlines and \
  377. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_TARBALL=y\n' in configlines and \
  378. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_TARBALL_LOCATION=""\n' in configlines:
  379. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_TARBALL=y\n')
  380. configlines.append('BR2_TARGET_ARM_TRUSTED_FIRMWARE_LATEST_VERSION=y\n')
  381. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_TARBALL_LOCATION=""\n')
  382. if 'BR2_TARGET_ARM_TRUSTED_FIRMWARE=y\n' in configlines and \
  383. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_GIT=y\n' in configlines and \
  384. 'BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_REPO_URL=""\n' in configlines:
  385. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_GIT=y\n')
  386. configlines.append('BR2_TARGET_ARM_TRUSTED_FIRMWARE_LATEST_VERSION=y\n')
  387. configlines.remove('BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_REPO_URL=""\n')
  388. if 'BR2_TARGET_AT91BOOTSTRAP3=y\n' in configlines and \
  389. 'BR2_TARGET_AT91BOOTSTRAP3_DEFCONFIG=""\n' in configlines:
  390. configlines.remove('BR2_TARGET_AT91BOOTSTRAP3=y\n')
  391. configlines.remove('BR2_TARGET_AT91BOOTSTRAP3_DEFCONFIG=""\n')
  392. if 'BR2_TARGET_BAREBOX=y\n' in configlines and \
  393. 'BR2_TARGET_BAREBOX_USE_CUSTOM_CONFIG=y\n' in configlines and \
  394. 'BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE=""\n' in configlines:
  395. configlines.remove('BR2_TARGET_BAREBOX=y\n')
  396. configlines.remove('BR2_TARGET_BAREBOX_USE_CUSTOM_CONFIG=y\n')
  397. configlines.remove('BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE=""\n')
  398. if 'BR2_TARGET_BAREBOX=y\n' in configlines and \
  399. 'BR2_TARGET_BAREBOX_USE_DEFCONFIG=y\n' in configlines and \
  400. 'BR2_TARGET_BAREBOX_BOARD_DEFCONFIG=""\n' in configlines:
  401. configlines.remove('BR2_TARGET_BAREBOX=y\n')
  402. configlines.remove('BR2_TARGET_BAREBOX_USE_DEFCONFIG=y\n')
  403. configlines.remove('BR2_TARGET_BAREBOX_BOARD_DEFCONFIG=""\n')
  404. if 'BR2_TARGET_OPTEE_OS=y\n' in configlines and \
  405. 'BR2_TARGET_OPTEE_OS_CUSTOM_TARBALL=y\n' in configlines and \
  406. 'BR2_TARGET_OPTEE_OS_CUSTOM_TARBALL_LOCATION=""\n' in configlines:
  407. configlines.remove('BR2_TARGET_OPTEE_OS_CUSTOM_TARBALL=y\n')
  408. configlines.append('BR2_TARGET_OPTEE_OS_LATEST=y\n')
  409. configlines.remove('BR2_TARGET_OPTEE_OS_CUSTOM_TARBALL_LOCATION=""\n')
  410. if 'BR2_TARGET_OPTEE_OS=y\n' in configlines and \
  411. 'BR2_TARGET_OPTEE_OS_PLATFORM=""\n' in configlines:
  412. configlines.remove('BR2_TARGET_OPTEE_OS=y\n')
  413. configlines.remove('BR2_TARGET_OPTEE_OS_PLATFORM=""\n')
  414. if 'BR2_TARGET_ROOTFS_EXT2=y\n' in configlines and \
  415. 'BR2_TARGET_ROOTFS_EXT2_SIZE="60M"\n' in configlines:
  416. configlines.remove('BR2_TARGET_ROOTFS_EXT2_SIZE="60M"\n')
  417. configlines.append('BR2_TARGET_ROOTFS_EXT2_SIZE="%s"\n' % ROOTFS_SIZE)
  418. if 'BR2_TARGET_ROOTFS_F2FS=y\n' in configlines and \
  419. 'BR2_TARGET_ROOTFS_F2FS_SIZE="100M"\n' in configlines:
  420. configlines.remove('BR2_TARGET_ROOTFS_F2FS_SIZE="100M"\n')
  421. configlines.append('BR2_TARGET_ROOTFS_F2FS_SIZE="%s"\n' % ROOTFS_SIZE)
  422. if 'BR2_TARGET_S500_BOOTLOADER=y\n' in configlines and \
  423. 'BR2_TARGET_S500_BOOTLOADER_BOARD=""\n' in configlines:
  424. configlines.remove('BR2_TARGET_S500_BOOTLOADER=y\n')
  425. configlines.remove('BR2_TARGET_S500_BOOTLOADER_BOARD=""\n')
  426. if 'BR2_TARGET_UBOOT=y\n' in configlines and \
  427. 'BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y\n' in configlines and \
  428. 'BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG=y\n' in configlines and \
  429. 'BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE=""\n' in configlines:
  430. configlines.remove('BR2_TARGET_UBOOT=y\n')
  431. configlines.remove('BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y\n')
  432. configlines.remove('BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG=y\n')
  433. configlines.remove('BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE=""\n')
  434. if 'BR2_TARGET_UBOOT=y\n' in configlines and \
  435. 'BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y\n' in configlines and \
  436. 'BR2_TARGET_UBOOT_USE_DEFCONFIG=y\n' in configlines and \
  437. 'BR2_TARGET_UBOOT_BOARD_DEFCONFIG=""\n' in configlines:
  438. configlines.remove('BR2_TARGET_UBOOT=y\n')
  439. configlines.remove('BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y\n')
  440. configlines.remove('BR2_TARGET_UBOOT_USE_DEFCONFIG=y\n')
  441. configlines.remove('BR2_TARGET_UBOOT_BOARD_DEFCONFIG=""\n')
  442. if 'BR2_TARGET_UBOOT=y\n' in configlines and \
  443. 'BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY=y\n' in configlines and \
  444. 'BR2_TARGET_UBOOT_BOARDNAME=""\n' in configlines:
  445. configlines.remove('BR2_TARGET_UBOOT=y\n')
  446. configlines.remove('BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY=y\n')
  447. configlines.remove('BR2_TARGET_UBOOT_BOARDNAME=""\n')
  448. if 'BR2_TOOLCHAIN_EXTERNAL=y\n' in configlines and \
  449. 'BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED=y\n' in configlines and \
  450. 'BR2_TOOLCHAIN_EXTERNAL_PATH=""\n' in configlines:
  451. configlines.remove('BR2_TOOLCHAIN_EXTERNAL=y\n')
  452. configlines.remove('BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED=y\n')
  453. configlines.remove('BR2_TOOLCHAIN_EXTERNAL_PATH=""\n')
  454. if 'BR2_ARCH_HAS_NO_TOOLCHAIN_BUILDROOT=y\n' in configlines:
  455. return False
  456. if 'BR2_TOOLCHAIN_EXTERNAL=y\n' in configlines and \
  457. 'BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y\n' in configlines and \
  458. 'BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y\n' in configlines and \
  459. 'BR2_TOOLCHAIN_EXTERNAL_URL=""\n' in configlines:
  460. configlines.remove('BR2_TOOLCHAIN_EXTERNAL=y\n')
  461. configlines.remove('BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y\n')
  462. configlines.remove('BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y\n')
  463. configlines.remove('BR2_TOOLCHAIN_EXTERNAL_URL=""\n')
  464. if 'BR2_ARCH_HAS_NO_TOOLCHAIN_BUILDROOT=y\n' in configlines:
  465. return False
  466. if 'BR2_TARGET_OPENSBI=y\n' in configlines and \
  467. 'BR2_TARGET_OPENSBI_CUSTOM_GIT=y\n' in configlines and \
  468. 'BR2_TARGET_OPENSBI_CUSTOM_REPO_URL=""\n' in configlines:
  469. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_GIT=y\n')
  470. configlines.append('BR2_TARGET_OPENSBI_LATEST_VERSION=y\n')
  471. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_REPO_URL=""\n')
  472. if 'BR2_TARGET_OPENSBI=y\n' in configlines and \
  473. 'BR2_TARGET_OPENSBI_CUSTOM_TARBALL=y\n' in configlines and \
  474. 'BR2_TARGET_OPENSBI_CUSTOM_TARBALL_LOCATION=""\n' in configlines:
  475. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_TARBALL=y\n')
  476. configlines.append('BR2_TARGET_OPENSBI_LATEST_VERSION=y\n')
  477. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_TARBALL_LOCATION=""\n')
  478. if 'BR2_TARGET_OPENSBI=y\n' in configlines and \
  479. 'BR2_TARGET_OPENSBI_CUSTOM_VERSION=y\n' in configlines and \
  480. 'BR2_TARGET_OPENSBI_CUSTOM_VERSION_VALUE=""\n' in configlines:
  481. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_VERSION=y\n')
  482. configlines.append('BR2_TARGET_OPENSBI_LATEST_VERSION=y\n')
  483. configlines.remove('BR2_TARGET_OPENSBI_CUSTOM_VERSION_VALUE=""\n')
  484. if 'BR2_PACKAGE_REFPOLICY=y\n' in configlines and \
  485. 'BR2_PACKAGE_REFPOLICY_CUSTOM_GIT=y\n' in configlines and \
  486. 'BR2_PACKAGE_REFPOLICY_CUSTOM_REPO_URL=""\n' in configlines:
  487. configlines.remove('BR2_PACKAGE_REFPOLICY_CUSTOM_GIT=y\n')
  488. configlines.append('BR2_PACKAGE_REFPOLICY_UPSTREAM_VERSION=y\n')
  489. configlines.remove('BR2_PACKAGE_REFPOLICY_CUSTOM_REPO_URL=""\n')
  490. if 'BR2_PACKAGE_XENOMAI=y\n' in configlines and \
  491. 'BR2_PACKAGE_XENOMAI_CUSTOM_GIT=y\n' in configlines and \
  492. 'BR2_PACKAGE_XENOMAI_REPOSITORY=""\n' in configlines:
  493. configlines.remove('BR2_PACKAGE_XENOMAI_CUSTOM_GIT=y\n')
  494. configlines.append('BR2_PACKAGE_XENOMAI_LATEST_VERSION=y\n')
  495. configlines.remove('BR2_PACKAGE_XENOMAI_REPOSITORY=""\n')
  496. if 'BR2_PACKAGE_XENOMAI=y\n' in configlines and \
  497. 'BR2_PACKAGE_XENOMAI_CUSTOM_TARBALL=y\n' in configlines and \
  498. 'BR2_PACKAGE_XENOMAI_CUSTOM_TARBALL_URL=""\n' in configlines:
  499. configlines.remove('BR2_PACKAGE_XENOMAI_CUSTOM_TARBALL=y\n')
  500. configlines.append('BR2_PACKAGE_XENOMAI_LATEST_VERSION=y\n')
  501. configlines.remove('BR2_PACKAGE_XENOMAI_CUSTOM_TARBALL_URL=""\n')
  502. if 'BR2_PACKAGE_XENOMAI=y\n' in configlines and \
  503. 'BR2_PACKAGE_XENOMAI_CUSTOM_VERSION=y\n' in configlines and \
  504. 'BR2_PACKAGE_XENOMAI_CUSTOM_VERSION_VALUE=""\n' in configlines:
  505. configlines.remove('BR2_PACKAGE_XENOMAI_CUSTOM_VERSION=y\n')
  506. configlines.append('BR2_PACKAGE_XENOMAI_LATEST_VERSION=y\n')
  507. configlines.remove('BR2_PACKAGE_XENOMAI_CUSTOM_VERSION_VALUE=""\n')
  508. if 'BR2_PACKAGE_XVISOR=y\n' in configlines and \
  509. 'BR2_PACKAGE_XVISOR_USE_CUSTOM_CONFIG=y\n' in configlines and \
  510. 'BR2_PACKAGE_XVISOR_CUSTOM_CONFIG_FILE=""\n' in configlines:
  511. configlines.remove('BR2_PACKAGE_XVISOR_USE_CUSTOM_CONFIG=y\n')
  512. configlines.append('BR2_PACKAGE_XVISOR_USE_DEFCONFIG=y\n')
  513. configlines.remove('BR2_PACKAGE_XVISOR_CUSTOM_CONFIG_FILE=""\n')
  514. with open(configfile, "w+") as configf:
  515. configf.writelines(configlines)
  516. return True
  517. def gen_config(args):
  518. """Generate a new random configuration
  519. This function generates the configuration, by choosing a random
  520. toolchain configuration and then generating a random selection of
  521. packages.
  522. """
  523. sysinfo = SystemInfo()
  524. if args.toolchains_csv:
  525. # Select a random toolchain configuration
  526. configs = get_toolchain_configs(args.toolchains_csv, args.buildrootdir)
  527. i = randint(0, len(configs) - 1)
  528. toolchainconfig = configs[i]
  529. else:
  530. toolchainconfig = []
  531. configlines = list(toolchainconfig)
  532. # Combine with the minimal configuration
  533. minimalconfigfile = os.path.join(args.buildrootdir,
  534. 'support/config-fragments/minimal.config')
  535. with open(minimalconfigfile) as minimalf:
  536. configlines += minimalf.readlines()
  537. # Allow hosts with old certificates to download over https
  538. configlines.append("BR2_WGET=\"wget --passive-ftp -nd -t 3 --no-check-certificate\"\n")
  539. # Per-package folder
  540. if randint(0, 15) == 0:
  541. configlines.append("BR2_PER_PACKAGE_DIRECTORIES=y\n")
  542. # Amend the configuration with a few things.
  543. if randint(0, 20) == 0:
  544. configlines.append("BR2_ENABLE_DEBUG=y\n")
  545. if randint(0, 20) == 0:
  546. configlines.append("BR2_ENABLE_RUNTIME_DEBUG=y\n")
  547. if randint(0, 1) == 0:
  548. configlines.append("BR2_INIT_BUSYBOX=y\n")
  549. elif randint(0, 15) == 0:
  550. configlines.append("BR2_INIT_SYSTEMD=y\n")
  551. elif randint(0, 10) == 0:
  552. configlines.append("BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y\n")
  553. if randint(0, 20) == 0:
  554. configlines.append("BR2_STATIC_LIBS=y\n")
  555. if randint(0, 20) == 0:
  556. configlines.append("BR2_PACKAGE_PYTHON3_PY_ONLY=y\n")
  557. if randint(0, 5) == 0:
  558. configlines.append("BR2_OPTIMIZE_2=y\n")
  559. if randint(0, 4) == 0:
  560. configlines.append("BR2_SYSTEM_ENABLE_NLS=y\n")
  561. if randint(0, 4) == 0:
  562. configlines.append("BR2_FORTIFY_SOURCE_2=y\n")
  563. # Randomly enable BR2_REPRODUCIBLE 10% of times
  564. # also enable tar filesystem images for testing
  565. if sysinfo.has("diffoscope") and randint(0, 10) == 0:
  566. configlines.append("BR2_REPRODUCIBLE=y\n")
  567. configlines.append("BR2_TARGET_ROOTFS_TAR=y\n")
  568. # Write out the configuration file
  569. if not os.path.exists(args.outputdir):
  570. os.makedirs(args.outputdir)
  571. if args.outputdir == os.path.abspath(os.path.join(args.buildrootdir, "output")):
  572. configfile = os.path.join(args.buildrootdir, ".config")
  573. else:
  574. configfile = os.path.join(args.outputdir, ".config")
  575. with open(configfile, "w+") as configf:
  576. configf.writelines(configlines)
  577. subprocess.check_call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
  578. "olddefconfig"])
  579. if not is_toolchain_usable(configfile, toolchainconfig):
  580. return 2
  581. # Now, generate the random selection of packages, and fixup
  582. # things if needed.
  583. # Safe-guard, in case we can not quickly come to a valid
  584. # configuration: allow at most 100 (arbitrary) iterations.
  585. bounded_loop = 100
  586. while True:
  587. if bounded_loop == 0:
  588. print("ERROR: cannot generate random configuration after 100 iterations",
  589. file=sys.stderr)
  590. return 1
  591. bounded_loop -= 1
  592. make_rand = [
  593. "make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
  594. "KCONFIG_SEED=0x%s" % hexlify(os.urandom(4)).decode("ascii").upper(),
  595. "KCONFIG_PROBABILITY=%d" % randint(1, 20),
  596. "randpackageconfig" if args.toolchains_csv else "randconfig"
  597. ]
  598. subprocess.check_call(make_rand)
  599. if fixup_config(sysinfo, configfile):
  600. break
  601. subprocess.check_call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
  602. "olddefconfig"])
  603. subprocess.check_call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
  604. "savedefconfig"])
  605. return subprocess.call(["make", "O=%s" % args.outputdir, "-C", args.buildrootdir,
  606. "dependencies"])
  607. if __name__ == '__main__':
  608. import argparse
  609. parser = argparse.ArgumentParser(description="Generate a random configuration")
  610. parser.add_argument("--outputdir", "-o",
  611. help="Output directory (relative to current directory)",
  612. type=str, default='output')
  613. parser.add_argument("--buildrootdir", "-b",
  614. help="Buildroot directory (relative to current directory)",
  615. type=str, default='.')
  616. toolchains_csv = parser.add_mutually_exclusive_group(required=False)
  617. toolchains_csv.add_argument("--toolchains-csv",
  618. dest="toolchains_csv",
  619. help="Path of the toolchain configuration file",
  620. type=str)
  621. toolchains_csv.add_argument("--no-toolchains-csv",
  622. dest="toolchains_csv",
  623. help="Generate random toolchain configuration",
  624. action='store_false')
  625. parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
  626. args = parser.parse_args()
  627. # We need the absolute path to use with O=, because the relative
  628. # path to the output directory here is not relative to the
  629. # Buildroot sources, but to the current directory.
  630. args.outputdir = os.path.abspath(args.outputdir)
  631. try:
  632. ret = gen_config(args)
  633. except Exception:
  634. traceback.print_exc()
  635. parser.exit(1)
  636. parser.exit(ret)