📄 download.c
字号:
/* * $Id: download.c,v 1.5 2003/09/24 12:13:35 jfabo Exp $ * * Copyright (C) 2001, 2002, 2003 ETC s.r.o. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by Marcel Telka <marcel@telka.sk>, 2001, 2002. * Juraj Fabo <vinco@etc.sk>, 2003. * */#include <_windows.h>#include "board.h"#if CPU == SA1110#include <sa11x0/rc.h>#include <sa11x0/gpio.h>#endif#if CPU == PXA250#include <pxa2x0/pmrc.h>#endif#include "except.h"#include "download.h"#include "flash.h"#include "format.h"#include "splash.h"#include ".config.h"const static char boot_packet[] = { '\xAA', '\x55', '\x55', '\xAA', '\x00', '\x00', /* boot packet header */ '\x09', '\x00', /* length */ '\xFF', '\xFF', '\xFF', '\xFF', /* boot type */ '\xFA', /* checksum */ '\x5A', '\xA5', '\x0A', '\x1A' /* packet tail */};#define BOOT_PACKET_SIZE (sizeof boot_packet / sizeof (char))/* keep the same size of two following structures */const static char sync_bytes[] = { 'B', '0', '0', '0', 'F', 'F', '\n'};const static char upload_id[] = { 'u', 'p', 'l', 'o', 'a', 'd', '\n'};#define SIZE_OF_SYNC_BYTES (sizeof sync_bytes / sizeof (char))static unsigned intread_dword( struct fntable *fn ){ unsigned int d = 0; fn->read(&((unsigned char)(d)), 4); return d;}voiddownload( struct fntable *fn, struct imginfo *img, int retry ){ int i; unsigned int *rec; unsigned char synchro[SIZE_OF_SYNC_BYTES];#ifdef CONFIG_SPLASH_SCREEN unsigned char progress_percentage = 0; uint32_t total_len = 0;#endif /* send boot packet */ for (i = 0; i < BOOT_PACKET_SIZE; i++) fn->writechar( boot_packet[i] ); /* read sync bytes */ for (i = 0; i < SIZE_OF_SYNC_BYTES; i++) fn->read(synchro + i, 1); /* check for upload/download */ for (i = 0; i < SIZE_OF_SYNC_BYTES; i++) { if (sync_bytes[i] != synchro[i]){ for (i = 0; i < SIZE_OF_SYNC_BYTES; i++) { if (upload_id[i] != synchro[i]) { Throw E_INVALIDSYNC; } } /* Here we know, that the PC wants to upload */ Throw E_UPLOADREQUEST; } } img->start = read_dword( fn ); img->len = read_dword( fn ); img->copy = 0; switch (img->start & 0xFF000000) { case MEM_VIRT_FLASH: case MEM_PHYS_FLASH: img->copy = 1; img->target = MEM_VIRT_XBOOT_RUN + MEM_SIZE_XBOOT_RUN; break; case MEM_VIRT_SDRAM: img->target = img->start; break; case MEM_PHYS_SDRAM: img->target = img->start - MEM_PHYS_SDRAM + MEM_VIRT_SDRAM; break; default: Throw E_UNKNOWNMEMORY; } if (img->copy) rec = (void *) img->target; else rec = (void *) (img->target + img->len); for (;;) { unsigned int i; unsigned int calcsum = 0; unsigned char *dst; unsigned int addr = *rec++ = read_dword( fn ); unsigned int len = *rec++ = read_dword( fn ); unsigned int sum = *rec++ = read_dword( fn );#ifdef CONFIG_SPLASH_SCREEN unsigned int step = 0, remaining = 0; unsigned char *source;#endif /* last record */ if (!addr && !sum) { img->launch_addr = len;#ifdef CONFIG_SPLASH_SCREEN progress_bar(100, 1);#endif return; } /* initialize dst pointer */ if (img->copy) { dst = (void *) rec; if (len % sizeof *rec) Throw E_DATAALIGNMENT; rec += len / sizeof *rec; } else dst = (void *) (addr - img->start + img->target);#ifndef CONFIG_SPLASH_SCREEN /* read data and copy to dst */ fn->read(dst, len);#else /* CONFIG_SPLASH_SCREEN */ source = dst; step = (1024 < len) ? 1024:len; remaining = len; while(remaining){ /* read data and copy to dst */ fn->read(dst, step); total_len += step; if (((total_len * 100 )/ img->len ) > progress_percentage ){ progress_percentage = (unsigned char)((total_len * 100 )/ img->len ); progress_bar(progress_percentage, 1); } remaining -= step; dst += step; step = (1024 < remaining)?1024:remaining; } dst = source;#endif /* calculate checksum */ for (i = 0; i < len; i++) calcsum += *dst++; /* check errors */ if (calcsum == sum) { if (retry) fn->writechar( 'O' ); } else { if (!retry || img->copy) Throw E_CHECKSUM; fn->writechar( 'R' ); rec -= 3; } }}intDownloadImage( struct imginfo *img ){ int status = -2;#if CPU == SA1110 /* download external image only after hardware reset and if the power button is pressed */ if ((RCSR & 1) && !(GPLR & GPIO_PWR_MASK)) {#elif CPU == PXA250 /* download external image only after hardware reset */ if (RCSR & RCSR_HWR) { #else { #endif #ifdef HAVE_USB if (status == -2) status = USB_download( img ); #endif #ifdef HAVE_PP if (status == -2) status = PP_download( img ); #endif if (status == -2) status = Serial_download( img ); } if (status == -2) status = Memory_download( img, (void *) MEM_VIRT_WINCE ); else if (status == 1) { EdbgOutputDebugString( "\nUpload completed.\n" ); } else { EdbgOutputDebugString( "\nDownload complete. Starting FLASH!\n\n" ); FlashImage( img, MEM_PHYS_WINCE - MEM_PHYS_FLASH ); EdbgOutputDebugString( "FLASH successfull.\n" ); status = 0; } return status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -