-
-static DWORD ExpectedAddr;
-static BYTE QueuedToSend[256];
-static BOOL AllWritten;
-#define PHYSICAL_FLASH_START 0x100000
-
-struct partition {
- int start;
- int end;
- int precious;
- const char *name;
-};
-struct partition partitions[] = {
- {0x100000, 0x102000, 1, "bootrom"},
- {0x102000, 0x110000, 0, "fpga"},
- {0x110000, 0x140000, 0, "os"},
-};
-
-/* If translate is set, subtract PHYSICAL_FLASH_START to translate for old
- * bootroms.
- */
-static void FlushPrevious(int translate)
-{
- UsbCommand c;
- memset(&c, 0, sizeof(c));
-
- printf("expected = %08x flush, ", ExpectedAddr);
-
- int i;
- for(i = 0; i < 240; i += 48) {
- c.cmd = CMD_SETUP_WRITE;
- memcpy(c.d.asBytes, QueuedToSend+i, 48);
- c.ext1 = (i/4);
- SendCommand(&c, TRUE);
- }
-
- c.cmd = CMD_FINISH_WRITE;
- c.ext1 = (ExpectedAddr-1) & (~255);
- if(translate) {
- c.ext1 -= PHYSICAL_FLASH_START;
- }
- printf("c.ext1 = %08x\r", c.ext1);
- memcpy(c.d.asBytes, QueuedToSend+240, 16);
- SendCommand(&c, TRUE);
-
- AllWritten = TRUE;
-}
-
-/* Where must be between start_addr (inclusive) and end_addr (exclusive).
- */
-static void GotByte(DWORD where, BYTE which, int start_addr, int end_addr, int translate)
-{
- AllWritten = FALSE;
-
- if(where < start_addr || where >= end_addr) {
- printf("bad: got byte at %08x, outside of range %08x-%08x\n", where, start_addr, end_addr);
- exit(-1);
- }
-
- if(where != ExpectedAddr) {
- printf("bad: got at %08x, expected at %08x\n", where, ExpectedAddr);
- exit(-1);
- }
- QueuedToSend[where & 255] = which;
- ExpectedAddr++;
-
- if((where & 255) == 255) {
- // we have completed a full page
- FlushPrevious(translate);
- }
+#include "util.h"
+#include "util_posix.h"
+#include "flash.h"
+#include "comms.h"
+#include "usb_cmd.h"
+
+
+void cmd_debug(UsbCommand* UC) {
+ // Debug
+ printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand));
+ printf(" cmd[len=%zd]: %016" PRIx64 "\n",sizeof(UC->cmd),UC->cmd);
+ printf(" arg0[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[0]),UC->arg[0]);
+ printf(" arg1[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[1]),UC->arg[1]);
+ printf(" arg2[len=%zd]: %016" PRIx64 "\n",sizeof(UC->arg[2]),UC->arg[2]);
+ printf(" data[len=%zd]: ",sizeof(UC->d.asBytes));
+ for (size_t i=0; i<16; i++) {
+ printf("%02x",UC->d.asBytes[i]);
+ }
+ printf("...\n");