[openfirmware] [commit] r3073 - in cpu/arm/mmp3: . thunderstone thunderstone/build
repository service
svn at openfirmware.info
Wed Jul 18 23:55:07 CEST 2012
Author: wmb
Date: Wed Jul 18 23:55:07 2012
New Revision: 3073
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3073
Log:
Initial revision of test build for Marvell Thunderstone MMP3 reference board.
Added:
cpu/arm/mmp3/
cpu/arm/mmp3/initmmu.fth
cpu/arm/mmp3/numdot.fth
cpu/arm/mmp3/resetvec.fth
cpu/arm/mmp3/thunderstone/
cpu/arm/mmp3/thunderstone/addrs.fth
cpu/arm/mmp3/thunderstone/boardgpio.fth
cpu/arm/mmp3/thunderstone/boardtwsi.fth
cpu/arm/mmp3/thunderstone/build/
cpu/arm/mmp3/thunderstone/build/Makefile
cpu/arm/mmp3/thunderstone/config.fth
cpu/arm/mmp3/thunderstone/fw-version.fth
cpu/arm/mmp3/thunderstone/fw.bth
cpu/arm/mmp3/thunderstone/ofw.bth
cpu/arm/mmp3/thunderstone/prefw.bth
cpu/arm/mmp3/thunderstone/resetvec.bth
cpu/arm/mmp3/thunderstone/sdhci.fth
cpu/arm/mmp3/thunderstone/usb.fth
Added: cpu/arm/mmp3/initmmu.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/initmmu.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,366 @@
+\ See license at end of file
+purpose: Setup the initial virtual address map
+
+[ifdef] notdef
+\ Synchronizes the instruction and data caches over the indicated
+\ address range, thus allowing the execution of instructions that
+\ have recently been written to memory.
+label sync-cache-range \ r0: adr, r1: len
+ begin
+ mcr p15, 0, r0, cr7, cr10, 1 \ clean D$ line
+ mcr p15, 0, r0, cr7, cr5, 1 \ invalidate I$ line
+ add r0, r0, #32 \ Advance to next line
+ subs r1, r1, #32
+ 0<= until
+ mov pc, lr
+end-code
+
+\ Forces data in the cache within the indicated address range
+\ into memory.
+label clean-dcache-range \ r0: adr, r1: len
+ begin
+ mcr p15, 0, r0, cr7, cr10, 1 \ clean D$ line
+ add r0, r0, #32 \ Advance to next line
+ subs r1, r1, #32
+ 0<= until
+ mov pc, lr
+end-code
+[then]
+
+\ Turn on the caches
+label caches-on
+
+ \ Invalidate the entire L1 data cache by looping over all sets and ways
+ mov r0,#0 \ Start with set/way 0 of L1 cache
+ begin
+ \ In this unrolled loop, the number of iterations (8) and the increment
+ \ value (0x20000000) depend on fact that this cache has 8 ways.
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way - will wrap to 0
+
+ inc r0,#32 \ Next set
+ ands r1,r0,#0xfe0 \ Mask set bits - depends on #sets=128
+ 0= until
+
+ \ Invalidate the entire L2 cache by looping over all sets and ways
+ mov r0,#2 \ Start with set/way 0 of L2 cache
+ begin
+ \ In this unrolled loop, the number of iterations (8) and the increment
+ \ value (0x20000000) depend on fact that this cache has 8 ways.
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr6, 2 \ Invalidate D$ line by set/index
+ inc r0,#0x20000000 \ Next way - will wrap to 0
+
+ inc r0,#32 \ Next set
+ set r2,#0x1ffe0 \ Mask for set field for L2 cache - depends on #sets=4096
+ ands r1,r0,r2 \ Mask set bits
+ 0= until
+
+ mcr p15, 0, r0, cr7, cr5, 0 \ Invalidate entire I$
+
+ mcr p15, 0, r0, cr7, cr5, 6 \ Flush branch target cache
+
+ mrc p15,0,r0,cr1,cr0,0 \ Read control register
+ orr r0,r0,#0x1000 \ ICache on
+ orr r0,r0,#0x0800 \ Branch prediction on
+ orr r0,r0,#0x0004 \ DCache on
+ mcr p15,0,r0,cr1,cr0,0 \ Write control register with new bits
+
+ mrc p15,0,r0,cr1,cr0,1 \ Read aux control register
+ orr r0,r0,#0x0002 \ L2 Cache on
+ mcr p15,0,r0,cr1,cr0,1 \ Write control register with new bits
+
+ mov pc, lr
+end-code
+
+\ Synchronizes the instruction and data caches, thus allowing the
+\ execution of instructions that have recently been written to memory.
+\ This version, which operates on the entire cache, is more efficient
+\ than an address-range version when the range is larger than the
+\ L1 cache size.
+label sync-caches \ No args or returns, kills r0 and r1
+
+ \ Clean (push the data out to a higher level) the entire L1 data cache
+ \ by looping over all sets and ways
+ mov r0,#0 \ Start with set/way 0 of L1 cache
+ begin
+ \ In this unrolled loop, the number of iterations (8) and the increment
+ \ value (0x20000000) depend on fact that this cache has 8 ways.
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way
+ mcr p15, 0, r0, cr7, cr10, 2 \ clean D$ line by set/index
+ inc r0,#0x20000000 \ Next way - will wrap to 0
+
+ inc r0,#32 \ Next set
+ ands r1,r0,#0xfe0 \ Mask set bits - depends on #sets=128
+ 0= until
+
+ mcr p15, 0, r0, cr7, cr5, 0 \ Invalidate entire I$
+ mov pc, lr
+end-code
+
+\ Insert zeros into the code stream until a cache line boundary is reached
+\ This must be enclosed with "ahead .. then" to branch around the zeros.
+: cache-align ( -- )
+ begin
+ here [ also assembler ] asm-base [ previous ] - h# 1f and
+ while
+ 0 l,
+ repeat
+;
+
+\ Turn on the MMU
+label enable-mmu ( -- )
+ mvn r2, #0 \ Set domains for Manager access - all domains su
+ mcr p15,0,r2,3,0,0 \ Update register 3 in CP15 - domain access control
+
+ \ Enable the MMU
+ mrc p15, 0, r2, 1, 0, 0 \ Read current settings in control reg
+ mov r2, r2, LSL #18 \ Upper 18-bits must be written as zero,
+ mov r2, r2, LSR #18 \ ... clear them now.
+
+ orr r2, r2, 0x200 \ Set the ROM Protection bit
+ bic r2, r2, 0x100 \ Clear the System Protection bit
+ orr r2, r2, 0x001 \ Set the MMU bit
+
+ \ Align following code to a cache line boundary
+ ahead
+ cache-align
+ then
+
+ mcr p15, 0, r2, cr1, cr0, 0 \ Go Virtual
+ mrc p15, 0, r2, cr2, cr0, 0 \ Ensure that the write completes
+ mov r2, r2 \ before continuing
+ sub pc, pc, #4
+
+ mov pc, lr
+end-code
+
+\ Map sections within the given address range, using
+\ the given protection/cacheability mode. pt-adr is the page table base address.
+label map-sections ( r0: pt-adr, r1: padr, r2: len, r3: mode r4: vadr -- )
+ add r1, r1, r3 \ PA+mode
+ begin
+ str r1, [r0, r4, lsr #18]
+
+ inc r1, #0x100000
+ inc r4, #0x100000
+ decs r2, #0x100000
+ 0<= until
+
+ mov pc, lr
+end-code
+
+\ Map sections virtual=physical within the given address range, using
+\ the given protection/cacheability mode. pt-adr is the page table base address.
+label map-sections-v=p ( r0: pt-adr, r1: adr, r2: len, r3: mode -- )
+ begin
+ add r4, r1, r3 \ PA+mode
+ str r4, [r0, r1, lsr #18]
+
+ inc r1, #0x100000
+ decs r2, #0x100000
+ 0<= until
+
+ mov pc, lr
+end-code
+
+\ Map sections within the given address range, using
+\ the given protection/cacheability mode. pt-adr is the page table base address.
+label allocate-and-map-sections ( r0: pt-adr, r1: padr-top, r2: len, r3: mode r4: vadr -- r1: padr-bot )
+ inc r4, r2 \ vadr-top
+ add r1, r1, r3 \ PA+mode
+ begin
+ dec r1, #0x100000
+ dec r4, #0x100000
+
+ str r1, [r0, r4, lsr #18]
+
+ decs r2, #0x100000
+ 0<= until
+
+ mov r1,r1,lsr #20 \ Clear out mode bits in padr
+ mov r1,r1,lsl #20
+
+ mov pc, lr
+end-code
+
+\ This assumes that there are no holes and that unused MMAP registers have CS_VALID=0
+label dramsize ( -- r0: size-in-bytes )
+ mov r0,0
+ mov r1,0xd0000000 \ Memory controller base address
+
+ ldr r2,[r1,#0x10] \ MMAP0 register
+ ands r3,r2,#1 \ Test CS_VALID
+ movne r3,#0x10000 \ Scale factor for memory size
+ movne r2,r2,lsl #11 \ Clear high bits above AREA_LENGTH field
+ movne r2,r2,lsr #27 \ Move AREA_LENGTH to LSB
+ addne r0,r0,r3,lsl r2 \ Compute bank size and add to accumulator
+
+ ldr r2,[r1,#0x14] \ MMAP1 register
+ ands r3,r2,#1 \ Test CS_VALID
+ movne r3,#0x10000 \ Scale factor for memory size
+ movne r2,r2,lsl #11 \ Clear high bits above AREA_LENGTH field
+ movne r2,r2,lsr #27 \ Move AREA_LENGTH to LSB
+ addne r0,r0,r3,lsl r2 \ Compute bank size and add to accumulator
+
+ add r1,r1,#0x10000 \ Memory controller base address d0010000
+
+ ldr r2,[r1,#0x10] \ MMAP0 register
+ ands r3,r2,#1 \ Test CS_VALID
+ movne r3,#0x10000 \ Scale factor for memory size
+ movne r2,r2,lsl #11 \ Clear high bits above AREA_LENGTH field
+ movne r2,r2,lsr #27 \ Move AREA_LENGTH to LSB
+ addne r0,r0,r3,lsl r2 \ Compute bank size and add to accumulator
+
+ ldr r2,[r1,#0x14] \ MMAP1 register
+ ands r3,r2,#1 \ Test CS_VALID
+ movne r3,#0x10000 \ Scale factor for memory size
+ movne r2,r2,lsl #11 \ Clear high bits above AREA_LENGTH field
+ movne r2,r2,lsr #27 \ Move AREA_LENGTH to LSB
+ addne r0,r0,r3,lsl r2 \ Compute bank size and add to accumulator
+
+ mov pc,lr
+end-code
+
+\ Initial the section table, setting up mappings for the platform-specific
+\ address ranges that the firmware uses.
+\ Destroys: r0-r4
+label init-map ( -- )
+ mov r10,lr
+
+ bl `dramsize` \ r0: total-memory-size
+ mov r1,r0 \ r1: allocation pointer starts at top of DRAM
+
+ \ Locate the page table at the top of the firmware memory, just below the frame buffer
+ dec r0,`/fb-mem #` \ Size of frame buffer
+ dec r0,`/page-table #` \ r0: page-table-pa
+
+ mcr p15,0,r0,cr2,cr0,0 \ Set table base address
+
+ \ Clear the entire section table for starters
+ mov r2, #0x1000 \ Section#
+ mov r3, #0 \ Invalid section entry
+ begin
+ subs r2, r2, #1 \ Decrement section number
+ str r3, [r0, r2, lsl #2] \ Invalidate section entry
+ 0= until
+ \ r1: top of DRAM
+ set r2,`/fb-mem #` \ Size of frame buffer
+ set r3,#0xc06 \ Write bufferable
+ set r4,`fb-mem-va #` \ Virtual address
+ bl `allocate-and-map-sections \ r1: bottom PA of frame buffer
+
+ set r2,`/fw-mem #` \ Size of firmware region
+ set r3,#0xc0e \ Write bufferable
+ set r4,`fw-mem-va #` \ Virtual address
+ bl `allocate-and-map-sections` \ r1: bottom PA of firmware memory
+
+ set r2,`/extra-mem #` \ Size of additional allocatable memory
+ set r3,#0xc0e \ Write bufferable
+ set r4,`extra-mem-va #' \ Virtual address
+ bl `allocate-and-map-sections` \ r1: bottom PA of extra memory
+
+ set r2,`/dma-mem #` \ Size of DMA area
+ set r3,#0xc02 \ No caching or write buffering
+ set r4,`dma-mem-va #` \ Virtual address
+ bl `allocate-and-map-sections` \ r1: bottom PA of DMA memory
+
+ mov r2,r1 \ Size of low memory
+ set r3,#0xc0e \ Cache and write bufferable
+ mov r4,#0 \ Virtual address
+ bl `allocate-and-map-sections` \ r1: 0
+
+ \ Now we have mapped all of DRAM
+ set r1,`sram-pa #` \ Address of SRAM
+ set r2,`/sram #` \ Size of SRAM
+ set r3,#0xc02 \ No caching or write buffering
+ bl `map-sections-v=p`
+
+ set r1,`io-pa #` \ Address of I/O
+ set r2,`/io #` \ Size of I/O region
+ set r3,#0xc02 \ No caching or write buffering
+ bl `map-sections-v=p`
+
+ set r1,`audio-sram-pa #` \ Address of Audio SRAM
+ set r2,`/audio-sram #` \ Size of audio SRAM
+ set r3,#0xc02 \ No caching or write buffering
+ bl `map-sections-v=p`
+
+ set r1,`io-pa #` \ Address of I/O
+ set r2,`/io #` \ Size of I/O region
+ set r3,#0xc02 \ No caching or write buffering
+ set r4,`io-va #` \ Virtual address
+ bl `map-sections`
+
+ set r1,`io2-pa #` \ Address of I/O
+ set r2,`/io2 #` \ Size of I/O region
+ set r3,#0xc02 \ No caching or write buffering
+ set r4,`io2-va #` \ Virtual address
+ bl `map-sections`
+
+ mov pc, r10
+end-code
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2011 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Added: cpu/arm/mmp3/numdot.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/numdot.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,3 @@
+label puthex ( r0: nn \ kills: r1-r3 )
+ mov pc,lr
+end-code
Added: cpu/arm/mmp3/resetvec.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/resetvec.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,279 @@
+\ See license at end of file
+purpose: Low-level startup code
+
+\ create debug-reset
+
+\needs start-assembling fload ${BP}/cpu/arm/asmtools.fth
+\needs write-dropin fload ${BP}/forth/lib/mkdropin.fth
+
+hex
+
+also forth definitions
+: c$, ( adr len -- )
+ 1+ here swap note-string dup allot move 4 (align)
+;
+previous definitions
+
+also arm-assembler definitions
+: $find-dropin, ( adr len -- )
+ 2>r
+ " mov r0,pc" evaluate \ Get address of string
+ " ahead" evaluate \ Skip string
+ 2r> c$, \ Place string
+ " then" evaluate
+ " bl `find-dropin`" evaluate \ and call find routine
+;
+previous definitions
+
+\ /fw-mem constant stack-offset \ Offset of top of inflater stack within destination RAM
+stack-offset h# 2.0000 - constant workspace-offset \ Offset of inflater workspace within destination RAM
+
+start-assembling
+
+label my-entry
+\ **** This is the primary entry point; it will contain a branch instruction
+\ that skips a few subroutines and lands at the startup sequence. That
+\ branch instruction is patched in below.
+ 0 , \ To be patched later
+end-code
+
+fload ${BP}/cpu/arm/mmp3/numdot.fth
+
+\ This subroutine is used by the startup code.
+\ It compares two null-terminated strings, returning zero if they match.
+\ Destroys: r2, r3
+label strcmp ( r0: str1 r1: str2 -- r0: 0 if match, nonzero if mismatch )
+ begin
+ ldrb r2,[r0],#1
+ ldrb r3,[r1],#1
+ cmp r2,r3
+ <> if
+ sub r0,r3,r2
+ mov pc,lr
+ then
+
+ cmp r2,#0
+ = until
+ mov r0,#0
+ mov pc,lr
+end-code
+
+\ This subroutine is used by the startup code.
+\ It searches the ROM for a dropin module whose name field matches the
+\ null-terminated string that is passed in r0.
+\ Destroys: r1-6
+label find-dropin ( r0: module-name-ptr -- r0: address|-1 )
+ mov r6,lr \ r6: return address
+ mov r5,r0 \ r5: module name
+
+ \ Compute address of first dropin (the one containing this code)
+\ sub r4,pc,`here asm-base - h# 20 + 8 + #` \ r4: module pointer
+ set r4,`'dropins #`
+
+ begin
+ ldr r1,[r4]
+ set r2,#0x444d424f \ 'OBMD' in little-endian
+ cmp r1,r2
+ = while
+ mov r0,r5
+ add r1,r4,#16
+ bl `strcmp`
+ cmp r0,#0
+ = if \ It the strings match, we found the dropin
+ mov r0,r4
+ mov pc,r6
+ then
+ ldr r0,[r4,#4] \ Length of dropin image
+ eor r1,r0,r0, ror #16 \ Byte reverse r0
+ bic r1,r1,#0xff0000 \ using the tricky sequence
+ mov r0,r0,ror #8 \ shown in the ARM Programming Techniques
+ eor r0,r0,r1,lsr #8 \ manual
+
+ add r0,r0,r4 \ Added to base address of previous dropin
+ add r0,r0,#35 \ Plus length of header (32) + roundup (3)
+ bic r4,r0,#3 \ Aligned to 4-byte boundary = new dropin addr
+ repeat
+
+ mvn r0,#0 \ No more dropins; return -1 to indicate failure
+ mov pc,r6
+end-code
+
+\ This subroutine is used by the startup code.
+\ It copies n (r2) bytes of memory from src (r1) to dst (r0)
+\ Destroys: r0-r3
+label memcpy ( r0: dst r1: src r2: n -- r0: dst )
+ ahead begin
+ ldr r3,[r1],#4
+ str r3,[r0],#4
+ but then
+ subs r2,r2,#4
+ 0< until
+
+ mov pc,lr
+end-code
+
+\ Load some additional subroutines that are used by the startup code
+fload ${BP}/cpu/arm/mmp3/initmmu.fth \ Setup the initial virtual address map
+
+\ **** This is the main-line code for the initial startup sequence.
+\ It is reached from a branch instruction (which will be patched in later)
+\ at the beginning of this module.
+
+label startup
+
+\ Place a branch instruction to this location at the entry address
+\ (i.e. the beginning) of this module
+here my-entry put-branch
+
+[ifdef] notdef
+ \ Locate and execute the dropin module named "start".
+ \ That module's job is to initialize the core logic and memory controller
+ \ at least to the point that memory works, and to size the memory.
+ \ It returns in r0 the physical address just past the end of the last
+ \ bank of memory. Near the beginning of the last megabyte of memory,
+ \ it stores bitmasks describing which memory banks are populated.
+
+ " start" $find-dropin, \ Assemble call to find-dropin with literal arg
+
+ add r0,r0,#32 \ Skip dropin header
+ mov lr,pc \ Set return address
+ mov pc,r0 \ Execute the dropin
+[then]
+
+ mov r0,#0x10
+ bl `puthex`
+
+ \ Setup the page (section) table and turn on the MMU and caches
+\ set r0,`page-table-pa #`
+ bl `init-map` \ Setup the initial virtual address map
+ bl `enable-mmu` \ Turn on the MMU
+ bl `caches-on` \ Turn on the caches
+
+ mov r0,#0x11
+ bl `puthex`
+
+ \ Now we are running with the MMU and caches on, thus going faster
+
+ \ Locate the dropin module named "firmware".
+
+ " firmware" $find-dropin, \ Assemble call to find-dropin with literal arg
+
+ ldr r1,[r0,#12] \ Get the module's "expanded size" field,
+ cmp r1,#0 \ which will be non0 if the module's compressed
+ <> if
+ \ The firmware dropin is compressed, so we find the inflater
+ \ and use it to inflate the firmware into RAM
+ mov r11,r0 \ Save address of firmware dropin
+
+ mov r0,#0x12
+ bl `puthex`
+
+ \ Locate the "inflate" module.
+ " inflate" $find-dropin, \ Assemble call to find-dropin with literal arg
+
+ add r4,r0,#32 \ r1: Base address of inflater code
+
+ mov r0,#0x13
+ bl `puthex`
+
+ \ Execute the inflater, giving it the address of the compressed firmware
+ \ module, the address where the inflated firmware should be placed, and
+ \ the address of some RAM the inflater can use for scratch variables.
+
+ set r0,`fw-virt-base workspace-offset + #` \ Scratch RAM for inflater
+ mov r1,#0 \ No-header flag (false)
+ set r2,`fw-virt-base #` \ Firmware RAM address
+ add r3,r11,#32 \ Address of compressed bits of firmware dropin
+
+ set sp,`fw-virt-base stack-offset + #` \ Stack for inflater
+
+[ifdef] notdef
+ \ Simple recipe for debug output to serial port
+ set r11, #0xd4018000
+ begin
+ ldr r10,[r11,0x14]
+ ands r10,r10,#0x20
+ 0<> until
+ set r10, #0x43 \ C
+ str r10, [r11]
+[then]
+
+ mov lr,pc
+ mov pc,r4 \ Inflate the firmware
+
+ else
+ \ The firmware dropin isn't compressed, so we just copy it to RAM
+
+ mov r11,r0
+
+ mov r0,#0x14
+ bl `puthex`
+
+ ldr r2,[r11,#4] \ Length of image
+
+ eor r1,r2,r2, ror #16 \ Byte reverse r2 using the
+ bic r1,r1,#0xff0000 \ tricky sequence shown in the
+ mov r2,r2,ror #8 \ ARM Programming Techniques
+ eor r2,r2,r1,lsr #8 \ manual
+
+ add r1,r0,#32 \ src: Skip dropin header
+
+ set r0,`fw-virt-base #` \ dst: Firmware RAM address
+ bl `memcpy` \ Copy the firmware
+ then
+
+ mov r0,#0x15
+ bl `puthex`
+
+ \ Synchronize the instruction and data caches so the firmware code can
+ \ be executed.
+ bl `sync-caches` \ Push Forth dictionary to memory
+
+ mov r0,#0x16
+ bl `puthex`
+
+[ifdef] notdef
+ " nanoforth" $find-dropin, \ Assemble call to find-dropin with literal arg
+
+ add r0,r0,#32 \ Skip dropin header
+ mov lr,pc \ Set return address
+ mov pc,r0 \ Execute the dropin
+[then]
+
+ \ Jump to the RAM firmware image
+ set r4, `fw-virt-base #` \ RAM start address
+ mov pc, r4
+
+ \ Notreached, in theory
+ begin again
+end-code
+
+end-assembling
+
+writing resetvec.img
+asm-base here over - ofd @ fputs
+ofd @ fclose
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2011 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Added: cpu/arm/mmp3/thunderstone/addrs.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/addrs.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,58 @@
+\ Platform design choices
+
+fload ${BP}/cpu/arm/mmuparams.fth
+
+h# 0040.0000 constant /fb-mem \ The screen uses a little more than 3 MiB at 1200x900x24
+
+\ h# 2000.0000 constant total-ram-size
+
+\ h# 1fc0.0000 constant fb-pa
+\ h# 20.0000 constant fb-size \ The screen use a little more than 1 MiB at 800x480x24
+
+\ fb-pa constant available-ram-size
+
+
+\ OFW implementation choices
+0 constant fw-mem-pa
+
+h# 0020.0000 constant /fw-mem
+h# 0020.0000 constant /extra-mem
+h# 0080.0000 constant /dma-mem
+
+h# fd00.0000 constant dma-mem-va
+h# fd80.0000 constant extra-mem-va
+h# fda0.0000 constant fw-mem-va
+h# fdc0.0000 constant fb-mem-va
+
+h# fe00.0000 constant io-va \ We map IO (APB + AXI) space at this virtual address
+h# fe30.0000 constant io2-va \ Mapping area for AXI2 space
+
+[ifdef] virtual-mode
+h# f700.0000 constant fw-virt-base
+h# 0100.0000 constant fw-virt-size \ 16 megs of mapping space
+[else]
+fw-mem-va value fw-virt-base
+/fw-mem value fw-virt-size
+[then]
+
+/fw-mem /page-table - constant page-table-offset
+page-table-offset constant stack-offset \ Stack is below this
+
+\ fw-mem-pa page-table-offset + constant page-table-pa
+
+\ h# 0110.0000 constant def-load-base
+h# 0800.0000 constant def-load-base
+
+\ The heap starts at RAMtop, which on this system is "fw-mem-pa /fw-mem +"
+
+h# 10.0000 constant heap-size
+heap-size constant initial-heap-size
+
+\ RAM address where the Security Processor code places the subset of the dropin module
+\ image that it copies out of SPI FLASH.
+h# 900.0000 constant 'dropins \ Must agree with 'compressed in cforth/src/app/arm-xo-1.75/
+
+h# 20000 constant dropin-offset \ Offset to dropin driver area in SPI FLASH
+
+h# f.ffd8 constant crc-offset
+h# 10.0000 constant /rom \ Total size of SPI FLASH
Added: cpu/arm/mmp3/thunderstone/boardgpio.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/boardgpio.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,253 @@
+purpose: Board-specific setup details - pin assigments, etc.
+
+: set-camera-domain-voltage
+ aib-unlock
+ h# 01e80c io@ 4 or ( n ) \ Set 1.8V selector bit in AIB_GPIO2_IO
+ aib-unlock
+ h# 01e80c io!
+;
+
+: set-gpio-directions ( -- )
+ 3 h# 38 clock-unit-pa + io! \ Enable clocks in GPIO clock reset register
+
+ d# 1 gpio-dir-out \ CAM1_RST_N
+ d# 2 gpio-dir-out \ CAM2_RST_N
+ d# 3 gpio-dir-out \ MPCIE33EN
+\ d# 4 gpio-dir-out \ BB_WAKE_N
+\ d# 6 gpio-dir-out \ BB_ENABLE
+\ d# 7 gpio-dir-out \ BB_RST_N
+ d# 8 gpio-dir-out \ DVC1
+ d# 9 gpio-dir-out \ DVC2
+ d# 15 gpio-dir-out \ GPS_RST
+ d# 57 gpio-dir-out \ WIFI_PD_N
+ d# 58 gpio-dir-out \ WIFI_RST_N
+ d# 62 gpio-dir-out \ CAM2_PWREN
+ d# 63 gpio-dir-out \ LED_B
+ d# 64 gpio-dir-out \ CAM1_PWDN
+ d# 68 gpio-dir-out \ CAM2_PWDN
+ d# 74 gpio-dir-out \ LED_O_N
+ d# 76 gpio-dir-out \ LED_R_N
+ d# 77 gpio-dir-out \ LED_G
+ d# 82 gpio-dir-out \ VBUS_EN
+ d# 84 gpio-dir-out \ LDO_EN
+ d# 86 gpio-dir-out \ TP_RST
+ d# 88 gpio-dir-out \ 5V_ON
+\ d# 89 gpio-dir-out \ VPP_EN
+\ d# 90 gpio-dir-out \ VCC_EN
+ d# 96 gpio-dir-out \ HSIC_RST_N
+\ d# 128 gpio-dir-out \ LCD_RST_N
+\ d# 129 gpio-dir-out \ MPCIESHDN_N
+\ d# 149 gpio-dir-out \ MMC3_RST
+;
+
+create mfpr-table
+ 0 +medium af, \ ,GPIO_00 - CAM1_RST_N
+ 1 +medium af, \ *GPIO_01 - CAM2_RST_N
+ 0 +medium af, \ *GPIO_02 - GPIO keypad (HOME)
+ 0 +medium af, \ ,GPIO_03 - MPCIE33EN
+ 0 +medium af, \ ,GPIO_04 - BB_WAKE_N
+ 0 +medium af, \ ,GPIO_05 - BB_ENABLE
+ no-update, \ ,GPIO_06 - n/c
+ 0 +medium af, \ ,GPIO_07 - BB_RST_N
+ 0 +medium af, \ ,GPIO_08 - DVC1
+ 0 +medium af, \ ,GPIO_09 - DVC2
+ 0 +medium af, \ ,GPIO_10 - FSYNC
+ 0 +medium af, \ ,GPIO_11 - HUB_INT
+ no-update, \ ,GPIO_12 - n/c
+ no-update, \ ,GPIO_13 - n/c
+ 0 +pull-dn af, \ *GPIO_14 - GPS_ON
+ 0 +pull-dn af, \ *GPIO_15 - GPS_RST
+ no-update, \ ,GPIO_16 - n/c
+ no-update, \ ,GPIO_17 - n/c
+ no-update, \ ,GPIO_18 - n/c
+ no-update, \ ,GPIO_19 - n/c
+ 0 +medium af, \ *GPIO_20 - GPIO keypad - DKIN4
+ 0 +medium af, \ ,GPIO_21 - FM_IRQ
+ 0 +medium af, \ *GPIO_22 - GPIO keypad - DKIN6
+ 0 +medium af, \ *GPIO_23 - GPIO for SSPA1 I2S
+ 1 +medium af, \ *GPIO_24 - I2S_SYSCLK (Codec) (n/c on schematic)
+ 1 +medium af, \ *GPIO_25 - I2S_BITCLK (Codec)
+ 1 +medium af, \ *GPIO_26 - I2S_SYNC (Codec)
+ 1 +medium af, \ *GPIO_27 - I2S_DATA_OUT (Codec)
+ 1 +medium af, \ *GPIO_28 - I2S_DATA_IN (Codec)
+ 1 +medium af, \ ,GPIO_29 - UART1_RXD (BT)
+ 1 +medium af, \ ,GPIO_30 - UART1_TXD (BT)
+ 1 +medium af, \ ,GPIO_31 - UART1_CTS (BT)
+ 1 +medium af, \ ,GPIO_32 - UART1_RTS (BT)
+ 1 +medium af, \ ,GPIO_33 - SSPA2_CLK
+ 1 +medium af, \ ,GPIO_34 - SSPA2_FRM
+ 1 +medium af, \ ,GPIO_35 - SSPA2_TXD
+ 1 +medium af, \ ,GPIO_36 - SSPA2_RXD
+ 1 +fast +pull-up af, \ *GPIO_37 - MMC2_DAT3 (WIB card)
+ 1 +fast +pull-up af, \ *GPIO_38 - MMC2_DAT2
+ 1 +fast +pull-up af, \ *GPIO_39 - MMC2_DAT1
+ 1 +fast +pull-up af, \ *GPIO_40 - MMC2_DAT0
+ 1 +fast +pull-up af, \ *GPIO_41 - MMC2_CMD
+ 1 +fast af, \ *GPIO_42 - MMC2_CLK
+ 3 +medium af, \ ,GPIO_43 - SSP1_RXD (thunderstone.c has 1,slow TWSI2_SCL)
+ 3 +medium af, \ ,GPIO_44 - SSP1_TXD (thunderstone.c has 1,slow TWSI2_SDA)
+ 3 +medium af, \ ,GPIO_45 - SSP1_CLK
+ 3 +medium af, \ ,GPIO_46 - SSP1_FRM
+ 1 +medium af, \ *GPIO_47 - UART2_RXD (GPS)
+ 1 +medium af, \ *GPIO_48 - UART2_TXD (GPS)
+ 1 +medium af, \ *GPIO_49 - UART2_CTS
+ 1 +medium af, \ *GPIO_50 - UART2_RTS
+ 1 +medium af, \ *GPIO_51 - UART3_RXD
+ 1 +medium af, \ *GPIO_52 - UART3_TXD
+ 5 +slow +pull-dn af, \ *GPIO_53 - PWM3
+ 4 +pull-up af, \ *GPIO_54 - HDMI_CEC
+ 0 +medium af, \ ,GPIO_55 - WL_BT_WAKE
+ 0 +medium af, \ ,GPIO_56 - WLAN_WAKE
+ 0 +medium af, \ *GPIO_57 - GPIO WIFI_PD_N
+ 0 +medium af, \ *GPIO_58 - GPIO WIFI_RST_N
+
+ 0 +medium af, \ ,GPIO_59 - HDMI_DET
+ 0 +medium af, \ ,GPIO_60 - USIM_DET
+ 0 +medium af, \ ,GPIO_61 - VBUS_FLT_N
+ 0 +medium af, \ ,GPIO_62 - CAM2_PWREN
+ 0 +medium af, \ ,GPIO_63 - LED_B
+ 0 +medium af, \ ,GPIO_64 - CAM1_PWDN
+ 0 +medium af, \ ,GPIO_65 - GYRO_INT_L3G_1
+ 0 +medium af, \ ,GPIO_66 - GYRO_INT_L3G_2
+ 0 +medium af, \ ,GPIO_67 - PCIE_GPIO0
+ 0 +medium af, \ *GPIO_68 - CAM2_PWDN
+ 0 +medium af, \ ,GPIO_69 - PCIE_GPIO1
+ 0 +medium af, \ ,GPIO_70 - MPU_INT
+
+ 1 +slow af, \ *GPIO_71 - TWSI3_SCL
+ 1 +slow af, \ *GPIO_72 - TWSI3_SDA
+ 4 +fast af, \ *GPIO_73 - CAM1_MCLK
+
+ 0 +medium af, \ ,GPIO_74 - LED_O_N
+ no-update, \ ,GPIO_75 - n/c
+ 0 +medium af, \ ,GPIO_76 - LED_R_N
+ 0 +medium af, \ ,GPIO_77 - LED_G
+ 5 +medium af, \ *GPIO_78 - SSP4_CLK
+ 5 +medium af, \ *GPIO_79 - SSP4_FRM
+ 5 +medium af, \ *GPIO_80 - SSP4_TXD
+ 5 +medium af, \ *GPIO_81 - SSP4_RXD
+ 0 +medium af, \ *GPIO_82 - VBUS_EN
+ 0 +medium af, \ ,GPIO_83 - FLASH_EN
+ 0 +medium af, \ *GPIO_84 - GPIO (for PWM3) LDO_EN
+ 0 +medium af, \ *GPIO_85 - GPIO TS_IO_EN
+ 0 +medium af, \ ,GPIO_86 - TP_RST
+ no-update, \ ,GPIO_87 - n/c
+ 0 +medium af, \ ,GPIO_88 - 5V_ON
+ 0 +medium af, \ ,GPIO_89 - VPP_EN
+ 0 +medium af, \ ,GPIO_90 - VCC_EN
+ 0 +medium af, \ ,GPIO_91 - GPIO_ISPCLK
+ 0 +medium af, \ ,GPIO_92 - GPIO_ISPDAT
+ 0 +medium af, \ ,GPIO_93 - PROX_INT
+ no-update, \ ,GPIO_94 - n/c
+ no-update, \ ,GPIO_95 - n/c
+
+ 0 sleep0 af, \ *GPIO_96 - VBUS_EN - OTG
+ 2 +slow af, \ *GPIO_97 - TWSI6_SCL
+ 2 +slow af, \ *GPIO_98 - TWSI_SDA
+ 4 +slow af, \ *GPIO_99 - TWSI5_SCL
+ 4 +slow af, \ *GPIO_100 - TWSI5_SDA
+ 0 +medium af, \ *GPIO_101 - GPIO TS INT
+ no-update, \ ,GPIO_102 - n/c
+ no-update, \ ,GPIO_103 - n/c
+ 0 +medium af, \ *GPIO_104 - DFI_D7
+ 0 +medium af, \ *GPIO_105 - DFI_D6
+ 0 +medium af, \ *GPIO_106 - DFI_D5
+ 0 +medium af, \ *GPIO_107 - DFI_D4
+
+ 2 +fast +pull-up af, \ *GPIO_108 - MMC3_DAT7
+ 2 +fast +pull-up af, \ *GPIO_109 - MMC3_DAT6
+
+ 2 +fast +pull-up af, \ *GPIO_110 - MMC3_DAT2
+ 2 +fast +pull-up af, \ *GPIO_111 - MMC3_DAT3
+ 0 +medium af, \ *GPIO_112 - ND_RDY0
+ no-update, \ ,GPIO_113 - n/c
+ no-update, \ ,GPIO_114 - n/c
+
+ 2 +medium af, \ ,GPIO_115 - HSI_TX_WAKE
+ 2 +medium af, \ ,GPIO_116 - HSI_TX_READY
+ 2 +medium af, \ ,GPIO_117 - HSI_TX_FLAG
+ 2 +medium af, \ ,GPIO_118 - HSI_TX_DATA
+ 2 +medium af, \ ,GPIO_119 - HSI_RX_WAKE
+ 2 +medium af, \ ,GPIO_120 - HSI_RX_READY
+ 2 +medium af, \ ,GPIO_121 - HSI_RX_FLAG
+ 2 +medium af, \ ,GPIO_122 - HSI_RX_DATA
+
+ 0 +medium af, \ ,GPIO_123 - LOW_BATT
+
+ no-update, \ ,GPIO_124 - n/c
+ no-update, \ ,GPIO_125 - n/c
+
+ 0 +medium af, \ ,GPIO_126 - ACC_INT_LSM_1
+ 0 +medium af, \ ,GPIO_127 - ACC_INT_LSM_2
+ 0 +fast af, \ *GPIO_128 - LCD_RST
+ 0 +medium af, \ ,GPIO_129 - MPCIESHDN_N
+ 0 +medium af, \ ,GPIO_130 - MPCIE_PG
+ 1 +fast +pull-up af, \ *GPIO_131 - MMC1_DAT3
+ 1 +fast +pull-up af, \ *GPIO_132 - MMC1_DAT2
+ 1 +fast +pull-up af, \ *GPIO_133 - MMC1_DAT1
+ 1 +fast +pull-up af, \ *GPIO_134 - MMC1_DAT0
+ 1 +fast af, \ *GPIO_135 - MMC1_CLK
+ 1 +fast +pull-up af, \ *GPIO_136 - MMC1_CMD
+
+ no-update, \ ,GPIO_137 - n/c
+ no-update, \ ,GPIO_138 - n/c
+ 0 +medium af, \ ,GPIO_139 - USB_VBUS_DET
+ 1 +fast +pull-up af, \ *GPIO_140 - MMC1_CD
+ 1 +fast +pull-up af, \ *GPIO_141 - MMC1_WP
+
+ no-update, \ ,GPIO_142 - n/c
+ 0 +medium af, \ *GPIO_143 - ND_nCS0
+ 0 +medium af, \ *GPIO_144 - ND_nCS1
+ 2 +fast +pull-up af, \ *GPIO_145 - MMC3_CMD
+ 2 +fast af, \ *GPIO_146 - MMC3_CLK
+
+ 0 +medium af, \ *GPIO_147 - ND_nWE
+ 0 +medium af, \ *GPIO_148 - ND_nRE
+ 1 +fast +pull-up af, \ ,GPIO_149 - MMC3_RST (not in thunderstone.c)
+ 0 +medium af, \ *GPIO_150 - ND_ALE
+
+ no-update, \ ,GPIO_151 - n/c
+ no-update, \ ,GPIO_152 - n/c
+ no-update, \ ,GPIO_153 - n/c
+ no-update, \ ,GPIO_154 - n/c
+ no-update, \ ,GPIO_155 - n/c
+ no-update, \ ,GPIO_156 - PRI_TDI
+ no-update, \ ,GPIO_157 - PRI_TMS
+ no-update, \ ,GPIO_158 - PRI_TCK
+ no-update, \ ,GPIO_159 - PRI_TMS
+ 0 +medium af, \ *GPIO_160 - ND_RDY1
+ 2 +fast +pull-up af, \ *GPIO_161 - MMC3_DAT5
+ 2 +fast +pull-up af, \ *GPIO_162 - MMC3_DAT1
+ 2 +fast +pull-up af, \ *GPIO_163 - MMC3_DAT4
+ 2 +fast +pull-up af, \ *GPIO_164 - MMC3_DAT0
+
+ 0 +medium af, \ *GPIO_165 - DFI_D3
+ 0 +medium af, \ *GPIO_166 - DFI_D2
+ 0 +medium af, \ *GPIO_167 - DFI_D1
+ 0 +medium af, \ *GPIO_168 - DFI_D0
+
+ 0 +slow af, \ *GPIO_169 - TWSI4_SCL
+ 0 +slow af, \ *GPIO_170 - TWSI4_SDA
+ no-update, \ ,GPIO_171 - n/c
+
+: init-mfprs
+ d# 172 0 do
+ mfpr-table i wa+ w@ ( code )
+ dup 8 = if ( code )
+ drop ( )
+ else ( code )
+ i af! ( )
+ then
+ loop
+;
+
+: gpios-for-nand ( -- )
+ h# c0 d# 111 af!
+ h# c0 d# 112 af!
+ d# 169 d# 162 do h# c0 i af! loop
+;
+: gpios-for-emmc ( -- )
+ h# c2 d# 111 af!
+ h# c2 d# 112 af!
+ d# 169 d# 162 do h# c2 i af! loop
+;
Added: cpu/arm/mmp3/thunderstone/boardtwsi.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/boardtwsi.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,172 @@
+purpose: Board-specific details of TWSI-connected devices
+
+\ TWSI devices per channel:
+\ 1 MAX8925 PMIC MAIN 78, PMIC ADC 8e, PMIC RTC d0, MAX8649 c0
+\ 2 WM8994 Audio Codec 34, WM2000 Noise Canceler 74
+\ 3 m6M0 Camera ISP 3e, OV8810 Camera 6c
+\ 4 HMC5843 compass 3c, CM3623 ALS/PS 20+22+b0, BMA150 accelerometer 70
+\ 5 TC358762 MIPI bridge 16, TM-1210 or TM1414 touchscreen 40
+\ 6 HDMI DDC EDID a0
+
+: select-touch-panel ( -- ) h# 40 5 set-twsi-target ;
+: touch-panel-type ( -- n ) select-touch-panel h# bd twsi-b@ ;
+: get-tm1414-data ( -- x y finger-mask )
+ select-touch-panel ( )
+ h# 1a twsi-b@ ( low-y,low-x )
+ dup h# f and h# 18 twsi-b@ 4 lshift or ( low-y,low-x x )
+ swap 4 rshift h# f and h# 19 twsi-b@ 4 lshift or ( x y )
+ h# 15 twsi-b@ ( x y mask )
+;
+: touchpad@ ( -- x y finger-mask ) get-tm1414-data ;
+
+: get-tm1210-data ( -- x y reg7-flick-magnitude reg6-gesture reg0-finger-count )
+ 3 twsi-b@ 2 twsi-b@ bwjoin ( x )
+ 5 twsi-b@ 4 twsi-b@ bwjoin ( x y )
+
+ 7 twsi-b@
+ 6 twsi-b@
+ 0 twsi-b@
+;
+
+: compass@ ( -- x y z temp id )
+ h# 3c 4 set-twsi-target
+ 0 0 twsi-b! \ Config register A
+ h# 50 1 twsi-b! \ Config register B
+ 0 2 twsi-b! \ Mode register
+ 4 twsi-b@ 3 twsi-b@ bwjoin ( x )
+ 6 twsi-b@ 5 twsi-b@ bwjoin ( x y )
+ 8 twsi-b@ 7 twsi-b@ bwjoin ( x y z )
+ h# b twsi-b@ ( x y z temp )
+ h# a twsi-b@ 9 twsi-b@ bwjoin ( x y z temp id )
+;
+
+: select-pmic ( -- ) h# 78 1 set-twsi-target ;
+
+: accel-power-on ( -- ) \ LDO8 - vout is 36, ctl is 34
+ select-pmic
+ d# 3000 d# 750 - d# 50 / h# 36 twsi-b! \ want 3.0V
+ h# 1f h# 34 twsi-b!
+;
+: accel-power-off ( -- ) \ LDO8 - vout is 36, ctl is 34
+ select-pmic
+ h# 1e h# 34 twsi-b!
+;
+: accel@ ( -- x y z temp id )
+ h# 70 4 set-twsi-target
+
+ 2 twsi-b@ 6 rshift ( x-low )
+ 3 twsi-b@ 2 lshift or ( x )
+
+ 4 twsi-b@ 6 rshift ( x y-low )
+ 5 twsi-b@ 2 lshift or ( x y )
+
+ 6 twsi-b@ 6 rshift ( x y z-low )
+ 7 twsi-b@ 2 lshift or ( x y z )
+
+ 8 twsi-b@ 0 twsi-b@ ( x y z temp id )
+;
+
+: init-pals ( -- )
+ h# b0 4 set-twsi-target \ Set PS parameters address
+ 0 1 twsi-write \ clear interrupt settings
+
+ h# 22 4 set-twsi-target \ Device init address
+ h# 10 1 twsi-write \ Init device
+
+ h# 20 4 set-twsi-target \ Ambient Light Sensor address
+ 2 1 twsi-write \ Enable ALS in most sensitive mode, 16-bit data
+;
+: als@ ( -- n )
+ h# 22 4 set-twsi-target \ Ambient Light Sensor LSB address
+ 0 1 twsi-get ( low )
+ h# 20 4 set-twsi-target \ Ambient Light Sensor MSB address
+ 0 1 twsi-get bwjoin ( n )
+;
+
+: proximity@ ( -- byte )
+ h# b0 4 set-twsi-target \ Proximity Sensor address
+ 0 1 twsi-get ( byte )
+;
+
+: lcd-backlight! ( b.intensity -- )
+ select-pmic ( b.intensity )
+ dup if ( b.intensity )
+ h# 85 twsi-b! ( )
+ h# 84 twsi-b@ 1 or h# 84 twsi-b! \ Turn on first LED string
+ else ( 0 )
+ drop ( )
+ h# 84 twsi-b@ 1 invert and h# 84 twsi-b! \ Turn off first LED string
+ then
+;
+
+: keypad-backlight! ( b.intensity -- )
+ select-pmic ( b.intensity )
+ dup if ( b.intensity )
+ h# 85 twsi-b! ( )
+ h# 84 twsi-b@ 3 or h# 84 twsi-b! \ Turn on both LED strings
+ else ( )
+ h# 84 twsi-b@ 3 invert and h# 84 twsi-b! \ Turn off both LED strings
+ then
+;
+
+: power-on-dsi ( -- )
+ select-pmic
+
+ h# 16 h# 22 twsi-b! \ 1.2 volts for LDO3
+ h# 1f h# 20 twsi-b! \ LDO3 enable
+
+ h# 16 h# 16 twsi-b! \ 1.2 volts for LDO17
+ h# 1f h# 14 twsi-b! \ LDO17 enable
+
+ h# 1f h# 34 twsi-b! \ LDO8 enable
+
+ d# 10 ms
+;
+
+: bcd> ( bcd -- binary )
+ dup h# f and swap 4 rshift d# 10 * +
+;
+: twsi-bcd@ ( reg# -- binary ) twsi-b@ bcd> ;
+: get-rtc ( -- )
+ h# d0 1 set-twsi-target
+
+\ 3 twsi-b@ ( dow )
+\
+
+ 0 twsi-bcd@ ( sec )
+ 1 twsi-bcd@ ( sec min )
+ 2 twsi-bcd@ ( sec min hr )
+ 4 twsi-bcd@ ( sec min hr day )
+ 5 twsi-bcd@ ( sec min hr day mon )
+ 6 twsi-bcd@ d# 2000 + ( sec min hr day yr )
+;
+
+: core-voltage! ( mv -- )
+ h# c0 1 set-twsi-target \ MAX8649 power management IC
+
+ d# 750 umax d# 1350 umin \ Clipped voltage
+ d# 750 - d# 10 / ( offset-in-mv/10 )
+ h# 80 or ( code )
+ 2 twsi-b!
+;
+: core-voltage@ ( -- mv )
+ h# c0 1 set-twsi-target \ MAX8649 power management IC
+ 2 twsi-b@ ( code )
+ h# 7f and ( offset-mv/10 )
+ d# 10 * ( offset-mv )
+ d# 750 +
+;
+: .core-voltage ( -- ) core-voltage@ .d ;
+
+: vibrate-on ( -- ) select-pmic h# 1f h# 3c twsi-b! ; \ LDO10
+: vibrate-off ( -- ) select-pmic h# 1e h# 3c twsi-b! ;
+
+: power-on-sd ( -- )
+ select-pmic
+ h# 29 h# 42 twsi-b!
+ h# 1f h# 40 twsi-b!
+;
+: power-off-sd ( -- )
+ select-pmic
+ h# 1e h# 40 twsi-b!
+;
Added: cpu/arm/mmp3/thunderstone/build/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/build/Makefile Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,64 @@
+ROMNAME=ofw
+
+BASEDIR= `(cd ../../../../..; pwd;)`
+
+OS := $(shell uname)
+HOSTCPU= $(shell ${BASEDIR}/forth/lib/hostcpu.sh)
+HOSTDIR= ../../../../${HOSTCPU}/${OS}
+BUILDSH= ${BASEDIR}/forth/lib/build.sh
+
+TAGFILES= ../../../build/*.tag *.tag
+CLIENTDIR=../../../../../clients
+CLIENTPROGS=
+
+all: ${ROMNAME}.rom tags
+
+${ROMNAME}.tag: ${ROMNAME}.rom
+
+tags: ${ROMNAME}.tag
+ @${BASEDIR}/forth/lib/toctags ${BASEDIR} ${TAGFILES}
+
+${ROMNAME}.rom: FORCE build ${CLIENTPROGS} ${HOSTDIR}/forth
+ ./build $@
+
+${HOSTDIR}/forth:
+ @make -C ${HOSTDIR} forth
+
+../../build/inflate.bin:
+ @make -C ../../../build inflate.bin
+
+build:
+ @ln -sf ${BUILDSH} build
+
+clean:
+ rm -f *.dic *.log headers *~ *.elf *.di *.img builton.fth build *.rom *.version tags *.tag
+
+clean-all: clean
+ @make -C ../../../build clean
+ @make -C ${HOSTDIR} clean
+
+.PHONY: FORCE clean all clean-all
+
+# LICENSE_BEGIN
+# Copyright (c) 2009 FirmWorks
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# LICENSE_END
Added: cpu/arm/mmp3/thunderstone/config.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/config.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,9 @@
+create debug-startup
+create use-elf
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/addrs.fth
+fload ${BP}/cpu/arm/mmp2/hwaddrs.fth
+
+create machine-signature ," TS0"
+
+h# 20000 constant l2-#sets
Added: cpu/arm/mmp3/thunderstone/fw-version.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/fw-version.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,4 @@
+\ The overall firmware revision
+macro: FW_PREFIX TS
+macro: FW_MAJOR A
+macro: FW_MINOR 00
Added: cpu/arm/mmp3/thunderstone/fw.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/fw.bth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,530 @@
+purpose: Build Open Firmware for Marvell MMP3 Thunderstone reference board
+\ See license at end of file
+
+dictionary: ${BP}/cpu/arm/mmp3/thunderstone/prefw.dic
+command: &armforth &dictionary &this
+build-now
+
+" fw.tag" r/w create-file drop tag-file !
+
+\ ' $report-name is include-hook
+ ' noop is include-hook
+
+dev /
+ " Marvell,Thunderstone" model
+ " Marvell,PXA2128" encode-string " architecture" property
+ " mrvl,pxa2128" +compatible
+ " mrvl,thunderstone" +compatible
+\ The clock frequency of the root bus may be irrelevant, since the bus is internal to the SOC
+\ d# 1,000,000,000 " clock-frequency" integer-property
+device-end
+
+fload ${BP}/dev/omap/diaguart.fth \ OMAP UART
+
+h# 18000 +io to uart-base \ UART3 base address on MMP2
+\ h# 30000 +io to uart-base \ UART1 base address on MMP2
+d# 26000000 to uart-clock-frequency
+
+\ CForth has already set up the serial port
+: inituarts ( -- ) ;
+
+fload ${BP}/forth/lib/sysuart.fth \ Set console I/O vectors to UART
+
+: poll-tty ( -- ) ubreak? if user-abort then ; \ BREAK detection
+: install-abort ( -- ) ['] poll-tty d# 100 alarm ;
+
+0 value keyboard-ih
+
+fload ${BP}/ofw/core/muxdev.fth \ I/O collection/distribution device
+
+\ Install the simple UART driver from the standalone I/O init chain
+warning off
+: stand-init-io ( -- )
+ stand-init-io
+ inituarts install-uart-io install-abort
+;
+warning on
+
+[ifdef] use-null-nvram
+\ For not storing configuration variable changes across reboots ...
+\ This is useful for "turnkey" systems where configurability would
+\ increase support costs.
+
+fload ${BP}/cpu/x86/pc/nullnv.fth
+stand-init: Null-NVRAM
+ " /null-nvram" open-dev to nvram-node
+ ['] init-config-vars catch drop
+;
+[then]
+
+\ Create a pseudo-device that presents the dropin modules as a filesystem.
+fload ${BP}/ofw/fs/dropinfs.fth
+
+\ This devalias lets us say, for example, "dir rom:"
+devalias rom /dropin-fs
+
+fload ${BP}/cpu/x86/pc/cpunode.fth \ The PC CPU node is actually fairly generic
+
+: cpu-mhz ( -- n )
+ " /cpu at 0" find-package drop ( phandle )
+ " clock-frequency" rot get-package-property if 0 exit then ( adr )
+ decode-int nip nip d# 1000000 /
+;
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/boardtwsi.fth
+fload ${BP}/cpu/arm/mmp3/thunderstone/boardgpio.fth
+: init-stuff
+ set-camera-domain-voltage
+ acgr-clocks-on
+\ init-mfprs \ Unnecessary, done in CForth
+ init-timers
+ init-twsi
+;
+warning @ warning off
+: stand-init-io
+ stand-init-io
+ init-stuff
+;
+warning !
+
+fload ${BP}/cpu/arm/mmp2/watchdog.fth \ reset-all using watchdog timer
+
+0 0 " d4018000" " /" begin-package \ UART3
+ fload ${BP}/cpu/arm/mmp2/uart.fth
+ " /apbc" encode-phandle d# 12 encode-int encode+ " clocks" property
+ d# 24 " interrupts" integer-property
+ 1 " linux,unit#" integer-property
+end-package
+devalias com1 /uart
+: com1 " com1" ;
+' com1 is fallback-device
+
+\ Create a RAMdisk node accessing the dropin modules
+h# 0900.0000 constant ramdisk-base \ Must agree with 'compressed in CForth
+fload ${BP}/dev/ramdisk.fth
+dev /ramdisk h# 10.0000. set-size device-end
+devalias dropins /ramdisk
+
+0 0 " f0400000" " /" begin-package
+ " vmeta" name
+ my-address my-space h# 1000 reg
+
+ " mrvl,mmp2-vmeta" +compatible
+
+ " /pmua" encode-phandle d# 10 encode-int encode+ " clocks" property
+ d# 26 " interrupts" integer-property
+end-package
+
+[ifdef] notyet
+0 0 " d420b000" " /" begin-package
+ " display" name
+\ XXX need to turn on PLL3, see d.l.o:~dilinger/mmp3-snapshot-patches/mmp3/0170-ARM-mmp3/add-fb-device-support.patch
+ fload ${BP}/cpu/arm/mmp2/lcdcfg.fth
+ fload ${BP}/cpu/arm/mmp2/dsi.fth
+
+ fload ${BP}/cpu/arm/mmp2/lcd.fth
+
+ defer convert-color ' noop to convert-color
+ defer pixel*
+ defer pixel+
+ defer pixel!
+
+ : color! ( r g b index -- ) 4drop ;
+ : color@ ( index -- r g b ) drop 0 0 0 ;
+
+ fload ${BP}/dev/video/common/rectangle16.fth \ Rectangular graphics
+
+ depth d# 24 = [if]
+ code 3a+ ( adr n -- n' )
+ pop r0,sp
+ inc tos,#3
+ add tos,tos,r0
+ c;
+ code rgb888! ( n adr -- )
+ pop r0,sp
+ strb r0,[tos]
+ mov r0,r0,lsr #8
+ strb r0,[tos,#1]
+ mov r0,r0,lsr #8
+ strb r0,[tos,#2]
+ pop tos,sp
+ c;
+ ' 3* to pixel*
+ ' 3a+ to pixel+
+ ' rgb888! to pixel!
+ ' noop to convert-color
+ [else]
+ ' /w* to pixel*
+ ' wa+ to pixel+
+ ' w! to pixel!
+ ' argb>565-pixel to convert-color
+ [then]
+
+ : display-on
+ frame-buffer-adr hdisp vdisp * >bytes h# ffffffff lfill
+ init-lcd
+ ;
+ : map-frame-buffer ( -- )
+ \ We use fb-mem-va directly instead of calling map-in on the physical address
+ \ because the physical address changes with the total memory size. The early
+ \ assembly language startup code establishes the mapping.
+ fb-mem-va to frame-buffer-adr
+ ;
+ " display" device-type
+ " ISO8859-1" encode-string " character-set" property
+ 0 0 encode-bytes " iso6429-1983-colors" property
+
+ \ Used as temporary storage for images by $get-image
+ : graphmem ( -- adr ) dimensions * pixel* fb-mem-va + ;
+
+ : display-install ( -- )
+ map-frame-buffer
+ display-on
+ default-font set-font
+ width height ( width height )
+ over char-width / over char-height / ( width height rows cols )
+ /scanline depth fb-install ( )
+ ;
+
+ : display-remove ( -- ) ;
+ : display-selftest ( -- failed? ) false ;
+
+ ' display-install is-install
+ ' display-remove is-remove
+ ' display-selftest is-selftest
+end-package
+
+devalias screen /display
+[then]
+
+devalias keyboard /keyboard
+
+create cp881-16 " ${BP}/ofw/termemu/cp881-16.obf" $file,
+' cp881-16 to romfont
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/sdhci.fth
+
+devalias ext /sd/disk at 1
+
+fload ${BP}/ofw/core/fdt.fth
+fload ${BP}/cpu/arm/linux.fth
+
+\ Create the alias unless it already exists
+: $?devalias ( alias$ value$ -- )
+ 2over not-alias? if $devalias exit then ( alias$ value$ alias$ )
+ 2drop 4drop
+;
+
+: ?report-device ( alias$ pathname$ -- )
+ 2dup locate-device 0= if ( alias$ pathname$ phandle )
+ drop ( alias$ pathname$ )
+ 2over 2over $?devalias ( alias$ pathname$ )
+ then ( alias$ pathname$ )
+ 4drop ( )
+;
+
+: report-disk ( -- )
+ " disk" " /usb/disk" ?report-device
+;
+
+: report-keyboard ( -- )
+ \ Prefer direct-attached
+ " usb-keyboard" " /usb/keyboard" ?report-device \ USB 2 (keyboard behind a hub)
+;
+
+\ If there is a USB ethernet adapter, use it as the default net device.
+\ We can't use ?report-device here because we already have net aliased
+\ to /wlan, and ?report-device won't override an existing alias.
+: report-net ( -- )
+ " /usb/ethernet" 2dup locate-device 0= if ( name$ phandle )
+ drop ( name$ )
+
+ \ Don't recreate the alias if it is already correct
+ " net" aliased? if ( name$ existing-name$ )
+ 2over $= if ( name$ )
+ 2drop exit ( -- )
+ then ( name$ )
+ then ( name$ )
+
+ " net" 2swap $devalias ( )
+ else ( name$ )
+ 2drop ( )
+ then
+;
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/usb.fth
+
+: bat-temp ( -- n ) 0 ;
+fload ${BP}/cpu/arm/mmp2/thermal.fth
+fload ${BP}/cpu/arm/mmp2/fuse.fth
+
+[ifndef] virtual-mode
+warning off
+: stand-init-io
+ stand-init-io
+ go-fast \ From mmuon.fth
+;
+warning on
+[then]
+
+\ The bottom of extra-mem is the top of DMA memory.
+\ We give everything up to that address to Linux.
+: olpc-memory-limit ( -- adr ) extra-mem-va >physical ;
+' olpc-memory-limit to memory-limit
+
+h# 20.0000 to linux-params \ The Jasper Linux kernel fails unless the params are between 0x20.0000 and 0x20.4000
+d# 99999 to arm-linux-machine-type
+
+\ Add a tag describing the linear frame buffer
+: mmp-fb-tag, ( -- )
+ 8 tag-l,
+ h# 54410008 tag-l, \ ATAG_VIDEOLFB
+ screen-wh over tag-w, \ Width ( width height )
+ dup tag-w, \ Height ( width height )
+ " depth" $call-screen dup tag-w, \ Depth ( width height depth )
+ rot * 8 / dup tag-w, \ Pitch ( height pitch )
+ fb-mem-va tag-l, \ Base address ( height pitch )
+ * tag-l, \ Total size - perhaps could be larger
+ \ The following assumes depth is 16 bpp
+ 5 tag-b, \ Red size
+ d# 11 tag-b, \ Red position
+ 6 tag-b, \ Green size
+ d# 5 tag-b, \ Green position
+ 5 tag-b, \ Blue size
+ d# 0 tag-b, \ Blue position
+ 0 tag-b, \ Rsvd size
+ d# 16 tag-b, \ Rsvd position
+;
+' mmp-fb-tag, to fb-tag,
+
+\ Add a tag describing the OFW callback
+3 constant MT_DEVICE_WC
+9 constant MT_MEMORY
+: (ofw-tag,) ( -- )
+ 4 2 * 3 + tag-l, \ size
+ h# 41000502 tag-l, \ ATAG_MEM
+ cif-handler tag-l, \ Client interface handler callback address
+
+ \ Each of these groups is a struct map_desc as defined in arch/arm/include/asm/mach/
+ extra-mem-va dup tag-l, \ VA of OFW memory
+ >physical pageshift rshift tag-l, \ Page frame number of OFW memory
+ fw-mem-va /fw-mem + extra-mem-va - tag-l, \ Size of OFW memory
+ MT_MEMORY tag-l, \ Mapping type of OFW memory
+
+ fb-mem-va dup tag-l, \ VA of OFW Frame Buffer
+ >physical pageshift rshift tag-l, \ PA of OFW Frame Buffer
+ /fb-mem tag-l, \ Size of OFW memory
+ MT_DEVICE_WC tag-l, \ Mapping type of OFW frame buffer
+;
+' (ofw-tag,) to ofw-tag,
+
+\ false to stand-init-debug?
+true to stand-init-debug?
+
+: protect-fw ( -- ) ;
+
+hex
+: i-key-wait ( ms -- pressed? )
+ cr ." Type 'i' to interrupt stand-init sequence" cr ( ms )
+ 0 do
+ ukey? if
+ ukey upc ascii I = if true unloop exit then
+ then
+ d# 1000 us \ 1000 us is more precise than 1 ms, which is often close to 2 ms
+ loop
+ false
+;
+
+warning @ warning off
+: init
+\ initial-heap add-memory
+ init
+
+ standalone? if
+ disable-interrupts
+ d# 1000 i-key-wait if
+\ protect-fw
+ ." Interacting" cr hex interact
+ then
+ \ Turn on USB power here to overlap the time with other startup actions
+ usb-power-on
+ then
+;
+warning !
+
+: (.firmware) ( -- )
+ ." Open Firmware " .built cr
+ ." Copyright 2010 FirmWorks All Rights Reserved" cr
+;
+' (.firmware) to .firmware
+
+\ Uninstall the diag menu from the general user interface vector
+\ so exiting from emacs doesn't invoke the diag menu.
+' quit to user-interface
+
+: screen-#lines ( -- n )
+ screen-ih 0= if default-#lines exit then
+ screen-ih package( #lines )package
+;
+' screen-#lines to lines/page
+
+true value text-on?
+: text-off ( -- )
+ text-on? if
+ screen-ih remove-output
+ false to text-on?
+ then
+;
+: text-on ( -- )
+ text-on? 0= if
+ screen-ih add-output
+\ cursor-on
+ true to text-on?
+ then
+;
+
+fload ${BP}/cpu/arm/mmp2/clocks.fth
+
+: console-start ( -- )
+ install-mux-io
+\ cursor-off
+ true to text-on?
+
+ " //null" open-dev to null-ih \ For text-off state
+;
+: keyboard-off ( -- )
+ keyboard-ih if
+ keyboard-ih remove-input
+ keyboard-ih close-dev
+ 0 to keyboard-ih
+ then
+;
+
+: teardown-mux-io ( -- )
+ install-uart-io
+ text-off
+ keyboard-off
+ fallback-out-ih remove-output
+ fallback-in-ih remove-input
+ stdin off
+ stdout off
+ in-mux-ih close-dev
+ out-mux-ih close-dev
+;
+: quiesce ( -- )
+ usb-quiet
+ teardown-mux-io
+ timers-off
+ unload-crypto
+;
+
+\ This must precede the loading of gui.fth, which chains from linux-hook's behavior
+' quiesce to linux-hook
+
+\ fload ${BP}/cpu/arm/mmp2/dramrecal.fth
+
+code halt ( -- ) wfi c;
+
+\ fload ${BP}/cpu/arm/mmp2/rtc.fth \ Internal RTC, used for wakeups
+
+fload ${BP}/dev/logdev.fth
+
+" u:\boot\olpc.fth ext:\boot\olpc.fth int:\boot\olpc.fth ext:\zimage /prober /usb/ethernet /usb/wlan"
+ ' boot-device set-config-string-default
+
+\needs ramdisk " " d# 128 config-string ramdisk
+" " ' boot-file set-config-string-default \ Let the boot script set the cmdline
+
+\ Eliminate 4 second delay in install console for the case where
+\ there is no keyboard. The delay is unnecessary because the screen
+\ does not go blank when the device is closed.
+patch drop ms install-console
+
+alias reboot bye
+
+alias crcgen drop ( crc byte -- crc' )
+
+\ Dictionary growth size for the ARM Image Format header
+\ 1 section before origin section table
+h# 10.0000 h# 8000 - h# 4000 - dictionary-size !
+
+fload ${BP}/cpu/arm/saverom.fth \ Save the dictionary for standalone startup
+
+fload ${BP}/ofw/core/countdwn.fth \ Startup countdown
+
+: interpreter-init ( -- )
+ hex
+ warning on
+ only forth also definitions
+
+\ install-alarm
+
+ page-mode
+ #line off
+
+\ .built cr
+;
+
+: startup ( -- )
+ standalone? 0= if exit then
+
+\ block-exceptions
+ no-page
+
+ console-start
+
+ " probe-" do-drop-in
+
+ ['] false to interrupt-auto-boot?
+[ifndef] probe-usb
+ probe-usb
+ report-disk
+ report-keyboard
+[else] ." Not probing usb" cr
+[then]
+ " probe+" do-drop-in
+
+ interpreter-init
+\ unblock-exceptions
+ ['] (interrupt-auto-boot?) to interrupt-auto-boot?
+\ ?usb-keyboard
+ auto-banner? if banner then
+
+ auto-boot
+
+ cr cr
+
+ quit
+;
+
+tag-file @ fclose tag-file off
+
+.( --- Saving fw.dic ...)
+" fw.dic" $save-forth cr
+
+fload ${BP}/cpu/arm/mmp2/rawboot.fth
+.( --- Saving fw.img --- ) cr " fw.img" $save-rom
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2010 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Added: cpu/arm/mmp3/thunderstone/ofw.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/ofw.bth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,147 @@
+purpose: Construct the Open Firmware module collection
+
+command: &builder &this
+in: ${BP}/cpu/arm/mmp3/thunderstone/build/fw.img
+in: ${BP}/cpu/arm/mmp3/thunderstone/build/resetvec.img
+in: ${BP}/dev/usb2/device/hub/build/hub.fc
+in: ${BP}/dev/usb2/device/generic/build/generic.fc
+in: ${BP}/dev/usb2/device/net/build/usbnet.fc
+in: ${BP}/dev/usb2/device/keyboard/build/usbkbd.fc
+in: ${BP}/dev/usb2/device/mouse/build/usbmouse.fc
+in: ${BP}/dev/usb2/device/serial/build/usbserial.fc
+in: ${BP}/dev/usb2/device/storage/build/usbstorage.fc
+build-now
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/fw-version.fth
+
+" macro: FW_VERSION ${FW_PREFIX}${FW_MAJOR}${FW_MINOR}" expand$ eval
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/config.fth
+
+\ Always re-create the builton.fth file when we make a new rom.img
+fload ${BP}/cpu/x86/pc/builton.bth
+fload ${BP}/cpu/arm/olpc/sourceurl.fth
+
+fload ${BP}/forth/lib/crc32.fth
+
+hex
+
+: pad-file ( location -- )
+ ofd @ fsize
+ 2dup u< abort" The ROM image is too large"
+ ?do h# ff ofd @ fputc loop
+;
+
+fload ${BP}/cpu/arm/marvell/tim.fth
+
+\ Marvel Trusted Image Module image creation script for
+\ XO-1.75 platform.
+
+tim: 00030400 0 OLPC PXA212x
+flash: SPI'10
+timh: TIMH 0 d101f000
+\ Main Processor code loaded into DRAM
+image: OBMI 800 d101c000 ${BP}/cpu/arm/olpc/dummy.img
+\ Secure Processor code loaded into SRAM
+\ image: WTMI 1000 d1018000 shim.img
+\ image: CFTH 2000 d1000000 cforth.img
+reserved:
+\ true to scrolling-debug? debug end-tim
+ term:
+end-reserved
+end-tim
+
+h# e.0000 to reserved-start
+h# f.0000 to reserved-end
+
+.( --- Saving as )
+" ${FW_VERSION}.rom" expand$ 2dup lower ( adr len )
+2dup type cr ( adr len )
+$new-file
+ tim$ ofd @ fputs
+
+ dropin-offset pad-file
+
+\ Loads the set of drivers that is common to different output formats
+
+ " ${BP}/cpu/arm/build/inflate.bin" " inflate" $add-dropin
+ " fw.img" " firmware" $add-deflated-dropin
+\ " fw.img" " firmware" $add-dropin
+ " resetvec.img" " reset" $add-dropin
+
+\ " verify.img" " verify" $add-deflated-dropin
+
+ " sourceurl" " sourceurl" $add-dropin
+
+ " builton.fth" " probe-" $add-dropin
+
+\ " ${BP}/dev/usb2/hcd/ehci/build/ehci.fc" " class0c0320" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/hub/build/hub.fc" " usb,class9" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/generic/build/generic.fc" " usbdevice" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/net/build/usbnet.fc" " usbnet" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/keyboard/build/usbkbd.fc" " usb,class3,1,1" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/mouse/build/usbmouse.fc" " usb,class3,1,2" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/serial/build/usbserial.fc" " usbserial" $add-deflated-dropin
+ " ${BP}/dev/usb2/device/storage/build/usbstorage.fc" " usbstorage" $add-deflated-dropin
+
+ " ${BP}/ofw/inet/telnetd.fth" " telnetd" $add-deflated-dropin
+.( Dropin top is ) ofd @ fsize .x cr
+
+/rom pad-file
+
+\ Insert the revision signature
+/rom h# 40 - ofd @ fseek
+h# 10 buffer: signature
+signature h# 10 blank
+machine-signature count signature swap move
+" ${FW_VERSION}" expand$ signature 6 + swap move
+" ${FW_PREFIX}${FW_MAJOR}" expand$ signature d# 13 + swap move
+signature h# 10 ofd @ fputs
+
+/l buffer: crcbuf
+/rom buffer: filebuf
+
+\ Read the entire image, compute the CRC, and store it h# 28 from the end
+0 ofd @ fseek
+filebuf /rom ofd @ fgets /rom <> abort" Can't read back image"
+0 crctab filebuf /rom ($crc) crcbuf !
+
+crc-offset ofd @ fseek
+crcbuf /l ofd @ fputs
+
+ofd @ fclose
+
+\ Creating olpc.version serves two purposes:
+\ a) It reports the firmware revision for use by external scripts
+\ b) It provides an olpc.* artifact for the builder dependency management.
+
+writing olpc.version
+" ${FW_VERSION}" expand$ 2dup lower ofd @ fputs
+ofd @ fclose
+
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2010 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
+
Added: cpu/arm/mmp3/thunderstone/prefw.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/prefw.bth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,13 @@
+purpose: Build OFW Forth dictionary for Thunderstone
+\ See license at end of file
+
+dictionary: ${BP}/cpu/arm/build/basefw.dic
+command: &armforth &dictionary &this
+build-now
+
+\ This line must be in this file instead of in prefw.fth so the definitions
+\ in config.fth will be tagged.
+" prefw.tag" r/w create-file drop tag-file !
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/config.fth
+fload ${BP}/cpu/arm/olpc/prefw.fth
Added: cpu/arm/mmp3/thunderstone/resetvec.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/resetvec.bth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,7 @@
+purpose: Build script for low-level startup code
+
+command: &builder &this
+build-now
+
+fload ${BP}/cpu/arm/mmp3/thunderstone/config.fth
+fload ${BP}/cpu/arm/mmp3/resetvec.fth
Added: cpu/arm/mmp3/thunderstone/sdhci.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/sdhci.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,28 @@
+purpose: Load file for SDHCI (Secure Digital Host Controller Interface)
+
+0 0 " d4280000" " /" begin-package
+
+ fload ${BP}/cpu/arm/mmp2/sdregs.fth
+ fload ${BP}/dev/mmc/sdhci/sdhci.fth
+ true to avoid-high-speed?
+
+ new-device
+ 3 encode-int " reg" property
+ fload ${BP}/dev/mmc/sdhci/sdmmc.fth
+ \ fload ${BP}/dev/mmc/sdhci/selftest.fth
+ " internal" " slot-name" string-property
+ finish-device
+
+\ new-device
+\ 2 encode-int " reg" property
+\ " mv8686" " $load-driver" eval drop
+\ finish-device
+
+ new-device
+ 1 encode-int " reg" property
+ fload ${BP}/dev/mmc/sdhci/sdmmc.fth
+ \ fload ${BP}/dev/mmc/sdhci/selftest.fth
+ " external" " slot-name" string-property
+ finish-device
+
+end-package
Added: cpu/arm/mmp3/thunderstone/usb.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp3/thunderstone/usb.fth Wed Jul 18 23:55:07 2012 (r3073)
@@ -0,0 +1,180 @@
+purpose: Platform-specific USB elaborations
+\ See license at end of file
+
+0 0 " d4208000" " /" begin-package \ USB Host Controller
+ h# 200 constant /regs
+ my-address my-space /regs reg
+ : my-map-in ( len -- adr )
+ my-space swap " map-in" $call-parent h# 100 + ( adr )
+ ;
+ : my-map-out ( adr len -- ) swap h# 100 - swap " map-out" $call-parent ;
+ " /pmua" encode-phandle 5 encode-int encode+ " clocks" property
+ d# 44 " interrupts" integer-property
+
+ false constant has-dbgp-regs?
+ false constant needs-dummy-qh?
+ : grab-controller ( config-adr -- error? ) drop false ;
+ fload ${BP}/dev/usb2/hcd/ehci/loadpkg.fth
+\ false to delay? \ No need for a polling delay on this platform
+ : otg-set-host-mode 3 h# a8 ehci-reg! ; \ Force host mode
+ ' otg-set-host-mode to set-host-mode
+
+ : sleep ( -- ) true to first-open? ;
+ : wake ( -- ) ;
+end-package
+
+: usb-power-on ( -- ) d# 82 gpio-set ;
+fload ${BP}/cpu/arm/marvell/utmiphy.fth
+: init-usb ( -- )
+ h# 9 h# 5c pmua! \ Enable clock to USB block
+ init-usb-phy
+;
+
+stand-init: Init USB Phy
+ ." Skipping init-usb-phy" cr
+\ init-usb-phy
+;
+devalias u /usb/disk
+
+\ Like $show-devs, but ignores pagination keystrokes
+: $nopage-show-devs ( nodename$ -- )
+ ['] exit? behavior >r ['] false to exit?
+ $show-devs
+ r> to exit?
+;
+
+\ Restrict selftest to external USB ports 1,2,3
+\ dev / 3 " usb-test-ports" integer-property dend
+
+: (probe-usb2) ( -- )
+ " device_type" get-property if exit then
+[ifdef] use-usb-debug-port
+ \ I haven't figured out how to turn on the EHCI cleanly
+ \ when the Debug Port is running
+ dbgp-off
+[then]
+ get-encoded-string " ehci" $= if
+ pwd$ open-dev ?dup if close-dev then
+ then
+;
+: (show-usb2) ( -- )
+ " device_type" get-property if exit then
+ get-encoded-string " ehci" $= if
+ pwd$ $nopage-show-devs
+ then
+;
+
+true value first-usb-probe?
+: (silent-probe-usb) ( -- ) " /" ['] (probe-usb2) scan-subtree ;
+: silent-probe-usb ( -- )
+ (silent-probe-usb)
+ report-disk report-net report-keyboard
+;
+: probe-usb ( -- )
+ first-usb-probe? if
+ false to first-usb-probe?
+ \ Initial probe to awaken the hub
+ (silent-probe-usb)
+ \ A little delay to let slow devices like USB scanner wake up
+ d# 150 ms
+ then
+ silent-probe-usb
+
+ ." USB devices:" cr
+ " /" ['] (show-usb2) scan-subtree
+
+;
+alias p2 probe-usb
+
+0 value usb-keyboard-ih
+
+: attach-usb-keyboard ( -- )
+ " usb-keyboard" expand-alias if ( devspec$ )
+ drop " /usb" comp 0= if ( )
+ " usb-keyboard" open-dev to usb-keyboard-ih
+ usb-keyboard-ih add-input
+ exit
+ then
+ else ( devspec$ )
+ 2drop
+ then
+;
+
+: detach-usb-keyboard ( -- )
+ usb-keyboard-ih if
+ usb-keyboard-ih remove-input
+ usb-keyboard-ih close-dev
+ 0 to usb-keyboard-ih
+ then
+;
+
+: ?usb-keyboard ( -- )
+ attach-usb-keyboard
+;
+
+: usb-quiet ( -- )
+ detach-usb-keyboard
+ " /usb" " reset-usb" execute-device-method drop
+;
+
+: suspend-usb ( -- )
+ detach-usb-keyboard
+ " /usb" " sleep" execute-device-method drop
+;
+: has-children? ( devspec$ -- flag )
+ locate-device if false else child 0<> then
+;
+: any-usb-devices? ( -- flag ) " /usb/hub" has-children? ;
+: resume-usb ( -- )
+ init-usb
+ " /usb" " wake" execute-device-method drop
+ any-usb-devices? if
+ d# 2000 ms \ USB misses devices if you probe too soon
+ then
+ silent-probe-usb
+ attach-usb-keyboard
+;
+
+\ Unlink every node whose phys.hi component matches port
+: port-match? ( port -- flag )
+ get-unit if drop false exit then
+ get-encoded-int =
+;
+: rm-usb-children ( port -- )
+ device-context? 0= if drop exit then
+ also ( port )
+ 'child ( port prev )
+ first-child begin while ( port prev )
+ over port-match? if ( port prev )
+ 'peer link@ over link! ( port prev ) \ Disconnect
+ else ( port prev )
+ drop 'peer ( port prev' )
+ then ( port prev )
+ next-child repeat ( port prev )
+ 2drop ( )
+ previous definitions
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2010 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
More information about the openfirmware
mailing list