📄 security.psm
字号:
OR s0, s1
auth_write_check2: COMPARE s7, 25
JUMP NZ, auth_write_check3
LOAD s1, sE ;merge upper order nibble for MS-Byte with random
AND s1, F0
AND s0, 0F
OR s0, s1
auth_write_check3: COMPARE s7, 7F
JUMP NZ, auth_write_check4
LOAD s1, sD ;merge lower order nibble for LS-Byte with random
AND s1, 0F
AND s0, F0
OR s0, s1
auth_write_check4: COMPARE s7, FA
JUMP NZ, write_auth
LOAD s1, sE ;merge lower order nibble for MS-Byte with random
AND s1, 0F
AND s0, F0
OR s0, s1
write_auth: CALL SF_single_byte_write ;write byte to FLASH
ADD s7, 01 ;increment address
RETURN Z ;complete after 256 writes
JUMP auth_write_loop
;
;
;**************************************************************************************
; Erase authentication value from StrataFLASH memory.
;**************************************************************************************
;
; Erase block 3 of the StrataFLASH memory which covers the address range 060000 to 07FFFF.
; This erases the area containing the authentication value and random values which helps
; to hide it.
;
erase_authentication: LOAD s9, 06 ;set address to 06xxxx hex which defines block 3 (060000 to 07FFFF)
CALL SF_erase_block
RETURN
;
;
;**************************************************************************************
; Initialise the StrataFlash Memory control signals.
;**************************************************************************************
;
; SF_read = 0 - Output enable off
; SF_ce = 1 - Deselect StrataFLASH memory
; SF_we = 1 - Write enable off
;
; Register used s0
;
SF_init: LOAD s0, 06
OUTPUT s0, SF_control_port
RETURN
;
;
;
;**************************************************************************************
; StrataFLASH Block Erase
;**************************************************************************************
;
; This routine will erase one 128k-byte block of the StrataFLASH memory.
; The block to be erased is specified by the contents of register 's9'.
;
; s9=06 erases Block 3 (address range 060000 to 07FFFF)
;
;
; To erase a block the 24-bit address must be set and then the block erase command
; (20 hex) written to the memory followed by the write confirm command (D0 hex).
;
; The act of erasing a block may take up to 1 second to complete. This routine
; waits for the memory to be ready before restoring the normal read array mode and
; returning.
;
; Registers used s0,s1,s7,s8,s9
;
SF_erase_block: LOAD s8, 00 ;define lower address of block = xx0000
LOAD s7, 00
LOAD s1, 20 ;block erase command
CALL SF_byte_write
LOAD s1, D0 ;write confirm command
CALL SF_byte_write
CALL wait_SF_ready ;wait for erase to complete
RETURN
;
;
;**************************************************************************************
; Write a single byte to StrataFlash Memory
;**************************************************************************************
;
; To write a single byte to StrataFLASH memory the address must be set and the
; single-word/byte program command (40 hex) sent to the memory. Then the data byte can
; be written to the memory using the same address.
;
; The 24-bit address should be supplied in register set [s9,s8,s7].
; Register s0 should contain the byte data to be written to the memory.
;
; The act of writing the memory array may take up to 175us to complete. This routine
; waits for the memory to be ready before restoring the normal read array mode and
; returning.
;
; Registers used s0,s1,s7,s8,s9 (s7,s8,s9 not changed)
;
; Registers used s0,s1,s7,s8,s9
;
SF_single_byte_write: LOAD s1, 40 ;command for single byte program
CALL SF_byte_write
LOAD s1, s0 ;write data to be programmed
CALL SF_byte_write
CALL wait_SF_ready ;wait for program to complete
RETURN
;
;
;
;**************************************************************************************
; Read the unique 64-bit serial number of the StrataFLASH FLASH memory
;**************************************************************************************
;
; To read the device information the Read device information command (90)
; must be written to the memory. The information is read back from address 000102
; to 000109 (note these are byte access addresses).
;
; The serial number is copied to 8 ascending scratch pad memory locations called
; 'serial_number0' through to 'serial_number7' for future use.
;
; After reading the device information the read array command is written to the
; device to put it back to normal read mode.
;
; Registers used s0,s1,s2,s7,s8,s9
;
read_SF_serial_number: LOAD s9, 00 ;StrataFLASH address to read serial number = 000102
LOAD s8, 01
LOAD s7, 02
LOAD s2, serial_number0 ;pointer to scratch pad memory
LOAD s1, 90 ;command to read device information
CALL SF_byte_write
read_SN_loop: CALL SF_byte_read ;read serial number value
STORE s0, (s2)
COMPARE s2, serial_number7 ;check for 8 bytes copied
JUMP Z, end_read_SN
ADD s7, 01 ;increment StrataFLASH address
ADD s2, 01 ;increment memory pointer
JUMP read_SN_loop
;
end_read_SN: CALL set_SF_read_array_mode ;restore normal read array mode
RETURN
;
;
;
;**************************************************************************************
; Read a byte from StrataFlash Memory
;**************************************************************************************
;
; The 24-bit address should be supplied in register set [s9,s8,s7].
; Register s0 will return the byte data retrieved from the memory.
;
; To read a byte, the address needs to be set up on the address lines
; and the controls set as follows
; SF_read = 1 - disable Spartan data outputs and enable StrataFlash outputs (OE=0)
; SF_ce = 0 - enable StrataFLASH memory
; SF_we = 1 - Write enable off
;
; The access time of the memory is 75ns. This is equivalent to 3.75 clock cycles at
; 50MHz. Since each KCPSM3 instruction takes 2 clock cycles to execute, two instructions
; provides adequate delay for the memory to be accessed.
;
; Registers used s0,s1,s7,s8,s9
;
SF_byte_read: OUTPUT s9, SF_addr_hi_port ;set 24-bit address
OUTPUT s8, SF_addr_mi_port
OUTPUT s7, SF_addr_lo_port
LOAD s1, 05 ;set controls
OUTPUT s1, SF_control_port
LOAD s1, 06 ;>75ns delay
LOAD s1, 06 ;but do something useful!
INPUT s0, SF_data_in_port ;read data byte
OUTPUT s1, SF_control_port ;clear controls
RETURN
;
;
;**************************************************************************************
; Write data or command byte to StrataFlash Memory
;**************************************************************************************
;
; The 24-bit address should be supplied in register set [s9,s8,s7].
; Register s1 should contain the byte to be written to the memory.
;
; To write a byte, the address needs to be set up on the address lines
; and the controls set as follows
; SF_read = 0 - enable Spartan data outputs and disable StrataFlash outputs (OE=1)
; SF_ce = 0 - enable StrataFLASH memory
; SF_we = 0 - Write enable on
;
; The setup time of the memory is 60ns. This is equivalent to 3 clock cycles at
; 50MHz. Since each KCPSM3 instruction takes 2 clo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -