blob: 1c3ec3a81212ff49bdfe72257a72cb6237586de7 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -05002
3r"""
4This module provides some functions for Secure Boot verification.
5"""
6
George Keishingb1d2f492022-12-15 13:33:42 -06007import bmc_ssh_utils as bsu # NOQA
8import var_funcs as vf # NOQA
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -05009
10
11# Define 'constant' functions.
12def secure_boot_mask():
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050013 return 0x08000000
14
15
16def jumper_mask():
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050017 return 0x04000000
18
19
20class secureboot(object):
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050021 def get_secure_boot_info(self, quiet=None):
22 r"""
23 Get secure-boot information and return it as a tuple consisting of
24 num_procs, secure_boot, jumper.
25
26 num_procs is the number of processors containing the information.
27
28 secure_boot will be set to True if each and every register value
29 in question has its secureboot bit set (Bit 4).
30
31 jumper will be set to True if each and every register value
32 in question has its jumper bit set (Bit 5).
33
34 Description of argument(s):
35 quiet See shell_cmd for details.
36 """
37
38 cmd_buf = "pdbg -d p9w -a getcfam 0x2801"
39 out_buf, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet)
40
41 # Convert result to a dictionary with one key for each processor:
42 # result:
43 # [p0:0x2801]: 0x80c00002
44 # [p1:0x2801]: 0x90c00002
45 result = vf.key_value_outbuf_to_dict(out_buf, delim="=")
46
47 num_procs = len(result)
48 # Initialize values to True.
49 secure_boot = True
50 jumper = True
51
52 for key, value in result.items():
53 # Convert hex string to int.
54 reg_value = int(value, 16)
55 if not reg_value & secure_boot_mask():
56 secure_boot = False
57 if not reg_value & jumper_mask():
58 jumper = False
59
60 return num_procs, secure_boot, jumper