freemyipod r438 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r437‎ | r438 | r439 >
Date:23:21, 16 January 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Add memory allocation APIs to USB protocol, change some other commands as neccessary
Modified paths:
  • /emcore/trunk/arm/contextswitch.S (modified) (history)
  • /emcore/trunk/contextswitch.h (modified) (history)
  • /emcore/trunk/usb/usb.c (modified) (history)

Diff [purge]

Index: emcore/trunk/arm/contextswitch.S
@@ -151,11 +151,13 @@
152152 .global execfirmware
153153 .type execfirmware, %function
154154 execfirmware:
155 - str r0, [sp,#-4]!
 155+ stmfd sp!, {r0-r2}
156156 bl interrupt_shutdown
 157+ msr cpsr_c, #0xd3
 158+ ldmfd sp, {r0-r2}
 159+ bl memmove
157160 bl clean_dcache
158 - ldr r1, [sp], #4
159 - msr cpsr_c, #0xd3
 161+ ldr r1, [sp]
160162 mrc p15, 0, r0,c1,c0
161163 bic r0, r0, #5
162164 mcr p15, 0, r0,c1,c0
Index: emcore/trunk/usb/usb.c
@@ -81,7 +81,12 @@
8282 DBGACTION_HWKEYAES,
8383 DBGACTION_HMACSHA1,
8484 DBGACTION_TARGETSPECIFIC,
85 - DBGACTION_STORAGE
 85+ DBGACTION_STORAGE,
 86+ DBGACTION_MALLOC,
 87+ DBGACTION_MEMALIGN,
 88+ DBGACTION_REALLOC,
 89+ DBGACTION_REOWNALLOC,
 90+ DBGACTION_FREE
8691 };
8792
8893 static struct scheduler_thread dbgthread_handle IBSS_ATTR;
@@ -107,8 +112,8 @@
108113
109114 static const char dbgconoverflowstr[] = "\n\n[overflowed]\n\n";
110115
111 -extern int _initstart; // These aren't ints at all, but gcc complains about void types being
112 -extern int _sdramstart; // used here, and we only need the address, so just make it happy...
 116+extern int _poolstart; // These aren't ints at all, but gcc complains about void types being
 117+extern int _poolend; // used here, and we only need the address, so just make it happy...
113118
114119
115120 static struct usb_device_descriptor CACHEALIGN_ATTR device_descriptor =
@@ -373,8 +378,8 @@
374379 dbgsendbuf[3] = usb_drv_get_max_in_size();
375380 break;
376381 case 2: // GET USER MEMORY INFO
377 - dbgsendbuf[1] = (uint32_t)&_initstart;
378 - dbgsendbuf[2] = (uint32_t)&_sdramstart;
 382+ dbgsendbuf[1] = (uint32_t)&_poolstart;
 383+ dbgsendbuf[2] = (uint32_t)&_poolend;
379384 break;
380385 default:
381386 dbgsendbuf[0] = 2;
@@ -537,7 +542,7 @@
538543 dbgsendbuf[0] = 1;
539544 size = 16;
540545 break;
541 - case 19: // KILL THREAD
 546+ case 19: // CREATE THREAD
542547 dbgsendbuf[0] = 1;
543548 dbgsendbuf[1] = (uint32_t)thread_create(NULL, (const char*)(dbgsendbuf[1]),
544549 (const void*)(dbgsendbuf[2]),
@@ -573,6 +578,8 @@
574579 case 24: // EXECFIRMWARE
575580 if (set_dbgaction(DBGACTION_EXECFIRMWARE, 0)) break;
576581 dbgactionaddr = dbgrecvbuf[1];
 582+ dbgactionoffset = dbgrecvbuf[2];
 583+ dbgactionlength = dbgrecvbuf[3];
577584 break;
578585 #ifdef HAVE_HWKEYAES
579586 case 25: // HWKEYAES
@@ -623,6 +630,29 @@
624631 memcpy(dbgasyncsendbuf, dbgrecvbuf, sizeof(dbgasyncsendbuf));
625632 break;
626633 #endif
 634+ case 52: // MALLOC
 635+ if (set_dbgaction(DBGACTION_MALLOC, 0)) break;
 636+ dbgactionlength = dbgrecvbuf[1];
 637+ break;
 638+ case 53: // MEMALIGN
 639+ if (set_dbgaction(DBGACTION_MEMALIGN, 0)) break;
 640+ dbgactionoffset = dbgrecvbuf[1];
 641+ dbgactionlength = dbgrecvbuf[2];
 642+ break;
 643+ case 54: // REALLOC
 644+ if (set_dbgaction(DBGACTION_REALLOC, 0)) break;
 645+ dbgactionaddr = dbgrecvbuf[1];
 646+ dbgactionlength = dbgrecvbuf[2];
 647+ break;
 648+ case 55: // REOWNALLOC
 649+ if (set_dbgaction(DBGACTION_REOWNALLOC, 0)) break;
 650+ dbgactionaddr = dbgrecvbuf[1];
 651+ dbgactionoffset = dbgrecvbuf[2];
 652+ break;
 653+ case 56: // FREE
 654+ if (set_dbgaction(DBGACTION_FREE, 0)) break;
 655+ dbgactionaddr = dbgrecvbuf[1];
 656+ break;
627657 default:
628658 dbgsendbuf[0] = 2;
629659 size = 16;
@@ -712,7 +742,8 @@
713743 shutdown(false);
714744 dbgasyncsendbuf[0] = 1;
715745 usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
716 - execfirmware((void*)dbgactionaddr);
 746+ execfirmware((void*)dbgactionaddr, (void*)dbgactionoffset,
 747+ (size_t)dbgactionlength);
717748 #ifdef HAVE_BOOTFLASH
718749 case DBGACTION_READBOOTFLASH:
719750 bootflash_readraw((void*)dbgactionaddr, dbgactionoffset, dbgactionlength);
@@ -912,6 +943,33 @@
913944 }
914945 break;
915946 #endif
 947+ case DBGACTION_MALLOC:
 948+ dbgasyncsendbuf[0] = 1;
 949+ dbgasyncsendbuf[1] = (uint32_t)malloc((size_t)dbgactionlength);
 950+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 951+ break;
 952+ case DBGACTION_MEMALIGN:
 953+ dbgasyncsendbuf[0] = 1;
 954+ dbgasyncsendbuf[1] = (uint32_t)memalign((size_t)dbgactionoffset,
 955+ (size_t)dbgactionlength);
 956+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 957+ break;
 958+ case DBGACTION_REALLOC:
 959+ dbgasyncsendbuf[0] = 1;
 960+ dbgasyncsendbuf[1] = (uint32_t)realloc((void*)dbgactionaddr,
 961+ (size_t)dbgactionlength);
 962+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 963+ break;
 964+ case DBGACTION_REOWNALLOC:
 965+ dbgasyncsendbuf[0] = 1;
 966+ reownalloc((void*)dbgactionaddr, (void*)dbgactionoffset);
 967+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 968+ break;
 969+ case DBGACTION_FREE:
 970+ dbgasyncsendbuf[0] = 1;
 971+ free((void*)dbgactionaddr);
 972+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 973+ break;
916974 }
917975 dbgaction = DBGACTION_IDLE;
918976 }
Index: emcore/trunk/contextswitch.h
@@ -33,7 +33,7 @@
3434 void resume_thread(void) __attribute__((noreturn)) ICODE_ATTR;
3535 uint32_t enter_critical_section(void) ICODE_ATTR;
3636 void leave_critical_section(uint32_t mode) ICODE_ATTR;
37 -void execfirmware(void* addr) ICODE_ATTR;
 37+void execfirmware(void* dest, void* src, size_t size) ICODE_ATTR;
3838
3939
4040 #endif