Changeset 12
- Timestamp:
- May 23, 2008, 12:59:00 PM (16 years ago)
- Location:
- tt-loader
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
tt-loader/2nd/Makefile
r11 r12 11 11 12 12 S_SRCS = start.S 13 C_SRCS = main.c usb.c 13 C_SRCS = main.c usb.c crc32.c 14 14 SRCS = $(S_SRCS) $(C_SRCS) 15 15 -
tt-loader/2nd/config.h
r11 r12 26 26 #define _CONFIG_H_ 27 27 28 // Default address in SRAM 28 // Default Linux commandline 29 #define KERNEL_CMDLINE "mem=64M console=ttyS0,115200 noinitrd root=/dev/mtdblock_bbs5" 30 31 // Default address in SRAM & RAM 32 #define RAM_SIZE 0x04000000 // 64M 33 #define CFG_BASESDRAM 0x10000000 29 34 #define CFG_LOADADDR 0x20000400 35 #define CFG_PARAMADDR CFG_BASESDRAM+0x100 36 #define INITRD_LOAD_ADDR 0x00800000 37 #define INITRD_SIZE 0x00000000 30 38 31 39 // Address to find jtag id, to check on which target we are running -
tt-loader/2nd/main.c
r11 r12 4 4 * Copyright (C) 2008 Guillaume Bougard <gbougard@pkg.fr> 5 5 * Copyright (C) 2005 Luis Recuerda <lrec@helios.homeip.net> 6 * 7 * ARM kernel loader. Adapt from qemu-neo1973 8 * Copyright (c) 2006-2007 CodeSourcery. 9 * Written by Paul Brook 6 10 * 7 11 * This program is free software; you can redistribute it and/or … … 24 28 #include "usb.h" 25 29 26 #define _LSR_ ((volatile u8 *) 0xfffb0014) 27 #define _THR_ ((volatile u8 *) 0xfffb0000) 28 #define _RHR_ ((volatile u8 *) 0xfffb0000) 29 30 #define MEM_READ_SIZE 32 30 extern u32 crc32( u32 crc, char* buf, u32 len, crc_cb_fnc_t* cb); 31 32 /* 33 * Length of memory dump done by 2nd.bin, must be a multiple of DUMP_LINE_SIZE from host main.c 34 * Must also be sufficient to output lines of text, let's say 128 bytes 35 */ 36 #define MEM_READ_SIZE 128*32 37 #define CHUNK_SIZE 8192 31 38 32 39 static char *usb_hdr = "TIS" ; 33 static char usb_outbuffer[64]; 34 35 // limited strcpy 40 static char usb_outbuffer[MEM_READ_SIZE+4]; 41 36 42 static u32 strcpy ( char *dest, char *src ) 37 43 { … … 39 45 char *tmp = dest, *s = src; 40 46 41 while ( ++count < 256&& *s != '\0' )47 while ( ++count < MEM_READ_SIZE && *s != '\0' ) 42 48 *tmp++ = *s++ ; 43 49 … … 45 51 46 52 return count ; 53 } 54 55 static u32 strlen ( char *src ) 56 { 57 u32 len = 0 ; 58 59 while ( *src != '\0' ) { 60 src++ ; 61 len ++ ; 62 } 63 64 return len ; 47 65 } 48 66 … … 56 74 57 75 return count ; 58 }59 60 static void bsend (char ch)61 {62 while (!((*_LSR_) & 0x20));63 *_THR_= ch;64 }65 66 static inline int check_serial (void) { return (*_LSR_) & 0x01; }67 68 static char brecv (void)69 {70 while (!((*_LSR_) & 0x01));71 return *_RHR_;72 }73 74 char crecv (void)75 {76 return brecv ();77 }78 79 void csend (char ch)80 {81 if (ch == '\n')82 bsend ('\r');83 bsend (ch);84 }85 86 void tsend (const char *text)87 {88 while (*text)89 csend (*text++);90 }91 92 void xsend (unsigned value)93 {94 if (value < 10)95 bsend (value + '0');96 else97 bsend (value + ('A'-10));98 }99 100 void x8send (u8 value)101 {102 xsend (value >> 4);103 xsend (value & 0xf);104 }105 106 void x16send (u16 value)107 {108 int i;109 for (i= 0; i < 4; ++i)110 {111 xsend (value >> 12);112 value<<= 4;113 }114 }115 116 void x32send (u32 value)117 {118 int i;119 for (i= 0; i < 8; ++i)120 {121 xsend (value >> 28);122 value<<= 4;123 }124 76 } 125 77 … … 181 133 } 182 134 135 // stl_raw is qemu related 136 #define stl_raw(x,v) *(u32 *)(x) = v 137 static void set_kernel_args(u32 ram_size, int initrd_size, const char *kernel_cmdline, u32 ram_start) 138 { 139 u32 *p; 140 141 // Set pointer to kernel params 142 p = (u32 *)(CFG_PARAMADDR); 143 144 /* ATAG_CORE */ 145 stl_raw(p++, 5); 146 stl_raw(p++, 0x54410001); 147 stl_raw(p++, 0); // 0 = ro ; 1= rw 148 stl_raw(p++, 0x1000); // Page size 149 stl_raw(p++, 0); // root device overrided by cmdline 150 /* ATAG_MEM */ 151 stl_raw(p++, 4); 152 stl_raw(p++, 0x54410002); 153 stl_raw(p++, ram_size); 154 stl_raw(p++, ram_start); 155 if (initrd_size) { 156 /* ATAG_INITRD2 */ 157 stl_raw(p++, 4); 158 stl_raw(p++, 0x54420005); 159 stl_raw(p++, ram_start + INITRD_LOAD_ADDR); 160 stl_raw(p++, initrd_size); 161 } 162 if (kernel_cmdline && *kernel_cmdline) { 163 /* ATAG_CMDLINE */ 164 int cmdline_size; 165 166 cmdline_size = strlen((char *)kernel_cmdline); 167 memcpy ((char *)p + 2, (char *)kernel_cmdline, cmdline_size + 1); 168 cmdline_size = (cmdline_size >> 2) + 1; 169 stl_raw(p++, cmdline_size + 2); 170 stl_raw(p++, 0x54410009); 171 p += cmdline_size; 172 } 173 /* ATAG_END */ 174 stl_raw(p++, 0); 175 stl_raw(p++, 0); 176 } 177 178 #define C1_DC (1<<2) /* dcache off/on */ 179 #define C1_IC (1<<12) /* icache off/on */ 180 181 void cleanup_before_linux (void) 182 { 183 /* 184 * this function is called just before we call linux 185 * it prepares the processor for linux 186 * 187 * we turn off caches etc ... 188 */ 189 190 unsigned long i; 191 192 /* turn off I/D-cache */ 193 asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i)); 194 i &= ~(C1_DC | C1_IC); 195 asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i)); 196 197 /* flush I/D-cache */ 198 i = 0; 199 asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i)); 200 } 201 202 void usb_crc32_pos( u32 pos, u32 total, u32 crc ) 203 { 204 u32 len = strcpy(usb_outbuffer,usb_hdr); 205 usb_outbuffer[len-1] = 'x' ; 206 (*(u32 *)(usb_outbuffer+len)) = pos ; 207 len += sizeof(u32); 208 (*(u32 *)(usb_outbuffer+len)) = total ; 209 len += sizeof(u32); 210 (*(u32 *)(usb_outbuffer+len)) = crc ; 211 len += sizeof(u32); 212 usb_send ( usb_outbuffer, len ); 213 while (!usb_sent ()); 214 } 215 183 216 u32 _main (void) 184 217 { 218 u32 params = CFG_PARAMADDR ; 185 219 u32 address = CFG_LOADADDR ; 220 u32 crc = 0 ; 186 221 usb_msg ('m', "In omap plateform"); 187 222 … … 205 240 u32 total, cmd, index = 0 ; 206 241 207 u8 usb_inbuffer[ 64];242 u8 usb_inbuffer[CHUNK_SIZE]; 208 243 usb_recv (usb_inbuffer, sizeof (usb_inbuffer)); 209 244 while (!usb_rcvd ()); … … 239 274 240 275 } else 276 if ((char)cmd == 'C') // set crc32 value for next download 277 { 278 crc = *(u32 *) &usb_inbuffer[index]; 279 usb_code ('i', crc); 280 281 } else 282 if ((char)cmd == 'm') // Download size from memory 283 { 284 total= *(u32 *) &usb_inbuffer[index]; 285 u32 size = 0; 286 287 usb_code ('I', total); 288 289 // Check crc32 if it has been set 290 if (total && crc) 291 { 292 crc_cb_fnc_t* cb = NULL ; 293 if (total>1024*1024) 294 cb = &usb_crc32_pos ; 295 u32 foundcrc = crc32(0, (char *)address,total,cb) ; 296 usb_code ('C', foundcrc); 297 // Skip download on crc match 298 if (foundcrc == crc) 299 total = 0 ; 300 } 301 302 if (total == 0) 303 usb_blk ('D', (char *)address, 0); 304 305 while (size < total) 306 { 307 u32 bs = MEM_READ_SIZE ; 308 if ( total - size < MEM_READ_SIZE) 309 bs = total - size ; 310 usb_blk ('D', (char *)address, bs); 311 address += bs ; 312 size += bs ; 313 } 314 315 // reset crc for next download anyway 316 crc = 0 ; 317 318 } else 319 if ((char)cmd == 'e') // End, just loop 320 { 321 usb_reset(); 322 323 } else 241 324 if ((char)cmd == 'f') // load file ACK 242 325 { … … 256 339 257 340 } else 341 if ((char)cmd == 'p') // do a poke on address 342 { 343 u32 size = memcpy( (char *) address, (char *) &usb_inbuffer[index], 4); 344 address += size ; 345 usb_code ('i', address ); 346 347 } else 348 if ((char)cmd == 'P') // do a peek on address 349 { 350 usb_code ('i', *(u32 *) address ); 351 address += 4 ; 352 353 } else 258 354 if ((char)cmd == 'c') // call command 259 355 { 260 index = ((u32_fnc_t *)address)(); 356 __asm__ __volatile__ ( 357 "mov r0, #0 ;" 358 "mov r1, #0 ;" 359 "mov r2, #0 ;" 360 "ldr r3, %1 ;" 361 "blx r3 ;" 362 "mov %0, r0 ;" 363 : "=r"(index) : "m"(address) : "r0", "r1", "r2", "r3" 364 ); 261 365 usb_code ('i', index); 262 366 … … 265 369 { 266 370 usb_code ('b', address ); 267 // Just return the address where is store the branch to do 268 u32 bootaddress = (u32) &address ; // Convert/cast address just to avoid gcc warning 269 return bootaddress ; 371 usb_reset(); 372 __asm__ __volatile__ ( 373 "ldr r0, %0 ;" 374 "mov pc, r0 ;" 375 : : "m"(address) 376 ); 377 378 } else 379 if ((char)cmd == 'k') // boot kernel command 380 { 381 int machid = * (int *) &usb_inbuffer[index]; 382 usb_code ('I', machid); 383 set_kernel_args( RAM_SIZE, INITRD_SIZE, KERNEL_CMDLINE, CFG_BASESDRAM ); 384 usb_code ('b', address ); 385 usb_reset(); 386 cleanup_before_linux(); 387 __asm__ __volatile__ ( 388 "mov r0, #0 ;" 389 "ldr r1, %0 ;" 390 "ldr r2, %1 ;" 391 "mov r3, #0 ;" 392 "mov r4, #0 ;" 393 "ldr r5, %2 ;" 394 "mov pc, r5 ;" 395 : : "m" (machid), "m"(params), "m"(address) 396 ); 397 } else 398 if ((char)cmd == 'S') // Stack command 399 { 400 __asm__ __volatile__ ( 401 "ldr fp, %0 ;" 402 "sub fp, #4 ;" 403 "mov sp, fp ;" 404 "sub sp, #256 ;" 405 : : "m"(address) 406 ); 407 usb_code ('i', address); 408 270 409 } 271 410 } -
tt-loader/2nd/start.S
r11 r12 102 102 .extern _main 103 103 bl _main 104 ldr pc, [r0] // Branch to content of mem returned as boot command105 106 104 107 105 WSPR_VAL1: -
tt-loader/2nd/types.h
r11 r12 32 32 typedef u32 (u32_fnc_t) (void); 33 33 typedef void (init_fnc_t) (void); 34 typedef void (crc_cb_fnc_t) (u32,u32,u32); 34 35 35 36 #endif -
tt-loader/2nd/usb.c
r11 r12 261 261 return result; 262 262 } 263 264 void usb_reset() 265 { 266 USBS_SYSCON1 &= ~_PULLUP_EN ; 267 USBS_SYSCON1 |= _PULLUP_EN ; 268 } -
tt-loader/2nd/usb.h
r11 r12 31 31 int usb_rcvd (void); 32 32 33 void usb_ debug(void);33 void usb_reset (void); 34 34 35 35 #endif -
tt-loader/Makefile
r11 r12 5 5 LDFLAGS = -g $(LIBS) 6 6 APP_NAME = tt-loader 7 APP_VERSION = 0. 17 APP_VERSION = 0.2 8 8 9 9 # Adapt this to your system … … 11 11 DIS_ADDR ?= 0 12 12 13 OBJS = main.o 13 # You can overide the name of the extracted MTD partition to get the kernel 14 KERNEL_MTD ?= mtd4 15 16 OBJS = main.o crc32.o 14 17 15 18 all: $(APP_NAME) … … 36 39 rm -f $(@F).elf 37 40 41 # Extract kernel from mtd4 nand partition extraction 42 kernel.bin: $(KERNEL_MTD) 43 ./kernel-extract.sh $^ $@ 44 38 45 .PHONY: all clean 2nd -
tt-loader/commands.txt
r11 r12 1 //////// X-LOAD 2 // Load x-load in the phone 1 /////////////////////////////////////////////////////////////////// READNAND 2 # ----------------------------------------- 3 # Init phone RAM 3 4 a 0x20010000 4 // Check README to generate x-load.bin5 5 f x-load.bin 6 7 // Boot with x-load 8 a 0x20010c00 9 b 10 6 // Call a sub from x-load.bin: TT BoardInit (should only work with TT) 7 a 0x20010da4 8 c 9 10 # ----------------------------------------- 11 # Upload FlashWriteNAND.bin program 12 a 0x10000000 13 f FlashWriteNAND.bin 14 15 # ----------------------------------------- 16 # ------------------X-LOAD----------------- 17 # ----------------------------------------- 18 # Setup read command for x-load.bin 19 a 0x1000ffec 20 p 0x00000003 21 p 0x10010000 22 p 0x00000000 23 p 0x00004000 24 p 0x00000000 25 26 // Just peek to control command is set as expected 27 a 0x1000ffec 28 P;P;P;P;P 29 30 # ----------------------------------------- 31 # Call FlashWriteNAND program 32 a 0x10000000 33 c 34 35 # ----------------------------------------- 36 # Setup file to be updated 37 F /lib/firmware/tt-x-load.bin 38 C 0 39 40 # ----------------------------------------- 41 # Download phone memory into local buffer 42 a 0x10010000 43 m 16 44 45 # ----------------------------------------- 46 # Save the local buffer into a file 47 D 48 49 # ----------------------------------------- 50 # ------------------U-BOOT----------------- 51 # ----------------------------------------- 52 # Setup read command for u-boot.bin 53 a 0x1000ffec 54 p 0x00000000 55 p 0x10010000 56 p 0x00004000 57 p 0x00030000 58 p 0x00000000 59 60 // Just peek to control command is set as expected 61 a 0x1000ffec 62 P;P;P;P;P 63 64 # ----------------------------------------- 65 # Call FlashWriteNAND program 66 a 0x10000000 67 c 68 69 # ----------------------------------------- 70 # Setup file to be updated 71 F /lib/firmware/tt-u-boot.bin 72 C 0 73 74 # ----------------------------------------- 75 # Download firmware to local file 76 a 0x10010000 77 m 192 78 D 79 80 # ----------------------------------------- 81 # ------------------UNUSED----------------- 82 # ----------------------------------------- 83 # Setup read command for u-boot-params.bin 84 a 0x1000ffec 85 p 0x00000000 86 p 0x10010000 87 p 0x00034000 88 p 0x00020000 89 p 0x00000000 90 91 // Just peek to control command is set as expected 92 a 0x1000ffec 93 P;P;P;P;P 94 95 # ----------------------------------------- 96 # Call FlashWriteNAND program 97 a 0x10000000 98 c 99 100 # ----------------------------------------- 101 # Setup file to be updated 102 F /lib/firmware/tt-u-boot-params.bin 103 C 0 104 105 # ----------------------------------------- 106 # Download firmware to local file 107 a 0x10010000 108 m 128 109 D 110 111 # ----------------------------------------- 112 # ------------------SPLASH----------------- 113 # ----------------------------------------- 114 # Setup read command for splash.bin 115 a 0x1000ffec 116 p 0x00000000 117 p 0x10010000 118 p 0x00054000 119 p 0x0002c000 120 p 0x00000000 121 122 // Just peek to control command is set as expected 123 a 0x1000ffec 124 P;P;P;P;P 125 126 # ----------------------------------------- 127 # Call FlashWriteNAND program 128 a 0x10000000 129 c 130 131 # ----------------------------------------- 132 # Setup file to be updated 133 F /lib/firmware/tt-splash.bin 134 C 0 135 136 # ----------------------------------------- 137 # Download firmware to local file 138 a 0x10010000 139 m 176 140 D 141 142 # ----------------------------------------- 143 # ------------------KERNEL----------------- 144 # ----------------------------------------- 145 # Setup read command for uImage.bin 146 a 0x1000ffec 147 p 0x00000000 148 p 0x10010000 149 p 0x00080000 150 p 0x00100000 151 p 0x00000000 152 153 // Just peek to control command is set as expected 154 a 0x1000ffec 155 P;P;P;P;P 156 157 # ----------------------------------------- 158 # Call FlashWriteNAND program 159 a 0x10000000 160 c 161 162 # ----------------------------------------- 163 # Setup file to be updated 164 F /lib/firmware/tt-uImage.bin 165 C 0 166 167 # ----------------------------------------- 168 # Download firmware to local file 169 a 0x10010000 170 m 1024 171 D 172 173 # ----------------------------------------- 174 # ------------------ROOTFS----------------- 175 # ----------------------------------------- 176 # Setup read command for rootfs.raw 177 a 0x1000ffec 178 p 0x00000000 179 p 0x10010000 180 p 0x00180000 181 p 0x00590000 182 p 0x00000000 183 184 // Just peek to control command is set as expected 185 a 0x1000ffec 186 P;P;P;P;P 187 188 # ----------------------------------------- 189 # Call FlashWriteNAND program 190 a 0x10000000 191 c 192 193 # ----------------------------------------- 194 # Setup file to be updated 195 F /lib/firmware/tt-rootfs.raw 196 C 0 197 198 # ----------------------------------------- 199 # Download firmware to local file 200 a 0x10010000 201 m 5696 202 D 203 204 # ----------------------------------------- 205 # ------------------E28-FS----------------- 206 # ----------------------------------------- 207 # Setup read command for e28fs.raw 208 a 0x1000ffec 209 p 0x00000000 210 p 0x10010000 211 p 0x00710000 212 p 0x01200000 213 p 0x00000000 214 215 // Just peek to control command is set as expected 216 a 0x1000ffec 217 P;P;P;P;P 218 219 # ----------------------------------------- 220 # Call FlashWriteNAND program 221 a 0x10000000 222 c 223 224 # ----------------------------------------- 225 # Setup file to be updated 226 F /lib/firmware/tt-e28fs.raw 227 C 0 228 229 # ----------------------------------------- 230 # Download firmware to local file 231 a 0x10010000 232 m 18432 233 D 234 235 # ----------------------------------------- 236 # ------------------RSC-FS----------------- 237 # ----------------------------------------- 238 # Setup read command for resource.raw 239 a 0x1000ffec 240 p 0x00000000 241 p 0x10010000 242 p 0x01910000 243 p 0x00500000 244 p 0x00000000 245 246 // Just peek to control command is set as expected 247 a 0x1000ffec 248 P;P;P;P;P 249 250 # ----------------------------------------- 251 # Call FlashWriteNAND program 252 a 0x10000000 253 c 254 255 # ----------------------------------------- 256 # Setup file to be updated 257 F /lib/firmware/tt-resource.raw 258 C 0 259 260 # ----------------------------------------- 261 # Download firmware to local file 262 a 0x10010000 263 m 5120 264 D 265 266 # ----------------------------------------- 267 # ------------------USERFS----------------- 268 # ----------------------------------------- 269 # Setup read command for user_jffs2.raw 270 a 0x1000ffec 271 p 0x00000000 272 p 0x10010000 273 p 0x01e10000 274 p 0x00dc0000 275 p 0x00000000 276 277 // Just peek to control command is set as expected 278 a 0x1000ffec 279 P;P;P;P;P 280 281 # ----------------------------------------- 282 # Call FlashWriteNAND program 283 a 0x10000000 284 c 285 286 # ----------------------------------------- 287 # Setup file to be updated 288 F /lib/firmware/tt-user_jffs2.raw 289 C 0 290 291 # ----------------------------------------- 292 # Download firmware to local file 293 a 0x10010000 294 m 14080 295 D 296 297 # ----------------------------------------- 298 # -----------------RESERVE----------------- 299 # ----------------------------------------- 300 # Setup read command for reserve.raw 301 a 0x1000ffec 302 p 0x00000000 303 p 0x10010000 304 p 0x02bd0000 305 p 0x01200000 306 p 0x00000000 307 308 // Just peek to control command is set as expected 309 a 0x1000ffec 310 P;P;P;P;P 311 312 # ----------------------------------------- 313 # Call FlashWriteNAND program 314 a 0x10000000 315 c 316 317 # ----------------------------------------- 318 # Setup file to be updated 319 F /lib/firmware/tt-reserve.raw 320 C 0 321 322 # ----------------------------------------- 323 # Download firmware to local file 324 a 0x10010000 325 m 18432 326 D 327 328 # ----------------------------------------- 329 # ------------------PART1------------------ 330 # ----------------------------------------- 331 # Setup read command for part1.raw 332 a 0x1000ffec 333 p 0x00000000 334 p 0x10010000 335 p 0x03dd0000 336 p 0x00008000 337 p 0x00000000 338 339 // Just peek to control command is set as expected 340 a 0x1000ffec 341 P;P;P;P;P 342 343 # ----------------------------------------- 344 # Call FlashWriteNAND program 345 a 0x10000000 346 c 347 348 # ----------------------------------------- 349 # Setup file to be updated 350 F /lib/firmware/tt-part1.raw 351 C 0 352 353 # ----------------------------------------- 354 # Download firmware to local file 355 a 0x10010000 356 m 32 357 D 358 359 # ----------------------------------------- 360 # ------------------PART2------------------ 361 # ----------------------------------------- 362 # Setup read command for part2.raw 363 a 0x1000ffec 364 p 0x00000000 365 p 0x10010000 366 p 0x03dd8000 367 p 0x00008000 368 p 0x00000000 369 370 // Just peek to control command is set as expected 371 a 0x1000ffec 372 P;P;P;P;P 373 374 # ----------------------------------------- 375 # Call FlashWriteNAND program 376 a 0x10000000 377 c 378 379 # ----------------------------------------- 380 # Setup file to be updated 381 F /lib/firmware/tt-part2.raw 382 C 0 383 384 # ----------------------------------------- 385 # Download firmware to local file 386 a 0x10010000 387 m 32 388 D 389 390 # ----------------------------------------- 391 # ------------------GSMFS------------------ 392 # ----------------------------------------- 393 # Setup read command for gsmfs.raw 394 a 0x1000ffec 395 p 0x00000000 396 p 0x10010000 397 p 0x03de0000 398 p 0x00020000 399 p 0x00000000 400 401 // Just peek to control command is set as expected 402 a 0x1000ffec 403 P;P;P;P;P 404 405 # ----------------------------------------- 406 # Call FlashWriteNAND program 407 a 0x10000000 408 c 409 410 # ----------------------------------------- 411 # Setup file to be updated 412 F /lib/firmware/tt-gsmfs.raw 413 C 0 414 415 # ----------------------------------------- 416 # Download firmware to local file 417 a 0x10010000 418 m 128 419 D 420 421 # ----------------------------------------- 422 # -----------------GSMCODE----------------- 423 # ----------------------------------------- 424 # Setup read command for gsm_code.raw 425 a 0x1000ffec 426 p 0x00000000 427 p 0x10010000 428 p 0x03e00000 429 p 0x00200000 430 p 0x00000000 431 432 // Just peek to control command is set as expected 433 a 0x1000ffec 434 P;P;P;P;P 435 436 # ----------------------------------------- 437 # Call FlashWriteNAND program 438 a 0x10000000 439 c 440 441 # ----------------------------------------- 442 # Setup file to be updated 443 F /lib/firmware/tt-gsm_code.raw 444 C 0 445 446 # ----------------------------------------- 447 # Download firmware to local file 448 a 0x10010000 449 m 2048 450 D 451 452 # ----------------------------------------- 11 453 end 12 /////////////////////////////////////////////////////////////////// X-LOAD END454 /////////////////////////////////////////////////////////////////// READNAND END 13 455 14 456 /////////////////////////////////////////////////////////////////// U-BOOT … … 23 465 24 466 // Load another program to a new address, check README to generate u-boot.bin 467 a 0x11080000 468 f u-boot.usb 469 470 a 0x10000000 471 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 1ko 472 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 2ko 473 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 3ko 474 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 4ko 475 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 5ko 476 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 6ko 477 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 7ko 478 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 8ko 479 480 a 0x1103F800 481 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 1ko 482 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 2ko 483 484 // dump depuis _bss_start 485 //a 0x11098160 486 a 0x1029f300 487 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 1ko 488 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 2ko 489 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 3ko 490 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 4ko 491 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 5ko 492 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 6ko 493 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 7ko 494 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 8ko 495 496 // dump zone malloc 497 a 0x11060800 498 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 1ko 499 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 2ko 500 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 3ko 501 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 4ko 502 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 5ko 503 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 6ko 504 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 7ko 505 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 8ko 506 507 // Send u-boot start address and boot there 508 a 0x11080000 509 b 510 511 end 512 /////////////////////////////////////////////////////////////////// U-BOOT END 513 514 /////////////////////////////////////////////////////////////////// U-BOOT 515 # Booting TT with hosted u-boot 516 a 0x20010000 517 f x-load.bin 518 519 // Call a sub from x-load.bin: TT BoardInit (should only work with TT) 520 a 0x20010da4 521 c 522 523 // Load u-boot.bin 25 524 a 0x10280000 26 525 f u-boot.bin 27 28 // Send an address and dump the content to check upload has been done29 a 0x10299a5030 M;M;M;M;M;M;M;M31 526 32 527 // Send u-boot start address and boot there … … 37 532 /////////////////////////////////////////////////////////////////// U-BOOT END 38 533 534 /////////////////////////////////////////////////////////////////// X-LOAD 535 # Booting TT with hosted x-load 536 // Load x-load in the phone 537 a 0x20010000 538 // Check README to generate x-load.bin 539 f x-load.bin 540 541 // Boot with x-load 542 a 0x20010c00 543 b 544 545 end 546 /////////////////////////////////////////////////////////////////// X-LOAD END 547 39 548 /////////////////////////////////////////////////////////////////// DUMP MEM 40 549 // Send an address 41 550 a 0x20000000 42 551 43 // Dump 8kB from that address 44 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 512 octets 45 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 1ko 46 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 47 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 2ko 48 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 49 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 3ko 50 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 51 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 4ko 52 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 53 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 5ko 54 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 55 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 6ko 56 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 57 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 7ko 58 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 59 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M // 8ko 552 // Dump from that address 553 M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M 60 554 61 555 end -
tt-loader/main.c
r11 r12 33 33 #include <errno.h> 34 34 35 extern unsigned long crc32( unsigned long crc, char* buf, unsigned int len); 36 35 37 /* 36 38 * Here Vendor/Product detected for the target device … … 43 45 44 46 /* 45 * Length of memory dump done by 2nd.bin47 * Length of memory dump lines 46 48 */ 47 #define MEM_READ_SIZE 3249 #define DUMP_LINE_SIZE 32 48 50 49 51 struct mem_file { 50 52 void *content ; 51 53 int size ; 54 char *filename ; 52 55 }; 53 56 57 /* 58 * MAX_SIZE is the maximum size of the 2nd.bin program 59 */ 54 60 #define MAX_SIZE 65536 61 #define CHUNK_SIZE 8192 55 62 static char buffer[MAX_SIZE + 128]; 56 63 static int buffsize = 0; 57 static struct mem_file cmdfile = { NULL, 0 };64 static struct mem_file cmdfile = { NULL, 0, NULL }; 58 65 static double btime ; 59 66 static double ticks ; 60 67 61 68 #define log1(X) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks) 62 #define log2(X,Y) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,Y) 63 #define log3(X,Y,Z) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,Y,Z) 69 #define log2(X,Y) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y)) 70 #define log3(X,Y,Z) fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y),(Z)) 71 #define log4(W,X,Y,Z) fprintf(stderr, "%9.3f: "W,((double)times(NULL)-btime)/ticks,(X),(Y),(Z)) 64 72 65 73 #if __BYTE_ORDER == __LITTLE_ENDIAN … … 71 79 #endif 72 80 73 static inline unsigned do_div(unsigned v, unsigned d)81 static inline unsigned roundup (unsigned v, unsigned d) 74 82 { 75 83 v+= --d; … … 92 100 { 93 101 int res, len = 5 ; 94 char buffer[64];95 102 96 103 buffer[0]= 'T'; … … 101 108 if (src!=NULL) 102 109 len += stringcopy (&buffer[4], src, 60); 110 else 111 len = 4 ; 103 112 buffer[63]= '\0' ; // truncate anyway 104 113 … … 106 115 if (res < len) 107 116 { 108 fprintf (stderr,"Error in usb_bulk_write during send_char: %d/4\n", res);117 log2("Error in usb_bulk_write during send_char: %d/4\n", res); 109 118 return 0; 110 119 } … … 113 122 } 114 123 115 static int send_binsize (usb_dev_handle *handle, int s z)124 static int send_binsize (usb_dev_handle *handle, int size) 116 125 { 117 126 int res; 118 char buffer[8];119 127 buffer[0]= 'T'; 120 128 buffer[1]= 'I'; 121 129 buffer[2]= 'S'; 122 130 buffer[3]= 's'; 123 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( (sz>4096)?4096:sz);131 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( size < CHUNK_SIZE ? size : CHUNK_SIZE ); 124 132 125 133 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 126 134 if (res < 8) 127 135 { 128 fprintf (stderr,"Error in usb_bulk_write during send_binsize: %d/8\n", res);136 log2("Error in usb_bulk_write during send_binsize: %d/8\n", res); 129 137 return 0; 130 138 } … … 133 141 } 134 142 135 static int send_ address (usb_dev_handle *handle, int addr)143 static int send_word (usb_dev_handle *handle, const char req, int word) 136 144 { 137 145 int res; 138 char buffer[8];139 146 buffer[0]= 'T'; 140 147 buffer[1]= 'I'; 141 148 buffer[2]= 'S'; 142 buffer[3]= 'a';143 *(u_int32_t *) &buffer[4]= cpu_to_le32 ( addr);149 buffer[3]= req; 150 *(u_int32_t *) &buffer[4]= cpu_to_le32 (word); 144 151 145 152 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 146 153 if (res < 8) 147 154 { 148 fprintf (stderr,"Error in usb_bulk_write: %d/8\n", res);155 log2("Error in usb_bulk_write: %d/8\n", res); 149 156 return 0; 150 157 } … … 153 160 } 154 161 155 static struct mem_file readfile( const char *filename)162 static int send_poke (usb_dev_handle *handle, int poke) 156 163 { 157 struct mem_file toread = { NULL, 0 }; 164 int res; 165 buffer[0]= 'T'; 166 buffer[1]= 'I'; 167 buffer[2]= 'S'; 168 buffer[3]= 'p'; 169 *(u_int32_t *) &buffer[4]= cpu_to_le32 (poke); 170 171 res= usb_bulk_write (handle, OUT_EP, buffer, 8, 1000); 172 if (res < 8) 173 { 174 log2("Error in usb_bulk_write: %d/8\n", res); 175 return 0; 176 } 177 178 return 1; 179 } 180 181 static struct mem_file readfile( char *filename ) 182 { 183 struct mem_file toread = { NULL, 0, NULL }; 158 184 int fd= open (filename, O_RDONLY); 159 185 160 186 if (fd < 0) 161 187 { 162 fprintf (stderr, "Error opening %s file\n", filename);188 log3("Error opening %s file (err=%d)\n", filename, errno); 163 189 return toread; 164 190 } … … 167 193 if (toread.size < 0 || lseek (fd, 0, SEEK_SET) < 0) 168 194 { 169 fprintf (stderr, "Error with lseek other %s file\n", filename);195 log3("Error with lseek other %s file (err=%d)\n", filename, errno); 170 196 close (fd); 171 197 return toread; 172 198 } 173 199 174 toread.content= malloc ( do_div(toread.size, 4));200 toread.content= malloc (roundup (toread.size, 4)); 175 201 if (toread.content == NULL) 176 202 { 177 fprintf (stderr,"Out of memory requesting %d bytes\n", toread.size);203 log2("Out of memory requesting %d bytes\n", toread.size); 178 204 close (fd); 179 205 return toread; … … 182 208 if ((toread.size= read (fd, toread.content, toread.size)) < 0) 183 209 { 184 fprintf (stderr, "Error reading %s file\n", filename);210 log3("Error reading %s file (err=%d)\n", filename, errno); 185 211 close (fd); 186 212 return toread; … … 190 216 191 217 return toread ; 218 } 219 220 static int savefile( char *filename, struct mem_file buffer ) 221 { 222 int fd= creat (filename, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH ); 223 224 if (fd < 0) 225 { 226 log3("Error opening %s file for writing (err=%d)\n", filename, errno); 227 return 1; 228 } 229 230 if (buffer.size != write (fd, buffer.content, buffer.size)) 231 { 232 log3("Error writing %s file (err=%d)\n", filename, errno); 233 close (fd); 234 return 1; 235 } 236 237 close (fd); 238 239 return 0 ; 192 240 } 193 241 … … 218 266 else 219 267 { 220 char inbuff[256]; 221 int insize= usb_bulk_read (handle, IN_EP, 222 inbuff, sizeof (inbuff), 5000); 268 char inbuff[MAX_SIZE + 128]; 269 int insize= usb_bulk_read (handle, IN_EP, inbuff, sizeof (inbuff), 1000); 223 270 224 271 if (insize < 48) … … 235 282 while (size > 0) 236 283 { 237 int outsize= usb_bulk_write (handle, OUT_EP, p, 64, 5000); 238 if (outsize < 64) 284 int chunksize = size < CHUNK_SIZE ? size : CHUNK_SIZE ; 285 int outsize = usb_bulk_write (handle, OUT_EP, p, chunksize, 1000); 286 if (outsize < chunksize) 239 287 { 240 log 2("Error in usb_bulk_write: %d/64\n", outsize);288 log3("Error in usb_bulk_write: %d/%d\n", outsize,chunksize); 241 289 break; 242 290 } 243 291 244 p+= 64;245 size-= 64;292 p+= chunksize; 293 size-= chunksize; 246 294 } 247 295 … … 249 297 { 250 298 log2("Sent %d bytes to OMAP\n",buffsize); 251 usb_bulk_write (handle, OUT_EP, buffer, 0, 1000);252 299 253 300 p= NULL; 254 301 size= 0; 255 302 256 int res=1, sz= 0, loop= 1, cmd=0 ;303 int res=1, sz= 0, loop= 1, cmd=0, ftag=0, finfo=0, fline=0 ; 257 304 int vendor, device, info ; 258 305 char *cmdp = cmdfile.content ; 259 struct mem_file current = { NULL, 0 };306 struct mem_file current = { NULL, 0, NULL }; 260 307 261 308 err = 1 ; // Set error by default … … 265 312 if (loop<0) loop++ ; // Avoid infinite loop 266 313 267 if (res>0 )314 if (res>0 || ftag) 268 315 res= usb_bulk_read (handle, IN_EP, 269 316 inbuff, sizeof (inbuff), 5000); … … 275 322 } 276 323 324 if (ftag) 325 { 326 switch (ftag) 327 { 328 case 0xaaaa0001: 329 // A string should be in the buffer with length still set in finfo 330 if ( res != finfo) 331 { 332 log3("Error waiting string from flasher program: length = %d vs %d expected\n", res, finfo); 333 break ; 334 } 335 // Fix the string just in case 336 inbuff[res] = '\0' ; 337 if (fline) 338 fprintf(stderr, "%s",inbuff); 339 else 340 log2("Flasher: %s", inbuff); 341 if ( inbuff[res-1] == '\n' ) 342 fline = 0 ; 343 else 344 fline ++ ; 345 break ; 346 case 0xaaaa0002: 347 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 348 break ; 349 case 0xaaaa0003: 350 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 351 log2("Flasher: NAND read = 0x%08X\n", finfo); 352 break ; 353 case 0xaaaa0004: 354 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 355 log2("Flasher: NAND size = 0x%08X\n", finfo); 356 break ; 357 case 0xaaaa0005: 358 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 359 log2("Flasher: Error code = %d\n", finfo); 360 err = - finfo ; // Will quit on error 361 break ; 362 case 0xaaaa0006: 363 finfo = le32_to_cpu (*(u_int32_t *) inbuff); 364 log2("Flasher: NAND remain = 0x%08X\n", finfo); 365 break ; 366 } 367 ftag = 0 ; 368 continue ; 369 } 370 371 if (err<0) 372 { 373 err = -err ; // Keep err as positive number 374 if (send_cmd (handle,'e',NULL)) 375 log1("Asking stop\n"); 376 else 377 log1("Can't ask to stop\n"); 378 break ; // Leave loop 379 } 380 277 381 if (res >= 4) 278 382 { … … 305 409 sz= le32_to_cpu (*(u_int32_t *) &inbuff[4]); 306 410 //log2("OMAP read %d\n", sz); // DEBUG 307 res= usb_bulk_write (handle, OUT_EP, p, sz, 5000);411 res= usb_bulk_write (handle, OUT_EP, p, sz, 1000); 308 412 if (res < sz) 309 413 { … … 318 422 break; 319 423 424 case 'x': 425 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 426 u_int32_t len = le32_to_cpu (*(u_int32_t *) &inbuff[8]); 427 u_int32_t crc = le32_to_cpu (*(u_int32_t *) &inbuff[12]); 428 log4("OMAP crc32 computing: pos 0x%08x/0x%08x, current crc32 0x%08X\n",info,len,crc); 429 break; 430 320 431 case 'A': 321 432 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 322 433 log2("OMAP address info: 0x%08X\n", info); 434 break; 435 436 case 'C': 437 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 438 log2("OMAP crc32 found: 0x%08X\n", info); 323 439 break; 324 440 … … 343 459 break; 344 460 461 case 'D': 462 if (!current.content) 463 { 464 log1("Can't dump memory without buffer\n"); 465 loop = 0 ; 466 break ; 467 } 468 res -= 4 ; 469 if (res < 1) 470 { 471 log2("Received empty memory dump (res=%d)\n",res); 472 // reset buffer size anyway 473 current.size = 0 ; 474 res = 0 ; // Target is waiting a new command 475 476 } else { 477 if (res > size) 478 { 479 log2("Can't dump %d bytes as buffer is full\n",res); 480 loop = 0 ; 481 break ; 482 } 483 memcpy(p,&inbuff[4],res); 484 p += res ; 485 size -= res ; 486 } 487 if ( size == 0 ) 488 { 489 log2("%d bytes dumped to buffer\n",current.size); 490 res = 0 ; // Target is waiting a new command 491 } 492 break; 493 345 494 case 'M': 346 loop=3 ; 347 log2("0x%08X | ",info); 348 while (++loop<36) 349 fprintf (stderr,"%02hhX", inbuff[loop]); 350 loop=3 ; 351 fprintf (stderr, " |"); 352 while (++loop<36) 353 if ((int)inbuff[loop]>=0x20 && (int)inbuff[loop]<0x7f) 354 fprintf (stderr,"%c", inbuff[loop]); 355 else 356 fprintf (stderr,"."); 357 fprintf (stderr,"|\n"); 495 sz = 0 ; 496 res -= 4 ; 497 while (sz<res) 498 { 499 log2("0x%08X | ",info); 500 501 loop=0 ; 502 while (++loop<=DUMP_LINE_SIZE) 503 fprintf (stderr,"%02hhX", inbuff[3+sz+loop]); 504 fprintf (stderr, " |"); 505 506 loop=0 ; 507 while (++loop<=DUMP_LINE_SIZE) 508 if ((int)inbuff[3+sz+loop]>=0x20 && (int)inbuff[3+sz+loop]<0x7f) 509 fprintf (stderr,"%c", inbuff[3+sz+loop]); 510 else 511 fprintf (stderr,"."); 512 513 fprintf (stderr,"|\n"); 514 515 info += DUMP_LINE_SIZE; 516 sz += DUMP_LINE_SIZE; 517 } 358 518 res = 0 ; // Target is waiting a new command 359 info += 32 ;360 519 break; 361 520 … … 369 528 info = le32_to_cpu (*(u_int32_t *) &inbuff[4]); 370 529 log2("OMAP is booting at address: 0x%08X\n", info); 371 res = 0 ; // Target is waiting a new command530 loop = err = res = 0 ; // Quit now 372 531 break; 373 532 … … 376 535 break; 377 536 } 378 } else { 379 // Fix the string just in case 380 inbuff[res] = '\0' ; 381 log2("Got: %s\n", inbuff); 537 } else 538 { 539 info = le32_to_cpu (*(u_int32_t *) inbuff); 540 switch (info) 541 { 542 case 0xaaaa0001: 543 case 0xaaaa0002: 544 case 0xaaaa0003: 545 case 0xaaaa0004: 546 case 0xaaaa0005: 547 case 0xaaaa0006: 548 ftag = info ; 549 break ; 550 case 0xff555580: 551 log1("Flasher: Command finished\n"); 552 break ; 553 default: 554 // Fix the string just in case 555 inbuff[res] = '\0' ; 556 // Strip final EOL in the string 557 if ( inbuff[res-1] == '\n' ) 558 inbuff[res-1] = '\0' ; 559 if (res==4) 560 log3("Got: %s (0x%08X)\n", inbuff, info); 561 else 562 log2("Got: %s\n", inbuff); 563 } 382 564 } 383 565 } … … 397 579 switch (cmdp[cmd]) 398 580 { 581 case 'D': // Save downloaded memory to a file still specified 582 if (current.filename == NULL) 583 { 584 log1("Can't save without a file specified with 'F' command\n"); 585 loop = 0 ; // Just quit on error 586 break ; 587 } 588 if (current.content == NULL) 589 { 590 log2("Can't save without download buffer to file '%s'\n",current.filename); 591 loop = 0 ; // Just quit on error 592 break ; 593 } 594 if (current.size==0) 595 log2("Nothing to save, file %s is still up to date\n",current.filename); 596 else if (savefile(current.filename, current)==0) 597 { 598 info = crc32(0,current.content,current.size); 599 log3("Downloaded memory saved to file %s with CRC32=0x%08X\n",current.filename,info); 600 } else 601 { 602 log2("Can't save downloaded memory saved to file %s\n",current.filename); 603 // Just quit on error 604 loop = 0 ; 605 } 606 // Release memory 607 free((void *)current.content); 608 free((void *)current.filename); 609 current.content = NULL ; 610 current.filename = NULL ; 611 res -- ; 612 break; 613 case 'd': // Save downloaded memory to a file 614 cmd += 2 ; 615 if (cmd >= cmdfile.size || cmdp[cmd] == '\0') 616 { 617 log1("Bad 'd' format in command download\n"); 618 break ; 619 } 620 if (current.content == NULL) 621 { 622 log2("Can't save without download buffer to file '%s'\n",&cmdp[cmd]); 623 loop = 0 ; // Just quit on error 624 break ; 625 } 626 if (current.size==0) 627 log2("Nothing to save, file %s is still up to date\n",&cmdp[cmd]); 628 else if (savefile(&cmdp[cmd], current)==0) 629 { 630 info = crc32(0,current.content,current.size); 631 log3("Downloaded memory saved to file %s with CRC32=0x%08X\n",&cmdp[cmd],info); 632 } else 633 { 634 log2("Can't save downloaded memory saved to file %s\n",&cmdp[cmd]); 635 // Just quit on error 636 loop = 0 ; 637 } 638 // Release memory 639 free((void *)current.content); 640 current.content = NULL ; 641 res -- ; 642 break; 399 643 case 'f': // Put a file to be uploaded in a memory buffer 400 644 cmd += 2 ; … … 407 651 if (current.content != NULL) 408 652 free((void *)current.content); 409 current = readfile( (const char *)&cmdp[cmd]);653 current = readfile(&cmdp[cmd]); 410 654 if (current.content == NULL) 411 655 { 412 656 log2("Can't read file '%s'\n",&cmdp[cmd]); 413 657 loop = 0 ; // Just quit on error 658 break ; 414 659 } 415 660 p = current.content ; … … 425 670 } 426 671 break; 672 case 'F': // Set a filename that would be loaded to check crc and saved 673 cmd += 2 ; 674 if (cmd >= cmdfile.size || cmdp[cmd] == '\0') 675 { 676 log1("Bad 'F' format in command file\n"); 677 break ; 678 } 679 // Free previously used memory buffer 680 if (current.filename != NULL) 681 free((void *)current.filename); 682 info = strlen(&cmdp[cmd]); 683 if (info == 0) 684 { 685 log2("Can't read filename '%s' length\n",&cmdp[cmd]); 686 loop = 0 ; // Just quit on error 687 break ; 688 } 689 current.filename = malloc (++info); 690 if (current.filename == NULL) 691 { 692 log2("Out of memory requesting %d bytes\n", info); 693 loop = 0 ; // Just quit on error 694 break ; 695 } 696 if (info!=stringcopy(current.filename,&cmdp[cmd],info)) 697 { 698 log2("Can't read filename '%s'\n",&cmdp[cmd]); 699 loop = 0 ; // Just quit on error 700 break ; 701 } 702 // still read next command 703 res -- ; 704 break; 705 case 'C': // Get a CRC32 and send it to target 706 cmd += 2 ; 707 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 708 { 709 log2("Can't read crc32 '%s'\n",&cmdp[cmd]); 710 loop = 0 ; // Just quit on error 711 break ; 712 } 713 // compute the current CRC32 if a file is referenced and exists 714 if (!info && current.filename != NULL) 715 { 716 struct mem_file loader = readfile(current.filename); 717 if (loader.content == NULL) 718 { 719 log2("Can't read file '%s', will be initialized with target\n",current.filename); 720 } else 721 { 722 log3("Checking CRC32 of %d bytes from %s file\n",loader.size,current.filename); 723 info = crc32(0,loader.content,loader.size); 724 free(loader.content); 725 } 726 } 727 if (send_word (handle, 'C', info)) 728 log2("Sending crc32 0x%02X\n", info); 729 else 730 { 731 log2("Can't send crc32 0x%02X\n", info); 732 loop = 0 ; // Just quit on error 733 } 734 break; 427 735 case 'a': // Get an address and send it to target 428 736 cmd += 2 ; … … 431 739 log2("Can't read address '%s'\n",&cmdp[cmd]); 432 740 loop = 0 ; // Just quit on error 433 } 434 if (send_address (handle, info)) 741 break ; 742 } 743 if (send_word (handle, 'a', info)) 435 744 log2("Sending address 0x%02X\n", info); 436 745 else … … 440 749 } 441 750 break; 751 case 'm': // Get a size in kB and ask a memory download 752 cmd += 2 ; 753 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 754 { 755 log2("Can't read size '%s'\n",&cmdp[cmd]); 756 loop = 0 ; // Just quit on error 757 break ; 758 } 759 // size unit is kbytes 760 size = info * 1024 ; 761 // Free previously used memory buffer 762 if (current.content != NULL) 763 free((void *)current.content); 764 current.size = size ; 765 p = malloc (roundup (size, 4)); 766 if ( p == NULL) 767 { 768 log2("Out of memory requesting %d bytes\n", roundup (size, 4)); 769 loop=0 ; 770 break ; 771 } 772 current.content = p ; 773 if (!(send_word (handle,'m',size))) 774 { 775 log2("Can't ask to download %d bytes from memory\n",size); 776 loop = 0 ; // Just quit on error 777 } else 778 log2("Allocated %d kBytes to download memory\n",info); 779 break; 442 780 case 'M': // Ask memory dump 443 781 if (!(send_cmd (handle,'M',NULL))) 444 782 { 445 783 log1("Can't ask to read memory\n"); 784 loop = 0 ; // Just quit on error 785 } 786 break; 787 case 'P': // Ask a peek onto the address 788 if (!(send_cmd (handle,'P',NULL))) 789 { 790 log1("Can't ask to peek memory\n"); 791 loop = 0 ; // Just quit on error 792 } 793 break; 794 case 'S': // Ask to change stack to the last given address 795 if (send_cmd (handle,'S',NULL)) 796 log1("Asking stack relocate\n"); 797 else 798 { 799 log1("Can't ask to relocate stack\n"); 446 800 loop = 0 ; // Just quit on error 447 801 } … … 457 811 break; 458 812 case 'b': // Boot the target by just branching to the last given address 459 if (send_cmd (handle,'b',NULL)) 813 if (send_cmd (handle,'b',NULL)) { 460 814 log1("Asking boot\n"); 461 else 815 // Quit now witout error set 816 loop = err = -10 ; 817 cmd = cmdfile.size ; 818 res = 1 ; 819 } else 462 820 { 463 821 log1("Can't ask to boot\n"); … … 467 825 case 'e': // End of commands 468 826 log1("Commands read and sent\n"); 827 if (send_cmd (handle,'e',NULL)) 828 log1("Asking stop\n"); 829 else 830 log1("Can't ask to stop\n"); 469 831 // Quit now witout error set 470 832 loop = err = 0 ; … … 472 834 res = 1 ; 473 835 break ; 836 case 'k': // Boot a linux kernel to the last given address 837 cmd += 2 ; 838 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 839 { 840 log2("Can't read mach id '%s'\n",&cmdp[cmd]); 841 loop = 0 ; // Just quit on error 842 break ; 843 } 844 if (send_word (handle,'k', info)) { 845 log1("Asking kernel to boot\n"); 846 // Quit now witout error set 847 loop = err = -10 ; 848 cmd = cmdfile.size ; 849 res = 1 ; 850 } else 851 { 852 log1("Can't ask to boot a kernel\n"); 853 loop = 0 ; // Just quit on error 854 } 855 break; 856 case 'p': // poke 857 cmd += 2 ; 858 if (sscanf((const char *)&cmdp[cmd], "%i", &info) != 1) 859 { 860 log2("Can't read value to poke '%s'\n",&cmdp[cmd]); 861 loop = 0 ; // Just quit on error 862 break ; 863 } 864 if (send_poke (handle, info)) 865 log2("Sending poke 0x%08X\n", info); 866 else 867 { 868 log2("Can't send poke 0x%08X\n", info); 869 loop = 0 ; // Just quit on error 870 } 871 break; 474 872 case '#': 873 cmd += 2 ; 874 log2("%s\n", &cmdp[cmd]); 475 875 case '/': 476 876 // skip comments … … 490 890 } 491 891 } 892 // Free used memory buffer 893 if (current.content != NULL) 894 free((void *)current.content); 895 if (current.filename != NULL) 896 free((void *)current.filename); 492 897 } 493 898 } … … 495 900 496 901 if (err>=0) { 902 log1("Releasing usb interface\n"); 497 903 err = usb_release_interface (handle, 0); 498 904 if (err < 0) 499 905 log2("Error in usb_release_interface (%d)\n",err); 906 log1("Released usb interface\n"); 500 907 } 501 908 … … 551 958 } 552 959 553 size= do_div(size, 4);960 size= roundup (size, 4); 554 961 555 962 p[0x21]= cpu_to_le32 (size - 0x40); … … 562 969 p[0x12]= cpu_to_le32 (size); 563 970 564 buffsize= 128 + do_div(size, 4);971 buffsize= 128 + roundup (size, 4); 565 972 566 973 cmdfile = readfile(argv[ARG_CMDFILE]); … … 575 982 if (cmdbuffer[i] == '\n' || cmdbuffer[i] == '\r' || cmdbuffer[i] == ';') 576 983 cmdbuffer[i] = '\0' ; 984 // Skip comment line 985 if (cmdbuffer[i] == '/') { 986 while ( i++ < cmdfile.size ) { 987 if (cmdbuffer[i] == '\n' || cmdbuffer[i] == '\r') { 988 i-- ; 989 break ; 990 } 991 } 992 } 577 993 } while ( i++ < cmdfile.size ); 578 994 }
Note: See TracChangeset
for help on using the changeset viewer.