Flashrom chrashes when accessing i210 over PCIe bus

Hi,

We have a crash case with flashrom utility when it tries to access i210 over PCIe bus.

The problem seem similar to the following case:

lspci reports 1230000000 while flashrom uses 0x0000000040012000.
How can I give flashrom the correct memory address in this case?

lspci output is here:

agx@agx:~$ sudo lspci -vv
0001:00:00.0 PCI bridge: NVIDIA Corporation Device 1ad2 (rev a1) (prog-if 00 [Normal decode])
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin A routed to IRQ 35
	Bus: primary=00, secondary=01, subordinate=ff, sec-latency=0
	I/O behind bridge: 00000000-00000fff
	Memory behind bridge: 40000000-40bfffff
	Secondary status: 66MHz- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- <SERR- <PERR-
	BridgeCtl: Parity- SERR- NoISA- VGA- MAbort- >Reset- FastB2B-
		PriDiscTmr- SecDiscTmr- DiscTmrStat- DiscTmrSERREn-
	Capabilities: [40] Power Management version 3
		Flags: PMEClk- DSI- D1- D2- AuxCurrent=375mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
		Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
	Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
		Address: 0000000000000000  Data: 0000
	Capabilities: [70] Express (v2) Root Port (Slot-), MSI 00
		DevCap:	MaxPayload 256 bytes, PhantFunc 0
			ExtTag- RBE+
		DevCtl:	Report errors: Correctable+ Non-Fatal+ Fatal+ Unsupported+
			RlxdOrd+ ExtTag- PhantFunc- AuxPwr- NoSnoop+
			MaxPayload 256 bytes, MaxReadReq 512 bytes
		DevSta:	CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr+ TransPend-
		LnkCap:	Port #0, Speed 5GT/s, Width x1, ASPM L0s L1, Exit Latency L0s <1us, L1 <64us
			ClockPM- Surprise+ LLActRep+ BwNot+ ASPMOptComp+
		LnkCtl:	ASPM L1 Enabled; RCB 64 bytes Disabled- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt+ AutBWInt-
		LnkSta:	Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive+ BWMgmt+ ABWMgmt-
		RootCtl: ErrCorrectable- ErrNon-Fatal- ErrFatal- PMEIntEna+ CRSVisible+
		RootCap: CRSVisible+
		RootSta: PME ReqID 0000, PMEStatus- PMEPending-
		DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR+, OBFF Not Supported ARIFwd-
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR+, OBFF Disabled ARIFwd-
		LnkCtl2: Target Link Speed: 5GT/s, EnterCompliance- SpeedDis-
			 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
			 Compliance De-emphasis: -6dB
		LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete-, EqualizationPhase1-
			 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
	Capabilities: [b0] MSI-X: Enable- Count=1 Masked-
		Vector table: BAR=0 offset=00000000
		PBA: BAR=0 offset=00000000
	Capabilities: [100 v2] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr-
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
		AERCap:	First Error Pointer: 00, GenCap+ CGenEn- ChkCap+ ChkEn-
	Capabilities: [148 v1] #19
	Capabilities: [158 v1] #26
	Capabilities: [17c v1] #27
	Capabilities: [190 v1] L1 PM Substates
		L1SubCap: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2- ASPM_L1.1- L1_PM_Substates+
			  PortCommonModeRestoreTime=60us PortTPowerOnTime=40us
		L1SubCtl1: PCI-PM_L1.2- PCI-PM_L1.1- ASPM_L1.2- ASPM_L1.1-
			   T_CommonMode=60us
		L1SubCtl2: T_PwrOn=40us
	Capabilities: [1a0 v1] Vendor Specific Information: ID=0002 Rev=4 Len=100 <?>
	Capabilities: [2a0 v1] Vendor Specific Information: ID=0001 Rev=1 Len=038 <?>
	Capabilities: [2d8 v1] #25
	Capabilities: [2e4 v1] Precision Time Measurement
		PTMCap: Requester:- Responder:+ Root:+
		PTMClockGranularity: 16ns
		PTMControl: Enabled:- RootSelected:-
		PTMEffectiveGranularity: Unknown
	Capabilities: [2f0 v1] Vendor Specific Information: ID=0004 Rev=1 Len=054 <?>
	Kernel driver in use: pcieport

0001:01:00.0 Ethernet controller: Intel Corporation Device 1531 (rev 03)
	Subsystem: Intel Corporation Device 0000
	Control: I/O- Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Interrupt: pin A routed to IRQ 0
	Region 0: Memory at 1230000000 (32-bit, non-prefetchable) [disabled] [size=8M]
	Region 2: I/O ports at 100000 [disabled] [size=32]
	Region 3: Memory at 1230800000 (32-bit, non-prefetchable) [disabled] [size=16K]
	Capabilities: [40] Power Management version 3
		Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
		Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=1 PME-
	Capabilities: [50] MSI: Enable- Count=1/1 Maskable+ 64bit+
		Address: 0000000000000000  Data: 0000
		Masking: 00000000  Pending: 00000000
	Capabilities: [70] MSI-X: Enable- Count=5 Masked-
		Vector table: BAR=3 offset=00000000
		PBA: BAR=3 offset=00002000
	Capabilities: [a0] Express (v2) Endpoint, MSI 00
		DevCap:	MaxPayload 512 bytes, PhantFunc 0, Latency L0s <512ns, L1 <64us
			ExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset+ SlotPowerLimit 0.000W
		DevCtl:	Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
			RlxdOrd+ ExtTag- PhantFunc- AuxPwr- NoSnoop+ FLReset-
			MaxPayload 256 bytes, MaxReadReq 512 bytes
		DevSta:	CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr+ TransPend-
		LnkCap:	Port #4, Speed 2.5GT/s, Width x1, ASPM L0s L1, Exit Latency L0s <2us, L1 <16us
			ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp+
		LnkCtl:	ASPM L1 Enabled; RCB 64 bytes Disabled- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR+, OBFF Via WAKE#
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled
		LnkCtl2: Target Link Speed: 2.5GT/s, EnterCompliance- SpeedDis-
			 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
			 Compliance De-emphasis: -6dB
		LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete-, EqualizationPhase1-
			 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
	Capabilities: [100 v2] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr-
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
		AERCap:	First Error Pointer: 00, GenCap+ CGenEn- ChkCap+ ChkEn-
	Capabilities: [140 v1] Device Serial Number 00-a0-c9-ff-ff-00-00-00
	Capabilities: [1a0 v1] Transaction Processing Hints
		Device specific mode supported
		Steering table in TPH capability structure
	Capabilities: [1c0 v1] Latency Tolerance Reporting
		Max snoop latency: 0ns
		Max no snoop latency: 0ns

flashrom output is below:

agx@agx:~/flashrom$ cat ./write_firmware.sh 
echo 1 | sudo tee /sys/bus/pci/devices/0001\:01\:00.0/enable
sudo flashrom -VVVV -p nicintel_spi:pci=0001:01:00.0 -w intel_i210.bin
agx@agx:~/flashrom$ 
agx@agx:~/flashrom$ 
agx@agx:~/flashrom$ ./write_firmware.sh 
1
flashrom v1.2-511-g29418b7 on Linux 4.9.253 (aarch64)
flashrom is free software, get the source code at https://flashrom.org

flashrom was built with libpci 3.5.2, GCC 7.5.0, little endian
Command line (5 args): flashrom -VVVV -p nicintel_spi:pci=0001:01:00.0 -w intel_i210.bin
Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
Initializing nicintel_spi programmer
Found "Intel I210 Gigabit Network Connection Unprogrammed" (8086:1531, BDF 01:00.0).
PCI header type 0x00
Requested BAR is of type MEM, 32bit, not prefetchable
PCI header type 0x00
Requested BAR is of type MEM, 32bit, not prefetchable
page_size=1000
pre-rounding:  start=0x0000000040012000, len=0x1000, end=0x0000000040013000
post-rounding: start=0x0000000040012000, len=0x1000, end=0x0000000040013000
[ 2253.290939] CPU3: SError detected, daif=1c0, spsr=0x80000000, mpidr=80000101, esr=be000000
[ 2253.290947] CPU1: SError detected, daif=1c0, spsr=0x80c000c5, mpidr=80000001, esr=be000000
[ 2253.290951] CPU2: SError detected, daif=1c0, spsr=0x80c000c5, mpidr=80000100, esr=be000000
[ 2253.290956] CPU0: SError detected, daif=1c0, spsr=0x80c000c5, mpidr=80000000, esr=be000000
[ 2253.291051] ras_ccplex_serr_callback: Scanning CCPLEX Error Records for Uncorrectable Errors
[ 2253.291073] **************************************
[ 2253.291075] RAS Error in SCF:SNOC, ERRSELR_EL1=1026:
[ 2253.291077] 	Status = 0xf400a20d
[ 2253.291079] 	IERR = Uncorrectable Carveout  Error: 0xa2
[ 2253.291083] 	SERR = Illegal address (software fault): 0xd
[ 2253.291085] 	Uncorrectable (this is fatal)
[ 2253.291105] 	MISC0 = 0x1804
[ 2253.291107] 	MISC1 = 0x991800000800
[ 2253.291127] 	ADDR = 0x800000004001201c
[ 2253.291133] **************************************
[ 2253.291140] ras_corecluster_serr_callback:Scanning CoreCluster Error Records for Uncorrectable Errors
[ 2253.291161] **************************************
[ 2253.291162] RAS Error in L2, ERRSELR_EL1=528:
[ 2253.291163] 	Status = 0xfc00640d
[ 2253.291165] 	IERR = SCF to L2 Decode Error Read: 0x64
[ 2253.291166] 	SERR = Illegal address (software fault): 0xd
[ 2253.291168] 	Overflow (there may be more errors) - Uncorrectable
[ 2253.291169] 	Uncorrectable (this is fatal)
[ 2253.291175] 	MISC0 = 0x100000000100000
[ 2253.291176] 	MISC1 = 0x40240000000
[ 2253.291179] 	ADDR = 0x800000004001201c
[ 2253.291184] **************************************
[ 2253.291209] ras_core_serr_callback: Scanning Core Error Records for Uncorrectable Errors
[ 2253.291278] Bad mode in Error handler detected on CPU1, code 0xbe000000 -- SError
[ 2253.291281] Kernel panic - not syncing: bad mode
[ 2253.291299] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.9.253 #1
[ 2253.291301] Hardware name: Jetson-AGX (DT)
[ 2253.291304] Call trace:
[ 2253.291318] [<ffffff800808ba40>] dump_backtrace+0x0/0x198
[ 2253.291326] [<ffffff800808c004>] show_stack+0x24/0x30
[ 2253.291333] [<ffffff8008f5cd5c>] dump_stack+0xa0/0xc4
[ 2253.291340] [<ffffff8008f59e00>] panic+0x12c/0x2a8
[ 2253.291343] [<ffffff800808c894>] bad_mode+0x7c/0x80
[ 2253.291346] [<ffffff800808ca5c>] handle_serr+0x124/0x128
[ 2253.291349] [<ffffff8008082d98>] el1_serr+0xb0/0x144
[ 2253.291355] [<ffffff8008b9c4ec>] cpuidle_enter_state+0x84/0x380
[ 2253.291361] [<ffffff8008b9c85c>] cpuidle_enter+0x34/0x48
[ 2253.291365] ras_ccplex_serr_callback: Scanning CCPLEX Error Records for Uncorrectable Errors
[ 2253.291369] [<ffffff800811139c>] call_cpuidle+0x44/0x70
[ 2253.291373] [<ffffff8008111718>] cpu_startup_entry+0x1b0/0x200
[ 2253.291376] [<ffffff8008091cf8>] secondary_start_kernel+0x190/0x1f8
[ 2253.291381] [<0000000080f6a1a8>] 0x80f6a1a8
[ 2253.291387] SMP: stopping secondary CPUs
[ 2253.291394] ras_corecluster_serr_callback:Scanning CoreCluster Error Records for Uncorrectable Errors
[ 2253.291486] ras_core_serr_callback: Scanning Core Error Records for Uncorrectable Errors
[ 2253.291627] ras_ccplex_serr_callback: Scanning CCPLEX Error Records for Uncorrectable Errors
[ 2253.291693] ras_corecluster_serr_callback:Scanning CoreCluster Error Records for Uncorrectable Errors
[ 2253.291714] ras_core_serr_callback: Scanning Core Error Records for Uncorrectable Errors
[ 2253.568178] ras_ccplex_serr_callback: Scanning CCPLEX Error Records for Uncorrectable Errors
[ 2253.576771] ras_corecluster_serr_callback:Scanning CoreCluster Error Records for Uncorrectable Errors
[ 2253.586037] ras_core_serr_callback: Scanning Core Error Records for Uncorrectable Errors
[ 2253.594197] Kernel Offset: disabled
[ 2253.597841] Memory Limit: none
[ 2253.600555] trusty-log panic notifier - trusty version Built: 12:20:34 Jul 26 2021 [ 2253.615901] Rebooting in 5 seconds..

Thank you.

Best,

Tegra PCIe employs a translation mechanism to covert CPU issues address to the address that is sent across the PCIe interface. So, effectively, the CPU address is not equivalent to the PCIe bus address.
You need to change the flashrom to use the correct address in this. The correct address can be had from the following location. (Please note that it has information on all the BARs. So, you need to extract the info from there)
/sys/bus/pci/devices/0001:01:00.0/resouce