/* 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. Spring Cloud 学习 (一) Eureka

    微服务的功能主要有以下几个方面: 服务的注册和发现 服务的负载均衡 服务的容错 服务网关 服务配置的统一管理 链路追踪 实时日志 服务注册是指向服务注册中心注册一个服务实例,服务提供者将自己的服务信息 ...

  2. 第9.8节 Python使用writelines函数写入文件内容

    一. 语法 writelines(lines) 参数lines为一个列表,写入时列表中的每个元素不会自动添加换行符,因此通常需要在列表的每个元素后面添加换行符以确保写入的文件会分行. 注意:Pytho ...

  3. pandas 由其中几列生成新的列

    data是一个dataframe #data["x1"]=data[["a","b"]].apply(lambda x:x["a& ...

  4. Linq to SQL 语法整理(子查询 & in操作 & join )

    子查询 描述:查询订单数超过5的顾客信息 查询句法: var 子查询 = from c in ctx.Customers where (from o in ctx.Orders group o by ...

  5. 你知道Python基本数据类型是哪6个么

    Python 是强类型语言,在学习 Python 时,有必要了解 Python 有哪些基本数据类型,一共 6 个:Number(数字).String(字符串).List(列表).Tuple(元组).S ...

  6. 微信小程序中使用text-indent实现首行缩进

    问题由来:在小程序中使用text标签包裹了一段话,要做一个首行缩进的效果,但是不起效果 . 解决方法:使用view标签代替text,使用text-indent:2em即可解决.

  7. vue 编程式导航

    // 命名的路由(这里的name为路由中定义的name名称) this.$router.push({ name: 'user', params: { userId: '123' }}) // 带查询参 ...

  8. 题解-CF1418G Three Occurrences

    题面 CF1418G Three Occurrences 给一个 \(n\) 个数的序列 \(a_i\),求每个出现过的数出现次数为 \(3\) 的子序列个数. 数据范围:\(1\le n\le 5\ ...

  9. 【JAVA基础】静态方法

    /* * 与Python的静态单例比较: * 一样是需要加上static方法才可以直接调用类里面的私有方法 * * Python的类方法上 加上装饰器@staticmethod就可以不用实例化类而直接 ...

  10. dropload.min.js 下拉刷新后,无法上拉加载更多

    使用方法 1.引入文件 <script src="/app/media/js/dropload.min.js"></script> 111111111111 ...