commit f9f1f12c2fc28e91f0cb2fef8884b01ff308ea16
parent d70ccf3a31b73ea7f5670ab9c721c21cc8dfab0d
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 16 Jun 2023 11:28:39 -0400
rpi: EMMC can read a sector!
After having done "emmc$", you can do something like "0 here block@" and then
dump your memory to see that the first block from the image passed through the
"-sd" flag was loaded.
This only works on QEMU, proper flag waits aren't done yet.
Diffstat:
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/drv/rpi/emmc.fs b/fs/drv/rpi/emmc.fs
@@ -14,7 +14,8 @@ $80000000 const ACMD41_COMPLETE
0 value rca \ RCA of current card
-: # not if abort" EMMC error" then ;
+: err abort" EMMC error" ;
+: # not if err then ;
: delay ( n -- ) begin 1- ?dup not until ;
: delayus ( us -- ) 1000 * delay ; \ TODO: use actual timer
: status ( mask -- f ) \ f=1 if things are ok
@@ -24,14 +25,25 @@ $80000000 const ACMD41_COMPLETE
1 delayus next drop 0 then ( f ) ;
: cmdwait 1 status # ; \ CMD_INHIBIT mask
: datawait 2 status # ; \ DAT_INHIBIT mask
-: cmd ( arg cmdidx -- ) cmdwait swap EMMC_ARG1 ! EMMC_CMDTM ! ;
+: intwait ( mask -- )
+ INT_ERROR_MASK or $10000 for
+ EMMC_INTERRUPT @ over and if break then 1 delayus next err then
+ EMMC_INTERRUPT @ INT_ERROR_MASK and not #
+ ( mask ) EMMC_INTERRUPT ! ;
+: cmddone 1 intwait ; \ INT_CMD_DONE
+: cmd ( arg cmdidx -- ) cmdwait swap EMMC_ARG1 ! EMMC_CMDTM ! ( cmddone ) ;
: acmd ( arg cmdidx -- ) 0 $37020000 cmd ( CMD55 ) 100 delayus cmd ;
: cmd0 0 0 cmd ; \ CMD_GO_IDLE
: cmd2 0 $02010000 cmd ; \ CMD_ALL_SEND_CID
: cmd3 ( -- rca ) 0 $03010000 cmd EMMC_RESP0 @ ; \ CMD_SEND_REL_ADDR
: cmd7 ( rca -- ) $07030000 cmd ;
: cmd8 ( arg -- ) $08020000 cmd 1000 delayus ; \ CMD_SEND_IF_COND
+: cmd17 ( lba -- ) $11220010 cmd ;
: acmd41 ( arg -- resp ) $29020000 acmd 1000 delayus EMMC_RESP0 @ ;
+: block@ ( lba dst -- )
+ datawait $00010200 EMMC_BLKSIZECNT !
+ swap cmd17 1000 delayus \ TODO: wait properly, but I can't make it work...
+ $200 >> >> for EMMC_DATA @ swap !+ next ;
: emmc$
$01000005 EMMC_CONTROL1 ! \ reset and enable clocks
cmd0 $1aa cmd8 6 for