blob: 1aa5f0628f622e514e2a3fd707f5ed95c90ddbc7 [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():
George Keishinge635ddc2022-12-08 07:38:02 -060014
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050015 return 0x08000000
16
17
18def jumper_mask():
George Keishinge635ddc2022-12-08 07:38:02 -060019
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050020 return 0x04000000
21
22
23class secureboot(object):
George Keishinge635ddc2022-12-08 07:38:02 -060024
Lakshminarayana R. Kammatheca4dce2019-03-27 12:28:06 -050025 def get_secure_boot_info(self, quiet=None):
26 r"""
27 Get secure-boot information and return it as a tuple consisting of
28 num_procs, secure_boot, jumper.
29
30 num_procs is the number of processors containing the information.
31
32 secure_boot will be set to True if each and every register value
33 in question has its secureboot bit set (Bit 4).
34
35 jumper will be set to True if each and every register value
36 in question has its jumper bit set (Bit 5).
37
38 Description of argument(s):
39 quiet See shell_cmd for details.
40 """
41
42 cmd_buf = "pdbg -d p9w -a getcfam 0x2801"
43 out_buf, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet)
44
45 # Convert result to a dictionary with one key for each processor:
46 # result:
47 # [p0:0x2801]: 0x80c00002
48 # [p1:0x2801]: 0x90c00002
49 result = vf.key_value_outbuf_to_dict(out_buf, delim="=")
50
51 num_procs = len(result)
52 # Initialize values to True.
53 secure_boot = True
54 jumper = True
55
56 for key, value in result.items():
57 # Convert hex string to int.
58 reg_value = int(value, 16)
59 if not reg_value & secure_boot_mask():
60 secure_boot = False
61 if not reg_value & jumper_mask():
62 jumper = False
63
64 return num_procs, secure_boot, jumper