blob: f38458e86a67841381f15f351a16ce7c8d5ebbbf [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
7import bmc_ssh_utils as bsu
8import var_funcs as vf
9from robot.libraries.BuiltIn import BuiltIn
10
11
12# Define 'constant' functions.
13def secure_boot_mask():
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050014 return 0x08000000
15
16
17def jumper_mask():
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050018 return 0x04000000
19
20
21class secureboot(object):
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050022 def get_secure_boot_info(self, quiet=None):
23 r"""
24 Get secure-boot information and return it as a tuple consisting of
25 num_procs, secure_boot, jumper.
26
27 num_procs is the number of processors containing the information.
28
29 secure_boot will be set to True if each and every register value
30 in question has its secureboot bit set (Bit 4).
31
32 jumper will be set to True if each and every register value
33 in question has its jumper bit set (Bit 5).
34
35 Description of argument(s):
36 quiet See shell_cmd for details.
37 """
38
39 cmd_buf = "pdbg -d p9w -a getcfam 0x2801"
40 out_buf, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet)
41
42 # Convert result to a dictionary with one key for each processor:
43 # result:
44 # [p0:0x2801]: 0x80c00002
45 # [p1:0x2801]: 0x90c00002
46 result = vf.key_value_outbuf_to_dict(out_buf, delim="=")
47
48 num_procs = len(result)
49 # Initialize values to True.
50 secure_boot = True
51 jumper = True
52
53 for key, value in result.items():
54 # Convert hex string to int.
55 reg_value = int(value, 16)
56 if not reg_value & secure_boot_mask():
57 secure_boot = False
58 if not reg_value & jumper_mask():
59 jumper = False
60
61 return num_procs, secure_boot, jumper