/** * Read data from SPI bus. * Since we are master, we have to trigger slave by sending * fake chars on the bus. */ static size_t spimaster_read(struct KFile *fd, void *_buf, size_t size) { Serial *fd_spi = SERIAL_CAST(fd); ser_flush(&fd_spi->fd); ser_purgeRx(fd_spi); size_t total_rd = 0; uint8_t *buf = (uint8_t *)_buf; int c; while (size--) { /* * Send and receive chars 1 by 1, otherwise the rxfifo * will overrun. */ ser_putchar(0, fd_spi); if ((c = ser_getchar(fd_spi)) == EOF) break; *buf++ = c; total_rd++; } return total_rd; }
/** * Read at most \a size bytes from \a port and put them in \a buf * * \return number of bytes actually read. */ static size_t ser_read(struct KFile *fd, void *_buf, size_t size) { Serial *fds = SERIAL_CAST(fd); size_t i = 0; char *buf = (char *)_buf; int c; while (i < size) { if ((c = ser_getchar(fds)) == EOF) break; buf[i++] = c; } return i; }
int fgetc (FILE *f) { return (ser_getchar()); }
int main(void) { unsigned image; init_omap3530beagle(); ser_putstr((char *)"\n\nQNX Neutrino Initial Program Loader for Texas Instruments OMAP3530 Beagle Board\n"); while (1) { image = QNX_LOAD_ADDRESS; ser_putstr((char *)"Commands:\n\n"); ser_putstr((char *)"Press 'D' for serial download, using the 'sendnto' utility\n"); ser_putstr((char *)"Press 'F' to boot an OS image from NAND flash\n"); ser_putstr((char *)"Press 'U' to Copy an OS image to NAND flash\n"); ser_putstr((char *)"Press 'I' to Update the IPL\n"); switch (ser_getchar()) { case 'D': case 'd': ser_putstr((char *)"Send image now...\n"); if (image_download_ser(image)) { ser_putstr((char *)"Download failed...\n"); continue; } else ser_putstr((char *)"Download OK...\n"); image = image_scan(image, image + 0x200); break; case 'F': case 'f': ser_putstr((char *)"reading from NAND flash ........\n"); if (read_image_from_nand(NAND_RESERVED_BLOCK_START, NAND_RESERVED_BLOCK_END, (unsigned)image) !=0 ) { ser_putstr((char *)"Read from NAND flash failed...\n"); continue; } image = image_scan(image, image+0x200); break; case 'U': case 'u': ser_putstr((char *)"send the ifs now...\n"); if (image_download_ser(image)) { ser_putstr((char *)"download failed...\n"); continue; }else{ ser_putstr((char *)"download OK...\n"); //read all left bytes while(ser_poll()){ ser_getchar(); } ser_putstr((char *)"Writing IFS image to NAND flash from block 4 ......\n"); if (upgrade_nand_flash(NAND_RESERVED_BLOCK_START, NAND_RESERVED_BLOCK_END, (unsigned)image) != 0 ) { ser_putstr((char *)"IFS image upgrading failed...\n"); } else { ser_putstr((char *)"Upgrade IFS OK...\n"); } continue; } break; case 'I': case 'i': ser_putstr((char *)"Send the IPL image, using the 'sendnto' utility...\n"); if (image_download_ser(image)) { ser_putstr((char *)"Download failed...\n"); continue; } else { ser_putstr((char *)"Download OK...\n"); ser_putstr((char *)"Writing IPL to NAND flash @ blk0 ......\n"); if (upgrade_IPL((unsigned)image) != 0 ) { ser_putstr((char *)"IPL upgrading failed...\n"); } else { ser_putstr((char *)"Update IPL OK\n"); } //read all left bytes while (ser_poll()) { ser_getchar(); } continue; } break; default: continue; } if (image != 0xffffffff) { //before we go, we need to unlock the top 128MB NAND // this will automatically lock all other blocks nand_unlock_blocks(1024, 2047); ser_putstr((char *)"Found image @ 0x"); ser_puthex(image); ser_putstr((char *)"\n"); image_setup(image); ser_putstr((char *)"Jumping to startup @ 0x"); ser_puthex(startup_hdr.startup_vaddr); ser_putstr((char *)"\n\n"); image_start(image); /* Never reach here */ return 0; }else{ ser_putstr((char *)"image_scan failed...\n"); } } return 0; }