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
diff --git a/bin/bootloader_resource.py b/bin/bootloader_resource.py
index 2ef1743..cc1fef3 100755
--- a/bin/bootloader_resource.py
+++ b/bin/bootloader_resource.py
@@ -16,6 +16,8 @@
16# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.16# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
1717
18import os18import os
19import re
20import subprocess as sp
1921
20from checkbox_support.parsers.kernel_cmdline import parse_kernel_cmdline22from checkbox_support.parsers.kernel_cmdline import parse_kernel_cmdline
2123
@@ -42,7 +44,7 @@ def booted_kernel_location(bl_name):
42 type = 'unknown'44 type = 'unknown'
43 if bl_name == 'uboot':45 if bl_name == 'uboot':
44 pass46 pass
45 if bl_name == 'grub':47 elif bl_name == 'grub':
46 # what about force-kernel-extract true/false ?48 # what about force-kernel-extract true/false ?
47 type = 'fs'49 type = 'fs'
48 with open('/proc/cmdline', 'r') as f:50 with open('/proc/cmdline', 'r') as f:
@@ -50,10 +52,25 @@ def booted_kernel_location(bl_name):
50 result = parse_kernel_cmdline(cmdline)52 result = parse_kernel_cmdline(cmdline)
51 grub_path = result.params['BOOT_IMAGE']53 grub_path = result.params['BOOT_IMAGE']
52 path = os.path.join('/boot/efi', grub_path[grub_path.index(')')+2:])54 path = os.path.join('/boot/efi', grub_path[grub_path.index(')')+2:])
53 if bl_name == 'androidboot':55 elif bl_name == 'androidboot':
54 pass56 pass
55 if bl_name == 'lk':57 elif bl_name == 'lk':
56 # get partlabel of actiave boot partition using `lk-boot-env -r`58 with open('/proc/cmdline', 'r') as f:
59 cmdline = f.readline()
60 result = parse_kernel_cmdline(cmdline)
61 snap_kernel = result.params['snap_kernel']
62 # get the bootimg matrix using `lk-boot-env -r`
63 try:
64 snap_boot_selection = sp.run(
65 ['lk-boot-env', '-r', os.path.join(*bootloaders['lk'])],
66 check=True, stdout=sp.PIPE).stdout.decode()
67 match = re.search(
68 'bootimg_matrix\s+\[(.*?)\]\[{}\]'.format(snap_kernel),
69 snap_boot_selection, re.M)
70 if match:
71 path = os.path.join(bootloaders['lk'][0], match.group(1))
72 except FileNotFoundError:
73 path = 'unknown'
57 type = 'raw'74 type = 'raw'
58 return (path, type)75 return (path, type)
5976
diff --git a/jobs/resource.pxu b/jobs/resource.pxu
index e786c77..9584e88 100644
--- a/jobs/resource.pxu
+++ b/jobs/resource.pxu
@@ -453,5 +453,6 @@ _description:
453 device. This can help identify what boot security systems might be used.453 device. This can help identify what boot security systems might be used.
454plugin: resource454plugin: resource
455estimated_duration: 1.0455estimated_duration: 1.0
456user: root
456command:457command:
457 bootloader_resource.py458 bootloader_resource.py

Subscribers

People subscribed via source and target branches