Merge ~sylvain-pineau/plainbox-provider-resource:bootloader_resource_lk into plainbox-provider-resource:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 585cbc2ce0ca185b4df1095759db4ab5c36938a1
Merged at revision: 113d2766475c41c8d42837d6aff1391ea57972dd
Proposed branch: ~sylvain-pineau/plainbox-provider-resource:bootloader_resource_lk
Merge into: plainbox-provider-resource:master
Diff against target: 62 lines (+22/-4)
2 files modified
bin/bootloader_resource.py (+21/-4)
jobs/resource.pxu (+1/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+374035@code.launchpad.net

Description of the change

Add lk support to bootloader_resource

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

Concerns described below...

Revision history for this message
Jonathan Cave (jocave) wrote :

After much discussion with Ondrej, the best method seems to be to use kernel_cmdline parser output to pick the parameter snap_kernel=<name>. The <name> value should be then be used to select the correct booting_matrix line in snap_boot_selection and the associated BOOTIMG_ is what should be returned.

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Implemented the above solution based on the kernel_cmdline parser.

review: Needs Resubmitting
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Tested on target system:

===========================[ Running Selected Jobs ]============================
--------------[ Running job 1 / 1. Estimated time left: 0:00:01 ]---------------
---------------[ Detect which bootloader is used on the device ]----------------
ID: com.canonical.certification::bootloader
Category: com.canonical.plainbox::uncategorised
... 8< -------------------------------------------------------------------------
name: lk
booted-kernel-path: /dev/disk/by-partlabel/BOOTIMG1
booted-kernel-partition-type: raw

------------------------------------------------------------------------- >8 ---
Outcome: job passed

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/bootloader_resource.py b/bin/bootloader_resource.py
2index 2ef1743..cc1fef3 100755
3--- a/bin/bootloader_resource.py
4+++ b/bin/bootloader_resource.py
5@@ -16,6 +16,8 @@
6 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
7
8 import os
9+import re
10+import subprocess as sp
11
12 from checkbox_support.parsers.kernel_cmdline import parse_kernel_cmdline
13
14@@ -42,7 +44,7 @@ def booted_kernel_location(bl_name):
15 type = 'unknown'
16 if bl_name == 'uboot':
17 pass
18- if bl_name == 'grub':
19+ elif bl_name == 'grub':
20 # what about force-kernel-extract true/false ?
21 type = 'fs'
22 with open('/proc/cmdline', 'r') as f:
23@@ -50,10 +52,25 @@ def booted_kernel_location(bl_name):
24 result = parse_kernel_cmdline(cmdline)
25 grub_path = result.params['BOOT_IMAGE']
26 path = os.path.join('/boot/efi', grub_path[grub_path.index(')')+2:])
27- if bl_name == 'androidboot':
28+ elif bl_name == 'androidboot':
29 pass
30- if bl_name == 'lk':
31- # get partlabel of actiave boot partition using `lk-boot-env -r`
32+ elif bl_name == 'lk':
33+ with open('/proc/cmdline', 'r') as f:
34+ cmdline = f.readline()
35+ result = parse_kernel_cmdline(cmdline)
36+ snap_kernel = result.params['snap_kernel']
37+ # get the bootimg matrix using `lk-boot-env -r`
38+ try:
39+ snap_boot_selection = sp.run(
40+ ['lk-boot-env', '-r', os.path.join(*bootloaders['lk'])],
41+ check=True, stdout=sp.PIPE).stdout.decode()
42+ match = re.search(
43+ 'bootimg_matrix\s+\[(.*?)\]\[{}\]'.format(snap_kernel),
44+ snap_boot_selection, re.M)
45+ if match:
46+ path = os.path.join(bootloaders['lk'][0], match.group(1))
47+ except FileNotFoundError:
48+ path = 'unknown'
49 type = 'raw'
50 return (path, type)
51
52diff --git a/jobs/resource.pxu b/jobs/resource.pxu
53index e786c77..9584e88 100644
54--- a/jobs/resource.pxu
55+++ b/jobs/resource.pxu
56@@ -453,5 +453,6 @@ _description:
57 device. This can help identify what boot security systems might be used.
58 plugin: resource
59 estimated_duration: 1.0
60+user: root
61 command:
62 bootloader_resource.py

Subscribers

People subscribed via source and target branches