ubuntu系统64位dnw
/* 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的更多相关文章
- Ubuntu Linux14 64位下在Android studio下用gradle编译Andrid项目时发生libz.so.1共享库找不到的解决方法。
---恢复内容开始--- 我在Ubuntu14 64为下安装了AS,但在用Gradle编译项目时总是报找不到 libz.so.1的错误. error while loading shared libr ...
- GHOST WIN7系统64位经典优化版 V2016年
来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统32,64位经典优化版 V2016年3月 系统概述 深度技术ghost win7系统64位经典优化版适用于笔 ...
- win7系统64位"禁用驱动程序签名强制"如何设置?
换了Win7系统64位旗舰版的朋友是不是都发现了一点,以前32位Win7系统用的好好的小程序小应用,一下子就装不上了.这是由于Win7系统64位系统对于未有认证签名的驱动程序进行了限制安装,而大部分小 ...
- win7系统64位安装oracle10g
win7系统64位安装oracle10g 下载地址: http://download.oracle.com/otn/nt/oracle10g/10204/10204_vista_w2k8_x64_pr ...
- Win7系统64位环境下使用Apache——安装Apache2.4时报错“Invalid command Order”问题的解决
之前在文章Win7系统64位环境下使用Apache--Apache2.4整合Tomcat与mod_jk提到了安装Apache2.4时有可能报错: Invalid command 'Order', pe ...
- Win7系统64位环境下使用Apache——Apache2.4整合Tomcat与mod_jk
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70398091 本文出自[我是干勾鱼的博客] 之前的几篇文章: Win7系统64位 ...
- Win7系统64位环境下使用Apache——下载mod_jk
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70313329 本文出自[我是干勾鱼的博客] 之前在几篇文章: Win7系统64位 ...
- Win7系统64位环境下使用Apache——Apache2.4版本安装及卸载
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70255992 本文出自[我是干勾鱼的博客] 之前在Win7系统64位环境下使用A ...
- WIN7系统 64位出现 Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).
WIN7系统 64位出现 Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).请安装 Microsoft Data Acces ...
随机推荐
- 我与PHP,ULM和Vue.js不得不说的故事(一个放荡不羁与一个神神秘秘一个似曾相识,从入门到放弃记录第二章)
·关于UML(git) 究竟是命运在茫茫语言之中遇到了你,还是我的魅力让你向我奔涌而来.好吧都不是,我俩就像古代包办婚姻,被专业牢牢的绑在一起了,既然都是一条绳上的蚂蚱.我我们应该能体谅彼此的不容易, ...
- MySQL数据库入门学习
一. 前言 作为一名大二在校生,因为正在学习网页设计,考虑到后台问题,所以便自学了数据库,可能给大家总结的不是很全,但是一些必要的点肯定会讲到.现在市场上有很多图形化的数据库, 二. MySQL基础知 ...
- ccpc赛前记
距离ccpc比赛还不到一个小时了,有些紧张又有些兴奋 作为留学选手参加国内的比赛感觉好像很奇怪?谁能想到一个疫情会让我拿ccpc结束自己的acm生涯(也许,谁知道呢) cf上蓝了 该准备gre了,目标 ...
- 第八章 Python类中常用的特殊变量和方法
上章花了近三十章节介绍类的知识,本章估计内容也比较多,讲完这些,其实还有更多.为什么这么多类有关的知识呢,这是因为在Python里面一切皆对象,就连整型.浮点数.字符串这些比较常规的类型都是作为类来实 ...
- PyQt(Python+Qt)学习随笔:model/view架构中的QStandardItemModel使用案例
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 1.案例说明 在应用中展示指定目录的图标文件的文件名和图标,界面就是一个简单的窗口上面放置一名为li ...
- 安装nginx并安全地配置和启动
一.安装nginx >>参考文章<< 安装教程,看代码&注释 # .sh # 如果centos服务器是最低安装,则先安装weget yum install -y wge ...
- 题解-CF755G PolandBall and Many Other Balls
题面 CF755G PolandBall and Many Other Balls 给定 \(n\) 和 \(m\).有一排 \(n\) 个球,求对于每个 \(1\le k\le m\),选出 \(k ...
- 学习笔记:Kruscal 重构树
网上感觉没有什么很详细 + 证明的讲解啊) 前置:Kruskal 求最小生成树. 这个算法可以将一棵树 / 无向连通图重构成一颗有性质的新树. 算法可以解决一些树上瓶颈边权之类的问题,可以把需要持久化 ...
- 使用 open 函数 写的代码 用户名登录
先创建文件ha.log 内容: aaa$$123bbb$$456 def dl(user,pas): f = open('ha.log', 'r', encoding="utf-8" ...
- JApiDocs(自动生成接口文档神器)
JApiDocs教程 前言 作为一名优秀的程序员来说,由于涉及到要与前端进行对接,所以避免不了的就是写接口文档.写完接口文档,一旦代码返回结果,参数等出现变动,接口文档还得随之改动,十分麻烦,违背了我 ...