فهرست منبع

Merge pull request #486 from netbootxyz/lspci

Adds PCI Device List to menu
Antony Messerli 5 سال پیش
والد
کامیت
9bfebc60ad

+ 4 - 0
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

+ 26 - 0
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}

+ 27 - 0
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"

+ 5 - 1
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
+    - generate_signatures | default(false) | bool

+ 34 - 0
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

+ 1 - 0
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: