Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adapt to use 4bytes address to dump more data #162

Merged
merged 8 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add select spi1 or 2
  • Loading branch information
dummys committed Feb 15, 2024
commit e766a1aff1cb71c4e30f54859ef8520d361e33ce
29 changes: 21 additions & 8 deletions contrib/hydra_spiflash_nor_dump/hydra_spiflash_nor_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,29 @@ def signal_handler(signal, frame):
class HydrabusSpiFlash:

def __init__(self, serial_port):

self.top_parser = argparse.ArgumentParser(add_help=False)
self.top_parser.add_argument('--spi',
default=1,
help='Set the SPI port to SPI1 or SPI2',
metavar='{1,2}')

parser = argparse.ArgumentParser(
parents=[self.top_parser],
description='Tool to query NOR memory flash with Hydrabus',
epilog='This script requires python 3.7+, and serial',
usage='''hydra_spiflash_nor_dump.py <command> [<args>]
usage='''hydra_spiflash_nor_dump.py <command> [<args>] [OPTIONS]

Commands are:
get_chip_id Return the chip identification
dump <dump_file> <n_4k_sectors> <hex_address> Dump the flash in <dump_file> starting at <hex_address>
get_chip_id Return the chip identification
dump <dump_file> <n_4k_sectors> <hex_address> Dump the flash in <dump_file> starting at <hex_address>

''')

parser.add_argument('command',
help='dump to dump the flash or get_chip_id')

args_spi = parser.parse_args()
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
print('Unrecognized command')
Expand All @@ -44,7 +54,7 @@ def __init__(self, serial_port):

self.serial_port = serial_port
self.hydrabus = None
self.setup()
self.setup(args_spi.spi)

# use dispatch pattern to invoke method with same name
getattr(self, args.command)()
Expand All @@ -61,7 +71,7 @@ def calc_hex_addr(self, addr, add, addr_len):
byte_arr = self.hex_to_bin(addr + add, addr_len)
return byte_arr

def setup(self):
def setup(self, spi):

# Open serial port
self.hydrabus = serial.Serial(self.serial_port, 115200)
Expand All @@ -80,8 +90,12 @@ def setup(self):
if b"SPI1" not in self.hydrabus.read(4):
self.error("Cannot set SPI mode, try again or reset hydrabus.")

# Configure SPI port (default polarity and clock phase, SPI1 device)
self.hydrabus.write(b'\x81')
if spi == 1:
# Configure SPI port (default polarity and clock phase, SPI1 device)
self.hydrabus.write(b'\x81')
else:
# Configure SPI port (default polarity and clock phase, SPI2 device)
self.hydrabus.write(b'\x80')
if b'\x01' not in self.hydrabus.read(1):
self.error(
"Cannot set SPI device settings, try again or reset hydrabus.")
Expand All @@ -102,7 +116,6 @@ def get_chip_id(self):

# send rdid byte (0x9f)
self.hydrabus.write(b'\x9f')

if b'\x01' not in self.hydrabus.read(1):
self.error('Oups something went wrong...')

Expand Down