⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f_intel_arm.s

📁 realview22.rar
💻 S
字号:
; ============================================================================
; F_INTEL_ARM - Flash programming algorithm for Intel Flash (Boot block style)
;
; Library Name: Included into container .s file.
;
; Module Name:  F_INTEL_ARM.S
; Module Descr: Flash programming for Intel Boot block Flash
; Creation Date:1998
; Author:       Paul Kimelman
;
; THIS INFORMATION IS PROPRIETARY TO
; ALLANT SOFTWARE, INC.
; 1280 Civic Drive, Suite 206
; Walnut Creek, CA 94596
; USA
; ----------------------------------------------------------------------
; Copyright (c) 1998-2000  Allant Software, Inc.
; ALL RIGHTS RESERVED;
;
; Revisions of F_INTEL_ARM.S: (latest revision on top)
; #.#  Name  Date      Description
; ---  ----- --------  -----------------------------------------------------
; 2.0  Paul  04/00     Ported to ARM asm (from TI asm).
; $Revision: 1.1.6.1 $
;
; Implementation notes:
;
; GENERAL
; -------
;
;       This file is to be included into another asm file which has the
; board/chip specific knowledge needed for initialization and the like.
; That is, this is the algorithm only.
;
;       This file is based on information on Intel Boot block flash 
; of various forms. It is generalized to handle x8 and x16 accesses.
; It does not need to know the block sizes or positions as that is all
; passed in. 
;
;       This uses the standard RVDEBUG implementation for an API. That
; means that registers are used for passing arguments and returning
; status. The registers used are based on the save/restore list. The
; first registers are assumed to be the ones to use for passing args.
; In the case of ARM, this is R0, R1, R2, R3, etc.
;
; REGISTER MODEL
; --------------
;
;       The register model for this routine is as follows:
;       R0:     Input: page of Flash (not used on ARM)
;               Output:status return to host
;       R1:     Input: base address of Flash block to operate on
;       R2/R3/R4/R5/R8/R9: Input: arguments
;               Typical meanings: R2=Counter
;       R6/R7:Scratch
;
; -----------------------------------------------------------------------------
; Description:
; ----------------------------------------------------------------------------
;                               NOTICE
;
;       This code is proprietary and secret; the use of this source is
; restricted, and all rights are reserved.
;
;       If reading for interest, enjoy.
;
;       If maintaining, read comments carefully! There are some inter-depen-
; dencies and connectivities. Areas with particular connection are marked.
; There are some variable protocols that are not self evident: check all uses
; of variables before making big changes.
; ============================================================================
;

;************************************************************************/
;* DEFINE ENTRY POINTS                                                  */
;************************************************************************/

;       EXPORT          FLASH_init      // provided by asm that includes us
;       EXPORT          FLASH_erase_all // not available
        EXPORT          FLASH_erase
        EXPORT          FLASH_write_erase
        EXPORT          FLASH_write
        EXPORT          FLASH_validate
        EXPORT          FLASH_break
;       EXPORT          FLASH_term      // we do not need one

;************************************************************************/
;* DEFINE MACROS AND EQUATES                                            */
;************************************************************************/

        IF              WIDTH=1
          MACRO
           STORE        $p1,$p2,$p3
            IF "$p3" = ""
             strb       $p1,$p2
            ELSE
             strb       $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3
            IF "$p3" = ""
             ldrb       $p1,$p2
            ELSE
             ldrb       $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF              WIDTH=2
          MACRO
           STORE        $p1,$p2,$p3=0
            IF "$p3" = ""
             strh       $p1,$p2
            ELSE
             strh       $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3=0
            IF "$p3" = ""
             ldrh       $p1,$p2
            ELSE
             ldrh       $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF              WIDTH=4
          MACRO
           STORE        $p1,$p2,$p3=0
            IF "$p3" = ""
             str        $p1,$p2
            ELSE
             str        $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3=0
            IF "$p3" = ""
             ldr        $p1,$p2
            ELSE
             ldr        $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF :DEF: P_WIDTH
          IF P_WIDTH > 1
            MACRO
              EXPAND    $p1
                add $p1, $p1, $p1, lsl #16
                IF P_WIDTH=4
                  add $p1, $p1, $p1, lsl #8
                ENDIF
            MEND
          ENDIF
        ELSE
          MACRO
            EXPAND      $p1
          MEND
        ENDIF

;************************************************************************/
;* THE GLOBAL FUNCTIONS (EXPORTED PUBLICLY)                             */
;************************************************************************/
 
;* -----------------------------------------------------------------------
;  FLASH_erase - erase a Flash block
;
;  Notes:
;     - this erases a Flash block on request from host. The host has
;       the information on which end has the boot block and its size,
;       so we do not need to worry about that. 
;     - we may be asked to erase one or a set of blocks, but all will
;       have the same size.
;
;  Input/Output:
;     - In: R1=Base of 1st Flash Block to erase
;           R0=Page of Flash (no meaning for ARM)
;           R2=Count of blocks to do
;           R3=Size of blocks (for iterate)
;     - Out:R0=status code (0=OK, else error)
;     - Scratch: R6,R7
;  ----------------------------------------------------------------------- */

FLASH_erase
        bl      erase_block     ; erase block in R1
        bne     flash_exit      ; failed on this one

        subs    R2,R2,#1        ; count down
        addne   R1,R1,R4        ; setup for next block if more
        bne     FLASH_erase     ; more to do
        b       flash_exit      ; Stop routine on breakpoint

;* -----------------------------------------------------------------------
;  FLASH_write - write to a Flash block
;  FLASH_write_erase - erase then write
;
;  Notes:
;     - this writes a buffer into a flash block. The caller is responsible
;       for pre-erasing if needed.
;     - note: this is writing half-words and not bytes
;     - the host knows about block sizes and all, and passes in the needed
;       info.
;     - if we are writing into a later part of the block, this will be
;       handled by the host.
;
;  Input/Output:
;     - In: R1=Base of Flash Block to write
;           R0=Page of Flash (no meaning for ARM)
;           R2=Count of bytes to copy
;           R4=Offset in block to copy into (from base)
;           R5=Address of buffer to copy from
;           R8=Page of buffer (no meaning for ARM)
;           R9=0 if no verify, else same value as R2 (count)
;     - Out:R0=status code (0=OK, else error)
;     - Scratch: R6,R7
;  ----------------------------------------------------------------------- */

FLASH_write_erase
        bl      erase_block     ; erase block in R1
        bne     flash_exit      ; failed on this one
FLASH_write
        add     R4,R4,R1        ; compute start address
        mov     R6,#0x40        ; program initiate msg
        EXPAND  R6

write_loop
        LOAD    R7,[R5],#WIDTH  ; load first value from buffer then inc
        STORE   R6,[R4]         ; program initiate
        STORE   R7,[R4],#WIDTH  ; write value desired then inc
        bl      wait_for_ready  ; wait for Flash to finish write

        subs    R2,R2,#WIDTH    ; decrement count, more?
        bgt     write_loop      ; yes, continue

        bl      check_status    ; check Flash status and return in R0

        cmp     R9,#0           ; want verify?
        beq     done_write      ; no, just quit

        cmp     R0,#0           ; write went ok?
        bne     done_write      ; no, just quit

        mov     R7,#0xFF        ; set to read mode
        EXPAND  R7
        STORE   R7,[R1]         ; write to Flash
        mov     R2,R9           ; reset count
        sub     R4,R4,R2        ; back up to start of block to verify
        sub     R5,R5,R2        ; back up to start of buffer to verify
        b       FLASH_validate  ; go on to validate code

done_write
        b       flash_exit      ; Stop routine on breakpoint

;* -----------------------------------------------------------------------
;  FLASH_validate - validate write to a Flash block
;
;  Notes:
;     - this compares a buffer and a flash block. The caller uses this
;       after a write to verify the write worked.
;     - the host knows about block sizes and all, and passes in the needed
;       info.
;
;  Input/Output:
;     - In: R1=Base of Flash block to verify
;           R0=Page of Flash (no meaning for ARM)
;           R2=Count of bytes to verify
;           R4=Offset in block to verify from
;           R5=Address of buffer to verify against
;           R8=Page of buffer (no meaning for ARM)
;     - Out:R0=status code (0=OK, else error)
;     - Scratch: R6,R7
;  ----------------------------------------------------------------------- */

FLASH_validate
        mov     R6,#0
        mov     R7,#0
validate_loop
        LOAD    R7,[R5],#WIDTH  ; load value from buffer
        LOAD    R6,[R4],#WIDTH  ; load value from Flash
        cmp     R6,R7           ; same?
        bne     bad_validate    ; no, failed

        subs    R2,R2,#WIDTH    ; decrement count, more?
        bgt     validate_loop   ; yes, continue

        bl      check_status    ; check Flash status and return in R0

        b       flash_exit      ; Stop routine on breakpoint
        
bad_validate
        mov     R0,#1           ; compare
        b       flash_exit      ; Stop routine on breakpoint

;* -----------------------------------------------------------------------
;  FLASH_break - end of function entry for all Flash routines
;
;  Notes:
;     - this routine is the Stop routine for the flash code. It runs over
;       what should be a break (set by host). If the host messes up, it
;       will loop forever allowing the host to halt it.
;
;  Input/Output:
;     - In: R0=status code to return (0=OK, else error)
;           R1=base of Flash block operated on
;   ----------------------------------------------------------------------- */

Local_init                      ; we have no local init
flash_exit
        mov     R7,#0xFF        ; set to read mode
        EXPAND  R7
        STORE   R7,[R1]         ; write to Flash
FLASH_break
        nop                     ; place to put breakpoint from host
forever
        b       forever         ; in case host screws up

;************************************************************************/
;* STATIC FUNCTIONS                                                     */
;************************************************************************/

;* -----------------------------------------------------------------------
;  erase_block - erase a block of the flash and check if OK
;
;  Notes:
;     - this handles erase of a Flash block and returns status in R0
;       as well as the Z flag
;
;  Input/Output:
;     - In: R1=Base of Flash
;     - Out:R0=Status (0=OK, else failed)
;     - Scratch: R0,R6
;  ----------------------------------------------------------------------- */

erase_block
        mov     R6,#0x20        ; erase setup msg
        EXPAND  R6
        STORE   R6,[R1]         ; ask to Flash erase
        mov     R6,#0xD0        ; erase confirmation msg
        EXPAND  R6
        STORE   R6,[R1]         ; confirm we want to erase
        mov     R6,R14          ; save link for call below
        bl      wait_for_ready  ; wait for erase to finish
        bl      check_status    ; check Flash status and return in R0
        mov     R15,R6          ; Return with code in R0 and Z bit

;* -----------------------------------------------------------------------
;  check_status - check to see if operation completed OK.
;
;  Notes:
;     - this reads the error status of the Flash and returns in R0.
;
;  Input/Output:
;     - In: R1=Base of Flash
;     - Out:R0=Status (0=OK, else failed)
;     - Scratch: R7
;  ----------------------------------------------------------------------- */

check_status
        mov     R0,#0x70        ; read status request
        EXPAND  R0
        STORE   R0,[R1]         ; write to Flash base
        LOAD    R0,[R1]         ; read back results

        mov     R7,#0x78
        EXPAND  R7
        ands    R0,R0,R7        ; mask for errors
        mov     R15,R14         ; Return with code in R0

;* -----------------------------------------------------------------------
;  wait_for_ready - wait for Flash to complete an operation.
;
;  Notes:
;     - this reads the status of the Flash until done.
;
;  Input/Output:
;     - In: R1=Base of Flash
;     - Scratch: R0,R7
;  ----------------------------------------------------------------------- */

wait_for_ready
        mov     R0,#0x70        ; read status request
        EXPAND  R0
        STORE   R0,[R1]         ; write to Flash base
        LOAD    R0,[R1]         ; read back results

        mov     R7,#0x80
        EXPAND  R7
        cmp     R0,R7           ; read back as 0x80 means OK
        bne     wait_for_ready  ; no, wait some more
        mov     R15,R14         ; Return

        END

⌨️ 快捷键说明

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