; --------------------------------------------------------------------------------
; @Title: Layerscape LS1012A SPINAND FLASH Program script (FRWY-LS1012A)
; @Description:
; The W25M161(Winbond, 2dies NOR + NAND ) is on the QuadSPI controller
;
; SRAM: 0x10000000
; QuadSPI(controller) Base: 0x1550000
; FLASH BASE ADDRESS(Qspi mapped): 0x40000000
;
; Prerequisites:
; * Connect Debug Cable/Combiprobe to J9
; * U25 Winbond W25M161
;
; @Author: jjeong
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; @Board: FRDM-LS1012A
; @Chip: LS1012A
; @Keywords: S25FS512S Flash SPI QuadSPI
; --------------------------------------------------------------------------------
; $Id: ls1012-spinand.cmm 11733 2023-01-16 08:55:12Z bschroefel $
LOCAL &pdd
&pdd=OS.PresentDemoDirectory()
PRIVATE &arg1
ENTRY &arg1
&arg1=STRing.UPpeR("&arg1") // for example "PREPAREONLY"
&QSPI_BASE=0x1550000
&ECC_ENABLE=1 // 0:disable
IF SYStem.MODE()<5
(
RESet
SYStem.RESet
SYStem.CPU LS1012A
SYStem.MemAccess DAP
SYStem.Option TRST OFF
SYStem.Option EnReset ON
;
; temporarily override the RCW. The RCW is fetched while the boot phase and defines initial
; pinmux/serdes/qspi/nor/nand/... configurations.
; The RCW override requires to reset the SoC. Two methods are supported.
; Method 1: EnReset OFF && HRCWOVerRide ON /PORESET - do not assert the nReset line, issue a JTAG based PORESET
; Method 2: EnReset ON && HRCWOVerRide ON - assert the nReset line
; Steps - Override RCW_SRC only
; * set EnReset & HRCWOVerRide - Method 1/2
; * switch to SYStem.Mode Prepare
; * write the RCW_SRC value to EDBG:0x42000040
; * switch to SYStem.Up
; Steps - Override RCW completely
; * set EnReset & HRCWOVerRide - Method 1/2
; * switch to SYStem.Mode Prepare
; * write the RCW_SRC value HARDCODED to EDBG:0x42000040
; * write the RCW itself to EDBG:0x42000000 onwards
; * ensure in RCW[6]/EDBG:0x42000018 the PBL_SRC is reserved e.g. 0xfb8?????
; * switch to SYStem.Up
; The following RCW is used to connect to the device even with a empty flash.
; The pinmux is configured to map the QSPI pins.
SYStem.Option EnReset OFF
SYStem.Option HRCWOVerRide ON /PORESET
SYStem.Mode.Prepare
; override RCW_SRC = Hardcoded
Data.Set EDBG:0x42000040 %Long 0x9a
; override the RCW itself - values as from LS1012 hardcoded+qspi settings
Data.Set EDBG:0x42000000 %Long 0x08000008
Data.Set EDBG:0x42000004 %Long 0x00000000
Data.Set EDBG:0x42000008 %Long 0x00000000
Data.Set EDBG:0x4200000c %Long 0x00000000
Data.Set EDBG:0x42000010 %Long 0x00000000
Data.Set EDBG:0x42000014 %Long 0xC0000008
;Data.Set EDBG:0x42000018 %Long 0x40000000 ; PBL=QSPI, IFC=0x0
Data.Set EDBG:0x42000018 %Long 0xfb800000 ; PBL_SRC=reserved, IFC=0x0
Data.Set EDBG:0x4200001C %Long 0x01003800
Data.Set EDBG:0x42000020 %Long 0x00800000
Data.Set EDBG:0x42000024 %Long 0x00000000
Data.Set EDBG:0x42000028 %Long 0x00000000
Data.Set EDBG:0x4200002C %Long 0x00000000
Data.Set EDBG:0x42000030 %Long 0x00000000
Data.Set EDBG:0x42000034 %Long 0x00000180
Data.Set EDBG:0x42000038 %Long 0x00000096
Data.Set EDBG:0x4200003C %Long 0x00000000
;
SYStem.Up
)
Register.Set M 0xd ; use the EL3h bcz the EL1h can not access the sram memory region
//EL3 disable the MMU & Data cache
PER.Set.simple SPR:0x36100 %Quad.Long Data.Long(SPR:0x36100)&~0x5
; we should now have access to the QSPI & SD card pins ;-)
Data.Assemble 0x10000000 b $-0x0
Register.Set PC 0x10000000
MAP.BE &QSPI_BASE++0xFFFF
Data.Set AD:&QSPI_BASE %BE %Long 0xF0000 ; QSPI_MCR[END_CFG], 64BE
PER.Set.simple AD:0x157015C %Long %BE 0x50100000 ; sclk=PLL/16
GOSUB READ_ID_TEST
; -------------------------------------------------------------------------------
; FlashFile configuration
; -------------------------------------------------------------------------------
programFlash:
Break.RESet
FLASHFILE.RESet
// 128MB(1 Gbit) NAND Flash, 128KB(2KB * 2^6 pages) uni-blocks
flashfile.create 0x0--0x7FFFFFF 0x20000 Byte
//FLASHFILE.CONFIG
FLASHFILE.CONFIG &QSPI_BASE 0x40000000
//FLASHFILE.TARGET
FLASHFILE.TARGET 0x10010000++0x3FFF EAXI:0x10014000++0x4FFF &pdd/flash/byte/spinand2k6p_ls1000.bin /KEEP /STACKSIZE 0x400 /DualPort
//please check the Winbond spinand flash documentation for the command format
FLASHFILE.SPICMD 0xc2 0x1 ;die select for Winbond specific command to select the SPI NAND die
FLASHFILE.GETID
//GOSUB READ_SPINAND_REG ;read all the internal Status Registers values before you change it
FLASHFILE.SPICMD 01F 0xA0 0x0 ;Status Register-1(0xA0), unlock for the all flash sectors
IF &ECC_ENABLE==1
FLASHFILE.SPICMD 01F 0xB0 0x18 ;Status Register-2(0xB0), enable ecc & buffered mode
ELSE
FLASHFILE.SPICMD 01F 0xB0 0x08 ;Status Register-2(0xB0), disable ecc & enable buffered mode
; Flash script ends here if called with parameter PREPAREONLY
IF "&arg1"=="PREPAREONLY"
ENDDO
; -------------------------------------------------------------------------------
; Flash programming example
; -------------------------------------------------------------------------------
FLASHFILE.DUMP 0x0 ; Read NAND main area
;FLASHFILE.DUMP 0x0 /SPARE ; Read NAND spare area
;FLASHFILE.ERASE 0x0--0xFFFFFF /EraseBadBlocks ; Erase NAND
;FLASHFILE.LOAD * 0x0 /WriteBadBlocks ; Write NAND
ENDDO
READ_ID_TEST:
(
PRINT "READ_ID_TEST..."
&temp=Data.Long(A:&QSPI_BASE)
Data.Set A:&QSPI_BASE %Long %BE (&temp|0x0c00) //clear Tx/Rx buffer
Data.Set A:(&QSPI_BASE+0x300) %Long %BE 0x5AF05AF0 ; LUTKEY
Data.Set A:(&QSPI_BASE+0x304) %Long %BE 0x2 ; LCKCR
//SEQID 5
Data.Set A:(&QSPI_BASE+0x360) %Long %BE 0x1c04049f ; LUT0, SEQID0
Data.Set A:(&QSPI_BASE+0x364) %Long %BE 0x0
Data.Set A:(&QSPI_BASE+0x368) %Long %BE 0x0
Data.Set A:(&QSPI_BASE+0x36C) %Long %BE 0x0
Data.Set A:(&QSPI_BASE+0x100) %Long %BE 0x40000000 ; SFAR , FLASH BASE ADDRESS
// assert Read id command
Data.Set A:(&QSPI_BASE+0x008) %Long %BE (5.<<24.) ; (5.<<24.)
WAIT 100.ms
&temp=Data.Long(A:&QSPI_BASE)
Data.Set ZSD:&QSPI_BASE %Long %BE (&temp|0x0800) //clear Tx buffer
PRINT "1st 0x" Data.Long(A:&QSPI_BASE+0x200)>>24. " (Manufacturer)"
PRINT "2nd 0x" (Data.Long(A:&QSPI_BASE+0x200)>>16.)&0xFF " (Device ID)"
PRINT "3rd 0x" (Data.Long(A:&QSPI_BASE+0x200)>>8.)&0xFF
PRINT "4th 0x" Data.Long(A:&QSPI_BASE+0x200)&0xFF
RETURN
)
READ_SPINAND_REG:
(
//For the Winbond SPI NAND
FLASHFILE.SPICMD 0x05 0xA0 /Read 2. ;0x00
FLASHFILE.SPICMD 0x05 0xB0 /Read 2. ;0x08 or 18
FLASHFILE.SPICMD 0x05 0xC0 /Read 2. ;0x00
RETURN
)