Author: wmb Date: Fri Oct 8 08:31:34 2010 New Revision: 1964 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/1964
Log: Added Marvell TIM (Trusted Image Module) compiler and scripts to generate various images with it.
Added: cpu/arm/marvell/tim.fth cpu/arm/mmp2/ddr_elpida_512m.fth cpu/arm/mmp2/ntim_mmp2_nand_cforth_ddr_elpida_512m.fth cpu/arm/mmp2/ntim_mmp2_nand_ofw_ddr_elpida_512m.fth cpu/arm/mmp2/ntim_mmp2_nand_ofwonly_ddr_elpida_512m.fth cpu/arm/mmp2/ntim_mmp2_nand_uboot_ddr_elpida_512m.fth
Added: cpu/arm/marvell/tim.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/marvell/tim.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,191 @@ +: >hex ( n -- n' ) d# 10 /mod h# 10 * + ; +: today>hex ( -- n ) + today ( day month year ) + d# 100 /mod ( day month yr century ) + rot >hex >r ( day yr century r: hex-month ) + rot >hex >r ( yr century r: hex-month hex-day ) + >hex >r ( yr r: hex-month hex-day hex-century ) + >hex r> r> r> bljoin ( n ) +; + +0 value image-size +0 value image-adr +0 value new-image-size +: ?realloc-image ( new-size -- ) + dup image-size > if ( new-size ) + to new-image-size ( ) + image-adr if ( ) + image-adr new-image-size resize abort" resize failed" ( adr ) + else ( ) + new-image-size alloc-mem ( adr ) + then ( adr ) + to image-adr ( ) + image-adr new-image-size image-size /string h# ff fill + new-image-size to image-size + else ( new-size ) + drop ( ) + then ( ) +; + +: hex, ( -- ) safe-parse-word $hnumber abort" Bad hex number" l, ; +: get-word ( -- adr len ) safe-parse-word ; +: get-filename ( -- adr len ) 0 parse ; + +: ?4bytes ( adr len -- adr ) 4 <> abort" Tag must be 4 characters" ; +: 4c, ( adr len -- ) + ?4bytes ( adr ) + 3 + 4 0 do dup i - c@ c, loop drop ( ) +; +: -4c, ( adr len -- ) + ?4bytes + 4 bounds do i c@ c, loop ( ) +; +: 4c! ( adr len dst -- ) + >r ?4bytes 4 + r> ( adr' dst ) + 4 0 do ( adr dst ) + swap 1- tuck c@ ( adr' dst src-byte ) + over c! 1+ ( adr dst' ) + loop ( adr dst ) + 2drop ( ) +; + +0 value tim-adr +0 value last-image-adr +0 value #images-adr +0 value res-size-adr +0 value #keys-adr +0 value res-adr +: save-tim: \ filename ( -- ) + writing + tim-adr here over - ofd @ fputs + ofd @ fclose +; +0 value my-timh-adr + +: save-image: \ filename ( -- ) + writing + image-adr image-size ofd @ fputs + ofd @ fclose + image-adr image-size free-mem +; +: tim: \ version trusted ID Processor + 0 to last-image-adr + here to tim-adr + hex, + " TIMH" 4c, + hex, \ Trusted +\ hex, \ Date + today>hex l, + get-word -4c, \ OEM ID + get-word 2drop \ Processor +; +: flash: \ id (e.g. NAN6) + 5 0 do -1 l, loop + + get-word ( adr len ) + \ Convert trailing number to binary byte value - e.g. NAN'6 -> NAN(06) + 2dup [char] ' left-parse-string 2drop ( adr len tail$ ) + push-decimal $number pop-base abort" Bad number" ( adr len n ) + nip over 3 + c! 4 ( adr 4 ) + 4c, + + here to #images-adr 0 l, + here to #keys-adr 0 l, + here to res-size-adr 0 l, +; +: set-last-image ( adr len -- ) + last-image-adr if last-image-adr 4c! else 2drop then + here to last-image-adr -1 l, +; +: $file-size ( adr len -- size ) + $read-open ifd @ fsize ifd @ fclose +; +: place-image ( adr len -- size ) + $read-open ifd @ fsize ( size ) + here 8 - l@ ( size offset ) + 2dup + ?realloc-image ( size offset ) + image-adr + over ( size adr size ) + ifd @ fgets ( size read-size ) + over <> abort" Read failed" ( size ) + ifd @ fclose ( size ) +\ h# 1000 round-up + 4 round-up +; +: place-hash \ XXX need to implement non-null hash info + d# 10 0 do 0 l, loop +; +: +#images ( -- ) #images-adr l@ 1+ #images-adr l! ; +: start-image ( adr len -- ) + +#images + get-word 2dup 4c, set-last-image + hex, \ Flash offset + hex, \ Load address +; +: image: \ name flash-offset mem-load-addr filename + start-image + get-filename place-image l, + place-hash +; +: timh: \ name flash-offset mem-load-addr + here to my-timh-adr + start-image + 0 l, \ This will be overwritten later + place-hash +; +0 value #res-pkgs-adr + +: reserved: + here to res-adr + " OPTH" 4c, + here to #res-pkgs-adr 0 l, +; +: end-reserved + here res-adr - res-size-adr l! + ['] (do-literal) to do-literal +; +0 value pkg-start-adr +: start-package ( adr len -- ) + #res-pkgs-adr l@ 1+ #res-pkgs-adr l! + here to pkg-start-adr + 4c, + 0 l, \ Package size +; +: end-package ( -- ) + here pkg-start-adr - pkg-start-adr la1+ l! +; +: end-tim ( -- ) + \ If we have used a timh: specifier, set its length and copy the constructed TIM into the image + my-timh-adr if + here tim-adr - my-timh-adr 4 la+ l! + tim-adr image-adr my-timh-adr 2 la+ l@ + here tim-adr - move + then +; +: tbrx: \ xferloc + " TBRX" start-package + hex, + 0 l, \ #pairs +; +: transfer: \ NAME address + pkg-start-adr 3 la+ dup l@ 1+ swap l! \ Increment #pairs + get-word 4c, + hex, +; +: pair: \ tag value + hex, + hex, +; +: gpios: + " GPIO" start-package + 0 l, \ #pairs +; +: gpio: \ address value + pkg-start-adr 2 la+ dup l@ 1+ swap l! \ Increment #pairs + pair: +; +: ddrc: \ + " DDRC" start-package +; +: cmcc: \ + " CMCC" start-package +; +: term: " Term" start-package end-package ;
Added: cpu/arm/mmp2/ddr_elpida_512m.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/ddr_elpida_512m.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,90 @@ + gpios: + gpio: d0000010 d0004d56 \ CONFIG_DECODE_ADDR + gpio: d0000100 000c0001 \ MMAP0 + gpio: d0000110 100c0001 \ MMAP1 + gpio: d0000020 00006420 \ SDRAM_CONFIG_TYPE1-CS0 + gpio: d0000030 00006420 \ SDRAM_CONFIG_TYPE1-CS1 + gpio: d0000b40 00000000 \ SDRAM_CONFIG_TYPE2-CS0 + gpio: d0000b50 00000000 \ SDRAM_CONFIG_TYPE2-CS1 + gpio: d0000050 488700c5 \ SDRAM_TIMING1 + gpio: d0000060 323300d2 \ SDRAM_TIMING2 + gpio: d0000190 20000e12 \ SDRAM_TIMING3 + gpio: d00001c0 3023009d \ SDRAM_TIMING4 + gpio: d0000650 00050082 \ SDRAM_TIMING5 + gpio: d0000660 00909064 \ SDRAM_TIMING6 + gpio: d0000080 00005000 \ SDRAM_CTRL1 + gpio: d0000090 00080010 \ SDRAM_CTRL2 + gpio: d00000f0 c0000000 \ SDRAM_CTRL3 + gpio: d00001a0 20c08115 \ SDRAM_CTRL4 + gpio: d0000280 01010101 \ SDRAM_CTRL5_ARB_WEIGHTS + gpio: d0000760 00000000 \ SDRAM_CTRL6_SDRAM_ODT_CTRL + gpio: d0000770 03000000 \ SDRAM_CTRL7_SDRAM_ODT_CTRL2 + gpio: d0000780 00000133 \ SDRAM_CTRL8_SDRAM_ODT_CTRL2 + gpio: d00007b0 01010101 \ SDRAM_CTRL11_ARB_WEIGTHS_FAST_QUEUE + gpio: d00007d0 0000000f \ SDRAM_CTRL13 + gpio: d00007e0 00000000 \ SDRAM_CTRL14 + gpio: d0000540 00000000 \ MCB_CTRL4 + gpio: d0000570 00000001 \ MCB_SLFST_SEL + gpio: d0000580 00000000 \ MCB_SLFST_CTRL0 + gpio: d0000590 00000000 \ MCB_SLFST_CTRL1 + gpio: d00005a0 00000000 \ MCB_SLFST_CTRL2 + gpio: d00005b0 00000000 \ MCB_SLFST_CTRL3 + gpio: d0000180 00000000 \ CM_WRITE_PROTECTION + gpio: d0000210 00000000 \ PHY_CTRL11 + gpio: d0000240 80000000 \ PHY_CTRL14 + gpio: d0000240 2000ce00 \ PHY_CTRL14 + gpio: d0000240 0000ce00 \ PHY_CTRL14 + gpio: d0000200 0011ce00 \ PHY_CTRL10 + gpio: d0000200 0010311c \ PHY_CTRL10 + gpio: d0000140 20004422 \ PHY_CTRL3 + gpio: d00001d0 13300559 \ PHY_CTRL7 (0x2330_0339 / 0x133C_2559) + gpio: d00001e0 03300990 \ PHY_CTRL8 + gpio: d00001f0 00000077 \ PHY_CTRL9 + gpio: d0000230 20000088 \ PHY_CTRL13 (0x2000_0108 / 0x2024_0109) + gpio: d0000e10 00000080 \ PHY_DLL_CTRL1 + gpio: d0000e20 00000080 \ PHY_DLL_CTRL2 + gpio: d0000e30 00000080 \ PHY_DLL_CTRL3 + gpio: d0000e40 00000000 \ PHY_CTRL_WL_SELECT + gpio: d0000e50 00000000 \ PHY_CTRL_WL_CTRL0 + gpio: d0000120 03000001 \ USER_INITIATED_COMMAND0 - init command to both CS (need to wait 200 us for tINIT3) + gpio: d0000410 0302003f \ USER_INITIATED_COMMAND1 - MRW MR63 (RESET) to both CS (need to wait RESET_COUNT) + gpio: d0000120 01001000 \ USER_INITIATED_COMMAND0 - MRW MR10 (ZQ long cal) to CS0 (need 360 ns delay for tZQCS) + gpio: d0000120 02001000 \ USER_INITIATED_COMMAND0 - MRW MR10 (ZQ long cal) to CS1 (need 360 ns delay for tZQCS) + gpio: d0000410 03020001 \ USER_INITIATED_COMMAND1 - MRW MR1 to both CS + gpio: d0000410 03020002 \ USER_INITIATED_COMMAND1 - MRW MR2 to both CS + gpio: d0000410 03020003 \ USER_INITIATED_COMMAND1 - MRW MR3 to both CS + end-package + ddrc: + pair: 00000000 00006320 \ ConfTypeCS0 + pair: 00000001 00006320 \ ConfTypeCS1 + pair: 00000002 4cd800c5 \ Timing1 + pair: 00000003 84660342 \ Timing2 + pair: 00000004 2000381b \ Timing3 + pair: 00000005 3023009d \ Timing4 + pair: 00000006 00110142 \ Timing5 + pair: 00000007 00005000 \ Cntrl1 + pair: 00000008 00080000 \ Cntrl2 + pair: 00000009 c0000000 \ Cntrl3 + pair: 0000000a 20c08115 \ Cntrl4 + pair: 0000000b 01010101 \ Cntrl5-arb + pair: 0000000c 00000000 \ Cntrl6-odt + pair: 0000000d 03000000 \ Cntrl7-odt + pair: 0000000e 00000000 \ mcb_cntrl1 + pair: 0000000f 20004433 \ phy-cntrl3 + pair: 00000010 13300559 \ phy-cntrl7 + pair: 00000011 03300770 \ phy_cntrl8 + pair: 00000012 00000077 \ phy-cntrl9 + pair: 00000013 00000000 \ phy_cntrl11 + pair: 00000014 20000088 \ phy-cntrl13 + pair: 00000015 80000000 \ phy_cntrl14 + pair: 00000016 00000080 \ dll-ctrl1 + pair: 00000017 00000080 \ dll_ctrl2 + pair: 00000018 00000080 \ dll-ctrl3 + pair: 00000019 000b0001 \ mmap0 + pair: 0000001a 080b0001 \ mmap1 + pair: 0000001b 00000000 \ user_cmd0 + end-package + cmcc: + pair: 0 0 \ config-ena? false + pair: 1 0 \ memtest? false + end-package
Added: cpu/arm/mmp2/ntim_mmp2_nand_cforth_ddr_elpida_512m.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/ntim_mmp2_nand_cforth_ddr_elpida_512m.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,19 @@ +\ Marvel Trusted Image Module image creation script for +\ MMP2 platform with 512M of Elpida RAM +\ Running CForth from the security processor + +tim: 00030102 0 Sky! PXA688 +flash: NAN'6 +timh: TIMH 0 d1020000 +image: OBMI 400 0 dummy.img +image: WTMI 404 d1000000 /home/wmb/OLPC/1.75/cforth-from-0xc0000.img +reserved: + tbrx: 00020000 + transfer: TIMH d1020000 + end-package + fload ddr_elpida_512m.fth + term: +end-reserved +end-tim + +save-image: nand_cforth.img
Added: cpu/arm/mmp2/ntim_mmp2_nand_ofw_ddr_elpida_512m.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/ntim_mmp2_nand_ofw_ddr_elpida_512m.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,20 @@ +\ Marvel Trusted Image Module image creation script for +\ MMP2 platform with 512M of Elpida RAM +\ Running OFW using MMP2_JASPER_LOADER as an intermediate step + +tim: 00030102 0 Sky! PXA688 +flash: NAN'6 +timh: TIMH 0 d1020000 +image: OBMI 80000 0 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/MMP2_JASPER_LOADER_3_2_15.bin +image: WTMI c0000 d1000000 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/WtmUnresetPJ4.bin +image: OSLO 100000 100000 /home/wmb/ofw.test/cpu/arm/mmp2/build/ofw.rom +reserved: + tbrx: 00020000 + transfer: TIMH d1020000 + end-package + fload ddr_elpida_512m.fth + term: +end-reserved +end-tim + +save-image: nand_ofw.img
Added: cpu/arm/mmp2/ntim_mmp2_nand_ofwonly_ddr_elpida_512m.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/ntim_mmp2_nand_ofwonly_ddr_elpida_512m.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,17 @@ +\ Marvel Trusted Image Module image creation script for +\ MMP2 platform with 512M of Elpida RAM +\ Running OFW directly, with no intermediate loader + +tim: 00030102 0 Sky! PXA688 +flash: NAN'6 +timh: TIMH 0 d1020000 +image: WTMI 1000 d1000000 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/WtmUnresetPJ4.bin +image: OBMI 80000 0 /home/wmb/ofw.test/cpu/arm/mmp2/build/ofw.rom +reserved: + + fload ddr_elpida_512m.fth + term: +end-reserved +end-tim + +save-image: nand_ofwonly.img
Added: cpu/arm/mmp2/ntim_mmp2_nand_uboot_ddr_elpida_512m.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/ntim_mmp2_nand_uboot_ddr_elpida_512m.fth Fri Oct 8 08:31:34 2010 (r1964) @@ -0,0 +1,20 @@ +\ Marvel Trusted Image Module image creation script for +\ MMP2 platform with 512M of Elpida RAM +\ Running uboot + +tim: 00030102 0 Sky! PXA688 +flash: NAN'6 +timh: TIMH 0 d1020000 +image: OBMI 80000 0 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/MMP2_JASPER_LOADER_3_2_15.bin +image: WTMI c0000 d1000000 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/WtmUnresetPJ4.bin +image: OSLO 100000 100000 /c/Documents and Settings/Mitch Bradley/My Documents/OLPC/Marvell/alpha1_sdcard_update/u-boot.bin +reserved: + tbrx: 00020000 + transfer: TIMH d1020000 + end-package + fload ddr_elpida_512m.fth + term: +end-reserved +end-tim + +save-image: nand_from_forth.img