From 01fdb200a34b1ef30f99312cd63b22c07ea550cb Mon Sep 17 00:00:00 2001 From: Antony Messerli Date: Fri, 3 Jan 2020 23:51:45 -0600 Subject: [PATCH] Adds PCI Device List to menu Adds a PCI Device list tool to the menu which uses the pci.ids list and refreshes it during deployment. --- roles/netbootxyz/defaults/main.yml | 4 +++ roles/netbootxyz/files/pciids_gen | 26 ++++++++++++++ roles/netbootxyz/tasks/generate_pciids.yml | 27 +++++++++++++++ roles/netbootxyz/tasks/main.yml | 6 +++- roles/netbootxyz/templates/menu/lspci.ipxe.j2 | 34 +++++++++++++++++++ roles/netbootxyz/templates/menu/menu.ipxe.j2 | 1 + 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 roles/netbootxyz/files/pciids_gen create mode 100644 roles/netbootxyz/tasks/generate_pciids.yml create mode 100644 roles/netbootxyz/templates/menu/lspci.ipxe.j2 diff --git a/roles/netbootxyz/defaults/main.yml b/roles/netbootxyz/defaults/main.yml index 356cd1d4..020142b8 100644 --- a/roles/netbootxyz/defaults/main.yml +++ b/roles/netbootxyz/defaults/main.yml @@ -35,6 +35,10 @@ generate_version_file: false generate_checksums: true checksums_filename: "{{ site_name }}-sha256-checksums.txt" +# pciids +generate_pciids: true +pciids_url: https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids + # bootloader options generate_disks: true generate_disks_legacy: true diff --git a/roles/netbootxyz/files/pciids_gen b/roles/netbootxyz/files/pciids_gen new file mode 100755 index 00000000..4dae058f --- /dev/null +++ b/roles/netbootxyz/files/pciids_gen @@ -0,0 +1,26 @@ +#!/bin/bash +# Used for processing pci.ids into ipxe format +# https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids + +if [[ ! -n "$1" || ! -n "$2" ]]; then + echo "Please set PCIIDS file location and PCIIDS output file location..." + echo "pciids_gen pci.ids pciids.ipxe" + exit 1 +fi + +PCIIDS_FILE=$1 +PCIIDS_IPXE=$2 + +awk ' \ + BEGIN { \ + print "#!ipxe\ngoto ${vendor}${device} || goto ${vendor} || exit" \ + } \ + /^[0-9a-f]{4}/ { \ + vendor=substr($1,1,4); \ + printf ":%s\nset ven %s\nexit\n", vendor, substr($0,7) \ + } \ + /^\t[0-9a-f]{4}/ { \ + printf ":%s%s\nset dev %s\ngoto %s\n", \ + vendor, substr($0, 2, 4), substr($0, 8), vendor \ + } \ +' ${PCIIDS_FILE} > ${PCIIDS_IPXE} diff --git a/roles/netbootxyz/tasks/generate_pciids.yml b/roles/netbootxyz/tasks/generate_pciids.yml new file mode 100644 index 00000000..8f63f137 --- /dev/null +++ b/roles/netbootxyz/tasks/generate_pciids.yml @@ -0,0 +1,27 @@ +--- + - name: Retrieve pci.ids + get_url: + url: "{{ pciids_url }}" + dest: "{{ netbootxyz_root }}/pci.ids" + + - name: Copy pciids_gen script to source dir + copy: + src: pciids_gen + dest: "{{ netbootxyz_root }}/pciids_gen" + mode: 0744 + + - name: Convert pci.ids to pciids.ipxe + shell: | + ./pciids_gen pci.ids pciids.ipxe + args: + chdir: "{{ netbootxyz_root }}" + tags: + - skip_ansible_lint + + - name: Cleanup of files no longer needed + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ netbootxyz_root }}/pciids_gen" + - "{{ netbootxyz_root }}/pci.ids" diff --git a/roles/netbootxyz/tasks/main.yml b/roles/netbootxyz/tasks/main.yml index 0ba81804..be6a6695 100644 --- a/roles/netbootxyz/tasks/main.yml +++ b/roles/netbootxyz/tasks/main.yml @@ -3,6 +3,10 @@ when: - generate_menus | default(true) | bool + - include: generate_pciids.yml + when: + - generate_pciids | default(true) | bool + - include: generate_menus_custom.yml when: - custom_generate_menus | default(false) | bool @@ -21,4 +25,4 @@ - include: generate_signatures.yml when: - - generate_signatures | default(false) | bool \ No newline at end of file + - generate_signatures | default(false) | bool diff --git a/roles/netbootxyz/templates/menu/lspci.ipxe.j2 b/roles/netbootxyz/templates/menu/lspci.ipxe.j2 new file mode 100644 index 00000000..d3d5d53c --- /dev/null +++ b/roles/netbootxyz/templates/menu/lspci.ipxe.j2 @@ -0,0 +1,34 @@ +#!ipxe + +# gather pci devices and list them +clear addr +pciscan addr && goto pciscan_found || +echo No pci devices found... +exit +:pciscan_found + +set spaces2:hex 20:20 +set spaces4:hex 20:20:20:20 + +imgfetch pciids.ipxe +iseq ${sigs_enabled} true && goto verify_sigs || goto skip_verify +:verify_sigs +imgverify pciids.ipxe ${sigs}pciids.ipxe.sig || +:skip_verify + +clear addr +menu PCI device list +:scan pciscan addr || goto scan_done + clear ven + clear dev + set vendor ${pci/${addr}.0.2} + set device ${pci/${addr}.2.2} + chain pciids.ipxe + item --gap ${addr:busdevfn} ${spaces4:string} ${ven} + item b${addr:busdevfn} ${spaces2:string} ${vendor}:${device} ${dev} + goto scan +:scan_done +choose press_enter || + +imgfree pciids.ipxe +exit diff --git a/roles/netbootxyz/templates/menu/menu.ipxe.j2 b/roles/netbootxyz/templates/menu/menu.ipxe.j2 index 151c9f5c..931828be 100644 --- a/roles/netbootxyz/templates/menu/menu.ipxe.j2 +++ b/roles/netbootxyz/templates/menu/menu.ipxe.j2 @@ -57,6 +57,7 @@ iseq ${arch} x86_64 && set bits 64 || set bits 32 item changebits ${space} Architecture: ${arch} (${bits}bit) item shell ${space} iPXE shell item netinfo ${space} Network card info +item lspci ${space} PCI Device List item about ${space} About netboot.xyz {% if sigs_menu | bool %} item --gap Signature Checks: