/* dnw2 linux main file. This depends on libusb.
* *
* * Author: Fox <hulifox008@163.com>
* * License: GPL
* *
* */
#include <stdio.h>
#include <usb.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> #define TINY4412_SECBULK_IDVENDOR 0x04e8
#define TINY4412_SECBULK_IDPRODUCT 0x1234 #define TINY4412_RAM_BASE 0xc0000000 // TINY4412
#define RAM_BASE TINY4412_RAM_BASE
#define VENDOR_ID TINY4412_SECBULK_IDVENDOR
#define PRODUCT_ID TINY4412_SECBULK_IDPRODUCT struct usb_dev_handle * open_port()
{
struct usb_bus *busses, *bus; usb_init();
usb_find_busses();
usb_find_devices(); busses = usb_get_busses();
for(bus=busses;bus;bus=bus->next)
{
struct usb_device *dev;
for(dev=bus->devices;dev;dev=dev->next)
{
if( VENDOR_ID==dev->descriptor.idVendor
&& PRODUCT_ID==dev->descriptor.idProduct)
{
printf("Target usb device found!\n");
struct usb_dev_handle *hdev = usb_open(dev);
if(!hdev)
{
perror("Cannot open device");
}
else
{
if(0!=usb_claim_interface(hdev, 0))
{
perror("Cannot claim interface");
usb_close(hdev);
hdev = NULL;
}
}
return hdev;
}
}
} printf("Target usb device not found!\n"); return NULL;
} void usage()
{
printf("Usage: dnw2 <file>\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<fs.st_size+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; } int main(int argc, char *argv[])
{
if(2!=argc)
{
usage();
return 1;
} struct usb_dev_handle *hdev = open_port();
if(!hdev)
{
return 1;
} 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 != 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;
}

makefile

#******************************************************************************
#*
#* Copyright (C) 2009-2012 Broadcom Corporation
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.
#* You may obtain a copy of the License at
#*
#* http://www.apache.org/licenses/LICENSE-2.0
#*
#* Unless required by applicable law or agreed to in writing, software
#* distributed under the License is distributed on an "AS IS" BASIS,
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#* See the License for the specific language governing permissions and
#* limitations under the License.
#*
#****************************************************************************** LDLIBS = -lusb
CFLAGS=-g dnw: dnw.o

ubuntu系统64位dnw的更多相关文章

  1. Ubuntu Linux14 64位下在Android studio下用gradle编译Andrid项目时发生libz.so.1共享库找不到的解决方法。

    ---恢复内容开始--- 我在Ubuntu14 64为下安装了AS,但在用Gradle编译项目时总是报找不到 libz.so.1的错误. error while loading shared libr ...

  2. GHOST WIN7系统64位经典优化版 V2016年

    来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统32,64位经典优化版 V2016年3月 系统概述 深度技术ghost win7系统64位经典优化版适用于笔 ...

  3. win7系统64位"禁用驱动程序签名强制"如何设置?

    换了Win7系统64位旗舰版的朋友是不是都发现了一点,以前32位Win7系统用的好好的小程序小应用,一下子就装不上了.这是由于Win7系统64位系统对于未有认证签名的驱动程序进行了限制安装,而大部分小 ...

  4. win7系统64位安装oracle10g

    win7系统64位安装oracle10g 下载地址: http://download.oracle.com/otn/nt/oracle10g/10204/10204_vista_w2k8_x64_pr ...

  5. Win7系统64位环境下使用Apache——安装Apache2.4时报错“Invalid command Order”问题的解决

    之前在文章Win7系统64位环境下使用Apache--Apache2.4整合Tomcat与mod_jk提到了安装Apache2.4时有可能报错: Invalid command 'Order', pe ...

  6. Win7系统64位环境下使用Apache——Apache2.4整合Tomcat与mod_jk

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70398091 本文出自[我是干勾鱼的博客] 之前的几篇文章: Win7系统64位 ...

  7. Win7系统64位环境下使用Apache——下载mod_jk

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70313329 本文出自[我是干勾鱼的博客] 之前在几篇文章: Win7系统64位 ...

  8. Win7系统64位环境下使用Apache——Apache2.4版本安装及卸载

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70255992 本文出自[我是干勾鱼的博客] 之前在Win7系统64位环境下使用A ...

  9. WIN7系统 64位出现 Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).

    WIN7系统 64位出现  Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).请安装 Microsoft Data Acces ...

随机推荐

  1. Zuul 超时设置

    问题描述 使用 Zuul 作为网关,偶发超时问题及第一次调用触发熔断问题 解决方案 超时问题 ribbon: ReadTimeout: 10000 SocketTimeout: 60000 第一次调用 ...

  2. vue中全局/按需引用element,样式都不生效

    简直是天坑啊,这个问题困扰了我一个晚上加今天一天,心里无数草泥马奔腾 被要求使用vue1.0+elementUI做一个后台管理项目,结果无论怎么操作elementUI,页面中都不显示css样式 谷歌百 ...

  3. 树莓派RTL8723BU_LINUX驱动安装

    1.安装前准备:sudo apt-get -y update;sudo apt-get -y upgrade;sudo apt-get -y dist-upgrade;sudo apt-get ins ...

  4. PyQt(Python+Qt)学习随笔:QScrollBar以及QAbstractSlider滚动条部件功能详解

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一.概述 在Designer输入部件中Horizo ...

  5. PyQt(Python+Qt)学习随笔:QTreeView树形视图的headerHiden属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTreeView树形视图的headerHiden属性用于控制视图中是否隐藏标题,为True隐藏,否 ...

  6. PyQt(Python+Qt)学习随笔:Qt Designer中部件的是否接受鼠标拖放事件的acceptDrops属性及含义

    acceptDrops属性表示当前部件是否接受鼠标拖放事件,鼠标拖放应该是与鼠标拖拽结合在一起的,在Qt Designer中可以通过属性acceptDrops设置部件是否接受鼠标拖放事件.如果部件接受 ...

  7. Tomcat启动报错org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file

    错误: 今天SVN导入新项目后启动项目时控制台报错,之后在网上搜了很多方法.下面列了一些大佬的解决方案: 1. 检查日志配置文件-logging.properties:https://www.cnbl ...

  8. CSS基础-背景

    CSS背景 background 纯色背景 {background-colcor:gray; padding:20px} 为元素设置背景色,并设置了内边距,使得元素中的文本向外少有延伸. 用rgba设 ...

  9. element ui中表格table翻页记忆勾选状态

    <el-table ref="multipleTable" :data="datalist" style="width:100%" @ ...

  10. 手写线程池,对照学习ThreadPoolExecutor线程池实现原理!

    作者:小傅哥 博客:https://bugstack.cn Github:https://github.com/fuzhengwei/CodeGuide/wiki 沉淀.分享.成长,让自己和他人都能有 ...