summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/contrib/improve_kernel_cve_report.py27
-rw-r--r--scripts/lib/devtool/deploy.py19
-rwxr-xr-xscripts/lib/devtool/ide_sdk.py2
-rw-r--r--scripts/lib/wic/ksparser.py21
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py14
5 files changed, 70 insertions, 13 deletions
diff --git a/scripts/contrib/improve_kernel_cve_report.py b/scripts/contrib/improve_kernel_cve_report.py
index 5c39df05a5..3a15b1ed26 100755
--- a/scripts/contrib/improve_kernel_cve_report.py
+++ b/scripts/contrib/improve_kernel_cve_report.py
@@ -236,6 +236,26 @@ def read_spdx3(spdx):
236 cfiles.add(filename) 236 cfiles.add(filename)
237 return cfiles 237 return cfiles
238 238
239def read_debugsources(file_path):
240 '''
241 Read zstd file from pkgdata to extract sources
242 '''
243 import zstandard as zstd
244 import itertools
245 # Decompress the .zst file
246 cfiles = set()
247 with open(file_path, 'rb') as fh:
248 dctx = zstd.ZstdDecompressor()
249 with dctx.stream_reader(fh) as reader:
250 decompressed_bytes = reader.read()
251 json_data = json.loads(decompressed_bytes)
252 # We need to remove one level from the debug sources
253 for source_list in json_data.values():
254 for source in source_list:
255 src = source.split("/",1)[1]
256 cfiles.add(src)
257 return cfiles
258
239def check_kernel_compiled_files(compiled_files, cve_info): 259def check_kernel_compiled_files(compiled_files, cve_info):
240 """ 260 """
241 Return if a CVE affected us depending on compiled files 261 Return if a CVE affected us depending on compiled files
@@ -373,6 +393,10 @@ def main():
373 help="SPDX2/3 for the kernel. Needs to include compiled sources", 393 help="SPDX2/3 for the kernel. Needs to include compiled sources",
374 ) 394 )
375 parser.add_argument( 395 parser.add_argument(
396 "--debug-sources-file",
397 help="Debug sources zstd file generated from Yocto",
398 )
399 parser.add_argument(
376 "--datadir", 400 "--datadir",
377 type=pathlib.Path, 401 type=pathlib.Path,
378 help="Directory where CVE data is", 402 help="Directory where CVE data is",
@@ -415,6 +439,9 @@ def main():
415 if args.spdx: 439 if args.spdx:
416 compiled_files = read_spdx(args.spdx) 440 compiled_files = read_spdx(args.spdx)
417 logging.info("Total compiled files %d", len(compiled_files)) 441 logging.info("Total compiled files %d", len(compiled_files))
442 if args.debug_sources_file:
443 compiled_files = read_debugsources(args.debug_sources_file)
444 logging.info("Total compiled files %d", len(compiled_files))
418 445
419 if args.old_cve_report: 446 if args.old_cve_report:
420 with open(args.old_cve_report, encoding='ISO-8859-1') as f: 447 with open(args.old_cve_report, encoding='ISO-8859-1') as f:
diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
index b5ca8f2c2f..a98b33c571 100644
--- a/scripts/lib/devtool/deploy.py
+++ b/scripts/lib/devtool/deploy.py
@@ -20,9 +20,9 @@ from devtool import exec_fakeroot_no_d, setup_tinfoil, check_workspace_recipe, D
20 20
21logger = logging.getLogger('devtool') 21logger = logging.getLogger('devtool')
22 22
23deploylist_path = '/.devtool' 23deploylist_dirname = '.devtool'
24 24
25def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=False, nopreserve=False, nocheckspace=False): 25def _prepare_remote_script(deploy, destdir='/', verbose=False, dryrun=False, undeployall=False, nopreserve=False, nocheckspace=False):
26 """ 26 """
27 Prepare a shell script for running on the target to 27 Prepare a shell script for running on the target to
28 deploy/undeploy files. We have to be careful what we put in this 28 deploy/undeploy files. We have to be careful what we put in this
@@ -31,6 +31,7 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals
31 busybox rather than bash with coreutils). 31 busybox rather than bash with coreutils).
32 """ 32 """
33 lines = [] 33 lines = []
34 deploylist_path = os.path.join(destdir, deploylist_dirname)
34 lines.append('#!/bin/sh') 35 lines.append('#!/bin/sh')
35 lines.append('set -e') 36 lines.append('set -e')
36 if undeployall: 37 if undeployall:
@@ -146,7 +147,7 @@ def deploy(args, config, basepath, workspace):
146 except Exception as e: 147 except Exception as e:
147 raise DevtoolError('Exception parsing recipe %s: %s' % 148 raise DevtoolError('Exception parsing recipe %s: %s' %
148 (args.recipename, e)) 149 (args.recipename, e))
149 150
150 srcdir = rd.getVar('D') 151 srcdir = rd.getVar('D')
151 workdir = rd.getVar('WORKDIR') 152 workdir = rd.getVar('WORKDIR')
152 path = rd.getVar('PATH') 153 path = rd.getVar('PATH')
@@ -244,6 +245,7 @@ def deploy_no_d(srcdir, workdir, path, strip_cmd, libdir, base_libdir, max_proce
244 tmpscript = '/tmp/devtool_deploy.sh' 245 tmpscript = '/tmp/devtool_deploy.sh'
245 tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list') 246 tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list')
246 shellscript = _prepare_remote_script(deploy=True, 247 shellscript = _prepare_remote_script(deploy=True,
248 destdir=destdir,
247 verbose=args.show_status, 249 verbose=args.show_status,
248 nopreserve=args.no_preserve, 250 nopreserve=args.no_preserve,
249 nocheckspace=args.no_check_space) 251 nocheckspace=args.no_check_space)
@@ -303,12 +305,19 @@ def undeploy(args, config, basepath, workspace):
303 scp_port = "-P %s" % args.port 305 scp_port = "-P %s" % args.port
304 ssh_port = "-p %s" % args.port 306 ssh_port = "-p %s" % args.port
305 307
306 args.target = args.target.split(':')[0] 308 try:
309 host, destdir = args.target.split(':')
310 except ValueError:
311 destdir = '/'
312 else:
313 args.target = host
314 if not destdir.endswith('/'):
315 destdir += '/'
307 316
308 tmpdir = tempfile.mkdtemp(prefix='devtool') 317 tmpdir = tempfile.mkdtemp(prefix='devtool')
309 try: 318 try:
310 tmpscript = '/tmp/devtool_undeploy.sh' 319 tmpscript = '/tmp/devtool_undeploy.sh'
311 shellscript = _prepare_remote_script(deploy=False, dryrun=args.dry_run, undeployall=args.all) 320 shellscript = _prepare_remote_script(deploy=False, destdir=destdir, dryrun=args.dry_run, undeployall=args.all)
312 # Write out the script to a file 321 # Write out the script to a file
313 with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f: 322 with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
314 f.write(shellscript) 323 f.write(shellscript)
diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index d9b54f7991..87a4c13ec5 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -104,7 +104,7 @@ class RecipeNative:
104 104
105 105
106class RecipeGdbCross(RecipeNative): 106class RecipeGdbCross(RecipeNative):
107 """Handle handle gdb-cross on the host and the gdbserver on the target device""" 107 """Handle gdb-cross on the host and the gdbserver on the target device"""
108 108
109 def __init__(self, args, target_arch, target_device): 109 def __init__(self, args, target_arch, target_device):
110 super().__init__('gdb-cross-' + target_arch, target_arch) 110 super().__init__('gdb-cross-' + target_arch, target_arch)
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 48b5b09ddd..4ccd70dc55 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -16,6 +16,7 @@ import os
16import shlex 16import shlex
17import logging 17import logging
18import re 18import re
19import uuid
19 20
20from argparse import ArgumentParser, ArgumentError, ArgumentTypeError 21from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
21 22
@@ -196,7 +197,7 @@ class KickStart():
196 bootloader.add_argument('--configfile') 197 bootloader.add_argument('--configfile')
197 bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'), 198 bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'),
198 default='msdos') 199 default='msdos')
199 bootloader.add_argument('--diskid', type=lambda x: int(x, 0)) 200 bootloader.add_argument('--diskid')
200 bootloader.add_argument('--timeout', type=int) 201 bootloader.add_argument('--timeout', type=int)
201 bootloader.add_argument('--source') 202 bootloader.add_argument('--source')
202 203
@@ -297,6 +298,24 @@ class KickStart():
297 if append_var: 298 if append_var:
298 self.bootloader.append = ' '.join(filter(None, \ 299 self.bootloader.append = ' '.join(filter(None, \
299 (self.bootloader.append, append_var))) 300 (self.bootloader.append, append_var)))
301 if parsed.diskid:
302 if parsed.ptable == "msdos":
303 try:
304 self.bootloader.diskid = int(parsed.diskid, 0)
305 except ValueError:
306 err = "with --ptbale msdos only 32bit integers " \
307 "are allowed for --diskid. %s could not " \
308 "be parsed" % self.ptable
309 raise KickStartError(err)
310 else:
311 try:
312 self.bootloader.diskid = uuid.UUID(parsed.diskid)
313 except ValueError:
314 err = "with --ptable %s only valid uuids are " \
315 "allowed for --diskid. %s could not be " \
316 "parsed" % (parsed.ptable, parsed.diskid)
317 raise KickStartError(err)
318
300 else: 319 else:
301 err = "%s:%d: more than one bootloader specified" \ 320 err = "%s:%d: more than one bootloader specified" \
302 % (confpath, lineno) 321 % (confpath, lineno)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index f40f033a3d..ad922cfbf1 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -315,7 +315,14 @@ class PartitionedImage():
315 # all partitions (in bytes) 315 # all partitions (in bytes)
316 self.ptable_format = ptable_format # Partition table format 316 self.ptable_format = ptable_format # Partition table format
317 # Disk system identifier 317 # Disk system identifier
318 if disk_id: 318 if disk_id and ptable_format in ('gpt', 'gpt-hybrid'):
319 self.disk_guid = disk_id
320 elif os.getenv('SOURCE_DATE_EPOCH'):
321 self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
322 else:
323 self.disk_guid = uuid.uuid4()
324
325 if disk_id and ptable_format == 'msdos':
319 self.identifier = disk_id 326 self.identifier = disk_id
320 elif os.getenv('SOURCE_DATE_EPOCH'): 327 elif os.getenv('SOURCE_DATE_EPOCH'):
321 self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff) 328 self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff)
@@ -545,11 +552,6 @@ class PartitionedImage():
545 552
546 def _write_disk_guid(self): 553 def _write_disk_guid(self):
547 if self.ptable_format in ('gpt', 'gpt-hybrid'): 554 if self.ptable_format in ('gpt', 'gpt-hybrid'):
548 if os.getenv('SOURCE_DATE_EPOCH'):
549 self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH')))
550 else:
551 self.disk_guid = uuid.uuid4()
552
553 logger.debug("Set disk guid %s", self.disk_guid) 555 logger.debug("Set disk guid %s", self.disk_guid)
554 sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \ 556 sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \
555 (self.sector_size, self.path, self.disk_guid) 557 (self.sector_size, self.path, self.disk_guid)