Skip to content

Instantly share code, notes, and snippets.

@patrickschur
Created March 30, 2021 21:58
Show Gist options
  • Save patrickschur/a093be96c91264e7092cc2ba95616ee4 to your computer and use it in GitHub Desktop.
Save patrickschur/a093be96c91264e7092cc2ba95616ee4 to your computer and use it in GitHub Desktop.
Reads the SPI flash memory via SMN space
#!/usr/bin/python3
import struct
import io
import sys
import os
IOHC_NB_SMN_INDEX_REG = 0xC4
config = os.open("/sys/devices/pci0000:00/0000:00:00.0/config", os.O_RDWR)
buffer = io.BytesIO()
for offset in range(0x44000000, 0x45FFFFFF, 4):
os.lseek(config, IOHC_NB_SMN_INDEX_REG, os.SEEK_SET)
os.write(config, struct.pack("I", offset))
buffer.write(os.read(config, 4))
os.close(config)
sys.stdout.buffer.write(buffer.getbuffer())
@patrickschur
Copy link
Author

sudo ./spi.py > spi.bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment