Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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(): |
| 14 | |
| 15 | return 0x08000000 |
| 16 | |
| 17 | |
| 18 | def jumper_mask(): |
| 19 | |
| 20 | return 0x04000000 |
| 21 | |
| 22 | |
| 23 | class secureboot(object): |
| 24 | |
| 25 | 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 |