nandutils.cmm

来自「QUALCOMM JNAND DRIVER」· CMM 代码 · 共 480 行

CMM
480
字号
; This script allows interactive managing of the NAND flash
;
local &debugflag
local &status &masked &statusstr
ENTRY &debugflag &status
if "&debugflag"!=""
  (
  &debugflag=0x1
  )
ELSE 
  (
  &debugflag=0x0
  )  
; if a 2nd param is passed, don't init anything (user knows all is setup)
if "&status"!=""
  (
  print "you passed a second parameter -- won't do any setup"
  )
ELSE
  (
  do constants.cmm
  system.CPU ARM9E
  system.jtagclock 1000000.
  system.up
  d.dump &NAND_BUFFER
  area
  ; Setup GPIO 33 so that NAND_ROM2_CS is setup (NAND flash).
  d.out 0x80001220 %LONG 33.
  d.out 0x80001224 %LONG 0x04
  ;Hard reset the NAND Controller
  d.set &NAND_FLASH_CMD %LONG 0x0
  wait 100.ms
  ;reset NAND flash controller memory 
  d.set &NAND_FLASH_CMD %LONG 0x7
  wait 100.ms
  ; enable the NAND bus (EBI2_CFG register)
  d.out 0x600000e0 %byte 0x2
  )

print
print   
print " ---------- Cougar NAND Flash Utilities -----------"
print "                Updated June 5th, 2002             "
print " Pages are 512bytes each, a block is either 16 or 32 pages (32 for Buck SURF)"
print "    Pass an argument, any argument, to get the full-featured menu  "
local &choice &subchoice &value &data
Main_Menu:
  print
  print " 0: Exit"
  if &debugflag==0x1
    (
    print " 1: Reset NAND Ctlr            2: Reset NAND device"
    print " 3: Zerofill NAND Ctlr buffer  4: Get NAND Ctlr Status"
    print " 5: Read NAND page             6: Write NAND page" 
    print " 7: Erase Block                8: Write lowest 16 pages of NAND (8k Boot Block)"
    )
  print "10: Survey config pages       11: Dump config page to file"
  print "12: Program config page from file"
  if &debugflag==0x1
    (
    print "20: Read File into NAND buffer "
    print "21: Output Buffer to file "
    print "22: Survey block"
    )
     
  print " Please make a choice: "
  
  &t32_cmm_stopped=1
  enter &choice
  &t32_cmm_stopped=0

area.clear 




if &choice==0  
  (  
  print "...exited NAND Utilities"
  enddo
  )
if &choice==1  
  (  
  print "resetting NAND Controller"
  ;Hard reset the NAND Controller
  d.set &NAND_FLASH_CMD %LONG 0x0
  wait 100.ms
  )
  
if &choice==2 
  (  
  print "resetting NAND Device"
  ;reset NAND flash device 
  d.set &NAND_FLASH_CMD %LONG 0x7
  wait 100.ms
  )

if &choice==3
  (  
  print "Zero filling NAND Controller buffer"
  ; clear the buffer
  d.set &NAND_BUFFER--&NAND_BUFFER_END 0x0
  )

if &choice==4
  (
    print "Reading Status"
    GOSUB Read_Status "Print_status"
  )
                        
if &choice==5
  (
  print " Please enter page number to be read (the script will add offset and multiply by page size): "
   
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0
                 
  gosub Read_Page &value "Print_status"
  gosub Read_Status "Print_status"
  )

if &choice==6                                                                        
  (
  print " Writing one page of NAND "
  print " Please enter value to be written to all bytes (0xfff to abort): "
   
  &t32_cmm_stopped=1
  enter &subchoice
  &t32_cmm_stopped=0
  
  if &subchoice>0xFF
    (
    print "aborting write -- fill value too large -- enter value 0xFF or below"
    goto Main_Menu 
    ) 
  
  ; fill the buffer
  d.set &NAND_BUFFER--&NAND_BUFFER_END %byte &subchoice
 
  print " Please enter page number to be written (the script will add offset and multiply by page size): "
   
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0
  
  IF &value>0x7FFFF
    (
    print "ERROR: page value entered >256MB, likely >NAND size -- try again"
    goto Main_Menu
    ) 
                 
  &value=&value*0x200
  print "Writing &subchoice to page at relative address &value" 
  ;set address to program
  d.set &NAND_FLASH_ADDR %long &value
  ; command NAND controller to write one page
  d.set &NAND_FLASH_CMD %LONG 0x3
  wait 100.ms
  )

if &choice==7
  (
  print " Please enter block number to erase (the script will add offset and multiply by block size(16k)): "
   
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0
                 
  IF &value>0x3FFF
    (
    print "ERROR: block value entered >256MB, likely >NAND size -- try again"
    goto Main_Menu
    ) 
                 
  &value=&value*0x4000
  print "Erasing block at relative address &value" 
  ;set address to erase
  d.set &NAND_FLASH_ADDR %long &value
  ; erase page
  d.set &NAND_FLASH_CMD %LONG 0x4
  wait 100.ms 
  )

if &choice==8
  (
  print " Writing lowest 16 pages of NAND (8k)"
  print " Please enter value to be written to all bytes (0xFFF to abort): "
   
  &t32_cmm_stopped=1
  enter &subchoice
  &t32_cmm_stopped=0
  
  if &subchoice>0xFF
    (
    print "not performing write -- fill value too large -- enter value 0xFF or below"
    goto Main_Menu 
    ) 
  
  ; fill the buffer
  d.set &NAND_BUFFER--&NAND_BUFFER_END %byte &subchoice
 
  ; write the buffer, one page at a time 
  local &page_Addr
  &page_Addr=0x0
  REPEAT 0x10 
    (
    print "  writing page &page_Addr"
    d.set &NAND_FLASH_ADDR %long &page_Addr
    d.set &NAND_FLASH_CMD %LONG 0x3
    &page_Addr=&page_Addr+0x200
    wait 100.ms
    )
  )
if &choice==10
  (
  print " Surveying NAND config pages..." 
  &value=0x60 // set to first config page
  gosub Survey_Block &value
  )
if &choice==11
  (
  print " Enter page number to read (First config page is 0x60, second is 0x61): "
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0

  IF &value>0x7FFFF
    (
    print "ERROR: page value entered >256MB, likely >NAND size -- try again"
    goto Main_Menu
    ) 
                 
  gosub Read_Page &value "Print_status"
  gosub Read_Status "Print_status"
  
  print " Please select the .txt file to save NAND buffer to:" 
  data.save.binary *.txt &NAND_BUFFER--&NAND_BUFFER_END 
  
  wait 100.ms
  )
if &choice==12
  (
  print " Enter page number to write (First config page is 0x60, second is 0x61): "
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0

  IF &value>0x7FFFF
    (
    print "ERROR: page value entered >256MB, likely >NAND size -- try again"
    goto Main_Menu
    ) 
                 
  ; check to see if the block is erased-- if not, err out.  
  ; read block, then check for 0xffffffff at first word
  gosub Read_Page &value "Print_status"
   &data=data.long(RD:&NAND_BUFFER) 
  IF &data!=0xFFFFFFFF
    (
    ; assume nand flash block is not erased, so don't write it.
    print "ERROR:The page you chose to write is not erased:  Please select another"
    wait 3.s
    goto Main_Menu
    )
                 
  print " Please select the .txt file to program into the NAND config page:" 
  data.load.binary *.txt &NAND_BUFFER--&NAND_BUFFER_END 
  wait 2.s
 
  &value=&value*0x200
  print "Writing buffer to page at relative address &value" 
  ;set address to program
  d.set &NAND_FLASH_ADDR %long &value
  ; command NAND controller to write one page
  d.set &NAND_FLASH_CMD %LONG 0x3
  wait 100.ms
  )
if &choice==20
  (
  print " Please select the .txt file to read into NAND buffer:" 
  data.load.binary *.txt &NAND_BUFFER--&NAND_BUFFER_END 
  
  wait 100.ms
  )

if &choice==21
  (
  print " Please select the .txt file to save NAND buffer to:" 
  data.save.binary *.txt &NAND_BUFFER--&NAND_BUFFER_END 
  
  wait 100.ms
  )
if &choice==22
  (
  print " Please enter block number to survey (the script will add offset and multiply by block size(16k)): "
   
  &t32_cmm_stopped=1
  enter &value
  &t32_cmm_stopped=0
                 
  IF &value>0x3FFF
    (
    print "ERROR: block value entered >256MB, likely >NAND size -- try again"
    goto Main_Menu
    ) 
                 
  &value=&value*0x20  // converting a block address into a page address
  print " Surveying NAND pages &value..." 
  gosub Survey_Block &value
  )

goto Main_Menu


enddo

Read_Page:
  ; reads a nand page
  local &pagenum &errstr &printswitch
  ENTRY &pagenum &printswitch

  if "&printswitch"!=""
    (
    &printswitch=0x1
    )
  ELSE 
    (
    &printswitch=0x0
    )  
  
  &pagenum=&pagenum*0x200
  &errstr="Reading relative address &pagenum" 
  ;set address to read
  d.set &NAND_FLASH_ADDR %long &pagenum
  ; read page
  d.set &NAND_FLASH_CMD %LONG 0x1
  wait 10.ms
  
  IF &printswitch==0x1
    (
    print "&statusstr"
    ) 
  RETURN

Read_Status:
  ; read status
  local &statusstr &printswitch
  ENTRY &printswitch
  if "&printswitch"!=""
    (
    &printswitch=0x1
    )
  ELSE 
    (
    &printswitch=0x0
    )  
  
  d.set &NAND_FLASH_CMD %LONG 0x6
   &status=data.long(RD:&NAND_FLASH_STATUS) 
  &statusstr= "NAND Controller status &status: "
  if &status>0x7FFFFFFF
    (
    &statusstr="&statusstr READ_ERR"
    )
  &masked=&status&0x2000
  if &masked>0x0 
    (
    &statusstr="&statusstr Ctlr_Ready"
    )
  else
    (
    &statusstr="&statusstr Ctlr_BUSY"
    )
  &masked=&status&0x80
  if &masked>0x0 
    (
    &statusstr="&statusstr Failure last page_write or block_erase"
    )
  &masked=&status&0x20
  if &masked>0x0 
    (
    &statusstr="&statusstr Device_Ready"
    )
  else
    (
    &statusstr="&statusstr Device_Busy " 
    ) 
  &masked=&status&0x10
  if &masked>0x0 
    (
    &statusstr="&statusstr Correctable error last read "
    )
  local &op_status
  &op_status=&status&0x7  
  if &op_status==0x0
    (
    &statusstr="&statusstr Status:Idle " 
    )
  if &op_status==0x1
    (
    &statusstr="&statusstr Status:Page_read_ongoing " 
    )
  if &op_status==0x2
    (
    &statusstr="&statusstr Status:flag_read_ongoing " 
    )
  if &op_status==0x3
    (
    &statusstr="&statusstr Status:page_write_ongoing " 
    )
  if &op_status==0x4
    (
    &statusstr="&statusstr Status:page_erase_ongoing " 
    )
  if &op_status==0x5
    (
    &statusstr="&statusstr Status:ID_fetch_ongoing " 
    )
  if &op_status==0x6
    (
    &statusstr="&statusstr Status:status_check_ongoing " 
    )
  if &op_status==0x7
    (
    &statusstr="&statusstr Status:NAND_device_being_reset " 
    )
  
  IF &printswitch==0x1
    (
    print "&statusstr"
    ) 
  RETURN 

;
;
; for the block passed in, this code sees what pages are erased and lets the user
; view data in any page
;
Survey_Block:
  local &pageaddr &addr
  ENTRY &pageaddr
  &statusstr="" 
  &addr=&pageaddr
  ; loop across the entire NAND block 
  REPEAT 0x10 
    (
    gosub Read_Page &addr
     &data=data.long(RD:&NAND_BUFFER) 
    IF &data==0xFFFFFFFF
      (
      ; nand flash page is erased
      &statusstr="&statusstr &addr" 
      )
    &addr=&addr+1
    )  
  print            
  print "The following pages are blank: &statusstr"
  print

  &addr=&pageaddr // reset addr to beginning of block 
  WHILE &addr<0x7FFFF
    (
    gosub Read_Page &addr
    print "Page &addr is shown in data.dump window"
    gosub Read_Status "Print_status"
    print
    print " Enter page number to be read (First config page=0x60). Enter >0x7FFFF to stop: "
    &t32_cmm_stopped=1
    enter &addr
    &t32_cmm_stopped=0
    )  
  RETURN 






⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?