George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | This module provides some functions for Secure Boot verification. |
| 5 | """ |
| 6 | |
| 7 | import bmc_ssh_utils as bsu |
| 8 | import var_funcs as vf |
| 9 | from robot.libraries.BuiltIn import BuiltIn |
| 10 | |
| 11 | |
| 12 | # Define 'constant' functions. |
| 13 | def secure_boot_mask(): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 14 | return 0x08000000 |
| 15 | |
| 16 | |
| 17 | def jumper_mask(): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 18 | return 0x04000000 |
| 19 | |
| 20 | |
| 21 | class secureboot(object): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 22 | 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 |