|
| 1 | +*** Settings *** |
| 2 | +Documentation Common header for OSFV boot management |
| 3 | +
|
| 4 | +Library Collections |
| 5 | +Library OperatingSystem |
| 6 | +Library Process |
| 7 | +Library String |
| 8 | +Library RequestsLibrary |
| 9 | +Library SSHLibrary |
| 10 | +Resource ../../variables.robot |
| 11 | +Resource ../../keywords.robot |
| 12 | +Resource ../../keys.robot |
| 13 | + |
| 14 | + |
| 15 | +*** Keywords *** |
| 16 | +Set Selected OS As First In Boot Order Via EDK2 |
| 17 | + [Documentation] Uses EDK2 menu to select given OS as first in |
| 18 | + ... boot menu. |
| 19 | + ... |
| 20 | + ... === Requirements === |
| 21 | + ... - Serial port connection has to be supported by the platform |
| 22 | + ... - Must be within Dasharo's main UEFI firmware setup |
| 23 | + ... |
| 24 | + ... === Arguments === |
| 25 | + ... - ``${os}``: ``string`` - ENV_ID of the OS we want to boot |
| 26 | + ... |
| 27 | + ... === Return Value === |
| 28 | + ... - None |
| 29 | + ... |
| 30 | + ... === Effects === |
| 31 | + ... - OS specified by ENV_ID will be priority during subsequent boots |
| 32 | + ... - Resets the DUT via EDK2 reset |
| 33 | + [Arguments] ${os} |
| 34 | + ${system_name}= Get From Dictionary ${ENV_ID_OS_BOOTMENU_NAMES} ${os} |
| 35 | + |
| 36 | + # When ESP scanning feature is there, boot entries are named differently than |
| 37 | + # they used to |
| 38 | + IF ${ESP_SCANNING_SUPPORT} == ${TRUE} |
| 39 | + IF "${system_name}" == "ubuntu" |
| 40 | + ${system_name}= Set Variable Ubuntu |
| 41 | + ELSE IF "${system_name}" == "fedora" |
| 42 | + ${system_name}= Set Variable Fedora |
| 43 | + ELSE IF "${system_name}" == "trenchboot" and "${MANUFACTURER}" == "QEMU" |
| 44 | + ${system_name}= Set Variable QEMU HARDDISK |
| 45 | + END |
| 46 | + END |
| 47 | + |
| 48 | + ${menu}= Get Setup Menu Construction |
| 49 | + ${menu}= Enter Submenu From Snapshot And Return Construction |
| 50 | + ... ${menu} |
| 51 | + ... Boot Maintenance Manager |
| 52 | + ${menu}= Enter Submenu From Snapshot And Return Construction |
| 53 | + ... ${menu} |
| 54 | + ... Boot Options |
| 55 | + ${menu}= Enter Submenu From Snapshot And Return Construction |
| 56 | + ... ${menu} |
| 57 | + ... Change Boot Order |
| 58 | + Press Enter |
| 59 | + ${os_list_raw}= Read From Terminal Until ---/ |
| 60 | + ${os_list}= Extract Strings From Frame ${os_list_raw} |
| 61 | + ${first_item}= Set Variable ${os_list}[0] |
| 62 | + ${is_first}= Run Keyword And Return Status Should Contain ${first_item} ${system_name} |
| 63 | + |
| 64 | + IF '${is_first}' == 'False' |
| 65 | + ${index}= Set Variable -1 |
| 66 | + FOR ${i} ${item} IN ENUMERATE @{os_list} |
| 67 | + ${item_lower}= Convert To Lowercase ${item} |
| 68 | + ${system_lower}= Convert To Lowercase ${system_name} |
| 69 | + ${found}= Run Keyword And Return Status Should Contain ${item_lower} ${system_lower} |
| 70 | + IF '${found}' == 'True' |
| 71 | + ${index}= Set Variable ${i} |
| 72 | + BREAK |
| 73 | + END |
| 74 | + END |
| 75 | + |
| 76 | + Should Not Be Equal As Integers ${index} -1 |
| 77 | + ... System name '${system_name}' not found in boot menu list |
| 78 | + |
| 79 | + Press Key N Times ${index} ${ARROW_DOWN} |
| 80 | + Press Key N Times ${index} ${KEY_PLUS} |
| 81 | + Press Enter |
| 82 | + Write Bare Into Terminal ${F10} |
| 83 | + Sleep 1s |
| 84 | + Write Bare Into Terminal y |
| 85 | + # Return to main menu |
| 86 | + Press Key N Times 3 ${ESC} |
| 87 | + Sleep 1s |
| 88 | + # Issue reset in the menu |
| 89 | + Press Key N Times 2 ${ARROW_DOWN} |
| 90 | + Press Enter |
| 91 | + ELSE |
| 92 | + Log To Console ${system_name} already set as prio. |
| 93 | + END |
| 94 | + |
| 95 | +Set Selected OS As First In Boot Order Via Efibootmgr |
| 96 | + [Documentation] Uses Ubuntu and efibootmgr to select boot prioroty |
| 97 | + ... |
| 98 | + ... === Requirements === |
| 99 | + ... - Connection to DUT must be established. |
| 100 | + ... - Platform must boot Ubuntu to access efibootmgr |
| 101 | + ... |
| 102 | + ... === Arguments === |
| 103 | + ... - ``${os}``: ``string`` - ENV_ID of the OS we want to boot |
| 104 | + ... |
| 105 | + ... === Return Value === |
| 106 | + ... - None |
| 107 | + ... |
| 108 | + ... === Effects === |
| 109 | + ... - OS specified by ENV_ID will be priority during subsequent |
| 110 | + [Arguments] ${os} |
| 111 | + ${system_name}= Get From Dictionary ${ENV_ID_OS_BOOTMENU_NAMES} ${os} |
| 112 | + Log To Console Setting ${system_name} as boot priority. |
| 113 | + |
| 114 | + Boot System Or From Connected Disk ${ENV_ID_UBUNTU} |
| 115 | + Login To Linux |
| 116 | + Switch To Root User |
| 117 | + |
| 118 | + ${os_boot_id}= Execute Linux Command |
| 119 | + ... efibootmgr | grep -i "${system_name}" | awk 'NR==1 {print $1}' | sed 's/Boot//g' | sed 's/*//g' |
| 120 | + Should Not Be Empty ${os_boot_id} |
| 121 | + |
| 122 | + ${order_check}= Execute Linux Command |
| 123 | + ... efibootmgr | grep "BootOrder: ${os_boot_id}" |
| 124 | + |
| 125 | + # Trim the boot list to exclude target OS |
| 126 | + IF '${order_check}' == '${EMPTY}' |
| 127 | + ${boot_order_trimmed}= Execute Linux Command |
| 128 | + ... efibootmgr | grep "BootOrder" | awk '{print $2}' | sed -e 's/,${os_boot_id}//g' |
| 129 | + Should Not Be Empty ${boot_order_trimmed} |
| 130 | + |
| 131 | + ${set_order_cmd}= Set Variable efibootmgr -o |
| 132 | + ${set_order_cmd}= Catenate ${set_order_cmd} |
| 133 | + ... ${os_boot_id},${boot_order_trimmed} |
| 134 | + |
| 135 | + ${out}= Execute Linux Command ${set_order_cmd} |
| 136 | + Should Contain ${out} BootOrder: ${os_boot_id} |
| 137 | + END |
0 commit comments