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 | |
George Keishing | b1d2f49 | 2022-12-15 13:33:42 -0600 | [diff] [blame] | 7 | import bmc_ssh_utils as bsu # NOQA |
| 8 | import var_funcs as vf # NOQA |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 9 | |
| 10 | |
| 11 | # Define 'constant' functions. |
| 12 | def secure_boot_mask(): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 13 | return 0x08000000 |
| 14 | |
| 15 | |
| 16 | def jumper_mask(): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 17 | return 0x04000000 |
| 18 | |
| 19 | |
| 20 | class secureboot(object): |
Lakshminarayana R. Kammath | eca4dce | 2019-03-27 12:28:06 -0500 | [diff] [blame] | 21 | 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 |