平台:

Ubuntu12.04 + 64bit

tiny4412ADK

1.首先要安装libusb-dev这个库,执行“sudo apt-get install libusb-dev”,装完之后就编译一个下载工具,网上有个牛人提供了一个。代码如下:

dnw.c

/* 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(!=usb_claim_interface(hdev, ))
{
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(-==fd)
{
perror("Cannot open file");
return NULL;
}
if(-==fstat(fd, &fs))
{
perror("Cannot get file size");
goto error;
}
write_buf = (unsigned char*)malloc(fs.st_size+);
if(NULL==write_buf)
{
perror("malloc failed");
goto error;
} if(fs.st_size != read(fd, write_buf+, fs.st_size))
{
perror("Reading file failed");
goto error;
}
unsigned short sum = ;
int i;
for(i=; i<fs.st_size+; 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+) = fs.st_size + ; //download size;
write_buf [fs.st_size + ] = sum & 0xff;
write_buf [fs.st_size + ] = sum >> ;
*len = fs.st_size + ;
return write_buf; error:
if(fd!=-) close(fd);
if(NULL!=write_buf) free(write_buf);
fs.st_size = ;
return NULL; } int main(int argc, char *argv[])
{
if(!=argc)
{
usage();
return ;
} struct usb_dev_handle *hdev = open_port();
if(!hdev)
{
return ;
} unsigned int len = ;
unsigned char* write_buf = prepare_write_buf(argv[], &len);
if(NULL==write_buf) return ; unsigned int remain = len;
unsigned int towrite;
printf("Writing data ...\n");
while(remain)
{
towrite = remain> ? : remain;
if(towrite != usb_bulk_write(hdev, 0x02, write_buf+(len-remain), towrite, ))
{
perror("usb_bulk_write failed");
break;
}
remain-=towrite;
printf("\r %d \t %d bytes ", (len-remain)*/len, len-remain);
fflush(stdout);
}
if(==remain) printf("Done!\n");
return ;
}

Makefile

#******************************************************************************
#*
#* Copyright (C) - 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

2. 把它保存为文件dnw.c,编译“gcc dnw2.c -o dnw -lusb”,编译完得到的dnw就是usb下载的PC端了。下载时用“dnw <filename>”下载文件到板上。也可生成的链接文件“sudo ln -s ./dnw /usr/sbin/dnw”,这样在编译完要下载文件就可以直接下载了。

Linux下DNW源码及安装的更多相关文章

  1. 在Linux下用源码编译安装apache2

    Linux下安装一个软件,最好去看下它的官方guide,apache2.4的安装安装guide 0. installation guide http://httpd.apache.org/docs/2 ...

  2. linux下如何源码编译安装vim

    1. 获取源码 git clone https://github.com/vim/vim.git ~/vim cd ~/vim 2. 配置 ./configure --prefix=/home/jel ...

  3. Linux 系统下用源码包安装软件

    Linux系统下用源码包安装软件 by:授客 QQ:1033553122 下载源码安装包,解压或者直接双击打开(如果有安装zip或rar等压缩/解压缩软件的话),查找相关的安装说明文件,一般是READ ...

  4. Linux环境PostgreSQL源码编译安装

    Linux环境PostgreSQL源码编译安装 Linux版本: Red Hat 6.4 PostgreSQL版本: postgresql-9.3.2.tar.gz 数据存放目录: /var/post ...

  5. Linux学习之源码包安装与脚本安装(十八)

    Linux学习之源码包安装与脚本安装 目录 源码包与RPM包的区别 源码包安装 脚本安装 源码包与RPM包的区别 1.区别 安装之前的区别:概念上的区别 安装之后的区别:安装位置不同 源码包: 开源的 ...

  6. linux下python3源码安装及卸载

    Linux下Python3的源码编译安装和卸载方法 [日期:2019-06-21] 来源:博客园  作者:wuli潇萧 [字体:大 中 小]     (一)Linux下软件的源码编译安装和卸载方法 L ...

  7. [整理]Linux下的源码安装步骤及其功能解释

    源码的安装一般由3个步骤组成:配置(./configure).编译(make).安装(make install). 这时最常用的命令就是这三个--./configure && make ...

  8. LINUX下编译源码时所需提前安装的常用依赖包列表

    yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-deve ...

  9. linux下如何源码安装expect

    1.作用 自动交互.比如如果用ssh登陆服务器,每次都输入密码,然而你觉得麻烦,那你就可以使用expect来做自动交互,这样的话就不用每次都输入密码 2.依赖 依赖tcl 3.获取源码 wget ht ...

随机推荐

  1. Spring MVC学习总结

    Spring MVC学习总结 Spring MVC学习路(一) 下载配置文件 Spring MVC学习路(二) 设置配置文件 Spring MVC学习路(三) 编写第一个demo Spring MVC ...

  2. 非常全的API接口查询

    http://www.apix.cn/services/category/3 https://www.showapi.com/ https://www.juhe.cn/docs http://deve ...

  3. 我给女朋友讲编程CSS系列(1) –添加CSS样式的3种方式及样式表的优先权

    如果说,原生态就是美,那么,我们就没有必要穿衣打扮. 网页是什么? 说白了,网页就是一堆[html标签]有序的搭配,让[CSS属性值]整整容,请[Javascript语言]处理一下事件. 一个人的整容 ...

  4. Python框架之Django学习笔记(五)

    第一个Django网页小结 进来的请求转入/hello/. Django通过在ROOT_URLCONF配置来决定根URLconf. Django在URLconf中的所有URL模式中,查找第一个匹配/h ...

  5. python2.X中文乱码

    在IDE下,加上# -- coding: UTF-8 -- 并且保证IDE也是utf-8编码. 在CMD下,这样执行会有乱码,为啥呢,因为cmd下是gbk编码的,你写的代码必须也是gbk编码的,你可以 ...

  6. 使用anaconda

    Please run $ source /opt/anaconda/bin/activate root    $ source /opt/anaconda/bin/deactivate root to ...

  7. 区分Activity的四种加载模式【转载】

    此文为转载,文章来源:http://marshal.easymorse.com/archives/2950 文章作者:   Marshal's Blog 参考文章:http://blog.csdn.n ...

  8. 【homework #1】第一次作业被虐感受

    当大二暑假结束,我发现我还是没有熟练掌握一门编程语言时,我就知道苦日子要来了. 这不,才开学第三周,就已经被虐的体无完肤了.连编译课用C语言写的词法分析,都要写很久.Debug很久才能写出来,更别提大 ...

  9. 求中位数为K的区间的数目

    给定一个长为 $n$ 的序列和常数 $k$,求此序列的中位数为 $k$ 的区间的数量.一个长为 $m$ 的序列的中位数定义为将此序列从小到大排序后第 $\lceil m / 2 \rceil$ 个数. ...

  10. JMeter 性能测试进阶实战

    课程简介 本课程制作的主要目的是为了让大家快速上手 JMeter,期间穿插了大量主流项目中用到的技术,以及结合当今主流微服务技术提供了测试 Dubbo 接口.Java 工程技术具体实施方案,注重实践. ...