資源簡介
使用該工具可以直接通過USB向開發(fā)板燒錄程序,避免了SD卡燒錄的繁瑣過程,相關(guān)教程詳見 http://blog.csdn.net/jzxcumt/article/details/50281325 。同時還可以通過該工具向4412的eMMC燒錄Uboot,方便實用。

代碼片段和文件信息
/*?dnw2?linux?main?file.?This?depends?on?libusb.
?*?*
?*?*?Author:?Fox?
?*?*?License:?GPL
?*?*
?*?*/
#include?
#include?
#include?
#include?
#include?
#define?TINY4412_SECBULK_IDVENDOR?0x04e8
#define?TINY4412_SECBULK_IDPRODUCT?0x1234
#define?TINY4412_RAM_base???????0xc0000000
typedef?unsigned?int?u_int32_t;?
//?TINY4412
#define?RAM_base????????????TINY4412_RAM_base
#define?VENDOR_ID???????????TINY4412_SECBULK_IDVENDOR
#define?PRODUCT_ID??????????TINY4412_SECBULK_IDPRODUCT
void?usage()
{
????printf(“Usage:?dnw2?\n\n“);
}
unsigned?char*?prepare_write_buf(char?*filename?unsigned?int?*len)
{
????unsigned?char?*write_buf?=?NULL;
????struct?stat?fs;
????int?fd?=?open(filename?O_RDONLY);
????if(-1==fd)
????{
????????perror(“Cannot?open?file“);
????????return?NULL;
????}
????if(-1==fstat(fd?&fs))
????{
????????perror(“Cannot?get?file?size“);
????????goto?error;
????}
????write_buf?=?(unsigned?char*)malloc(fs.st_size+10);
????if(NULL==write_buf)
????{
????????perror(“malloc?failed“);
????????goto?error;
????}
????if(fs.st_size?!=?read(fd?write_buf+8?fs.st_size))
????{
????????perror(“Reading?file?failed“);
????????goto?error;
????}
????????unsigned?short?sum?=?0;
????????int?i;
????????for(i=8;?i ????????{
????????????????sum?+=?write_buf[i];
????????}
????printf(“Filename?:?%s\n“?filename);
????printf(“Filesize?:?%d?bytes\n“?(int)fs.st_size);
????printf?(“Sum?is?%x\n“sum);
????*((u_int32_t*)write_buf)?=?RAM_base;????????//download?address
????*((u_int32_t*)write_buf+1)?=?fs.st_size?+?10;????//download?size;
????write_buf?[fs.st_size?+?8]?=?sum?&?0xff;
????write_buf?[fs.st_size?+?9]?=?sum?>>?8;
????*len?=?fs.st_size?+?10;
????return?write_buf;
error:
????if(fd!=-1)?close(fd);
????if(NULL!=write_buf)?free(write_buf);
????fs.st_size?=?0;
????return?NULL;
???
}
const?char?*?dev=“/dev/secbulk0“;
int?main(int?argc?char?*argv[])
{
????if(2!=argc)
????{
????????usage();
????????return?1;
????}
????/*struct?usb_dev_handle?*hdev?=?open_port();
????if(!hdev)
????{
????????return?1;
????}*/
????
????int?fd_dev?=?open(dev?O_WRONLY);
if(?-1?==?fd_dev)
{
printf(“Can?not?open?%s\n“?dev);
}
????unsigned?int?len?=?0;
????unsigned?char*?write_buf?=?prepare_write_buf(argv[1]?&len);
????if(NULL==write_buf)?return?1;
????unsigned?int?remain?=?len;
????unsigned?int?towrite;
????printf(“Writing?data?...\n“);
????while(remain)
????{
????????towrite?=?remain>512???512?:?remain;
????????if(towrite?!=?write(fd_dev?write_buf+(len-remain)?towrite))
????????//if(towrite?!=?usb_bulk_write(hdev?0x02?write_buf+(len-remain)?towrite?3000))
????????{
????????????perror(“usb_bulk_write?failed“);
????????????break;
????????}
????????remain-=towrite;
????????printf(“\r?%d?\t?%d?bytes?????“?(len-remain)*100/len?len-remain);
????????fflush(stdout);
????}
????if(0==remain)?printf(“Done!\n“);
????return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-12-13?11:19??dnw-linux\
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\
?????文件?????????543??2015-12-13?10:27??dnw-linux\.gitignore
?????目錄???????????0??2015-12-13?10:27??dnw-linux\.git\branches\
?????文件?????????268??2015-12-13?10:27??dnw-linux\.git\config
?????文件??????????73??2015-12-13?10:27??dnw-linux\.git\desc
?????文件??????????23??2015-12-13?10:27??dnw-linux\.git\HEAD
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\hooks\
?????文件?????????452??2015-12-13?10:27??dnw-linux\.git\hooks\applypatch-msg.sample
?????文件?????????896??2015-12-13?10:27??dnw-linux\.git\hooks\commit-msg.sample
?????文件?????????189??2015-12-13?10:27??dnw-linux\.git\hooks\post-update.sample
?????文件?????????398??2015-12-13?10:27??dnw-linux\.git\hooks\pre-applypatch.sample
?????文件????????1704??2015-12-13?10:27??dnw-linux\.git\hooks\pre-commit.sample
?????文件????????4898??2015-12-13?10:27??dnw-linux\.git\hooks\pre-reba
?????文件????????1239??2015-12-13?10:27??dnw-linux\.git\hooks\prepare-commit-msg.sample
?????文件????????3611??2015-12-13?10:27??dnw-linux\.git\hooks\update.sample
?????文件?????????736??2015-12-13?10:27??dnw-linux\.git\index
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\info\
?????文件?????????240??2015-12-13?10:27??dnw-linux\.git\info\exclude
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\logs\
?????文件?????????178??2015-12-13?10:27??dnw-linux\.git\logs\HEAD
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\logs\refs\
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\logs\refs\heads\
?????文件?????????178??2015-12-13?10:27??dnw-linux\.git\logs\refs\heads\master
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\logs\refs\remotes\
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\logs\refs\remotes\origin\
?????文件?????????178??2015-12-13?10:27??dnw-linux\.git\logs\refs\remotes\origin\HEAD
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\ob
?????目錄???????????0??2015-12-13?10:27??dnw-linux\.git\ob
?????目錄???????????0??2015-12-13?11:19??dnw-linux\.git\ob
?????文件????????4516??2015-12-13?10:27??dnw-linux\.git\ob
............此處省略34個文件信息
評論
共有 條評論