这些都是自个从一月份开始学习ARM+Linux中遇到的问题做的笔记,我觉得很有用,所以分享出来!
因为没有老师教,自己琢磨遇到的问题很多,欢迎交流!
--------------------------------------------------------------------------------------------------
零点漂移队:封尘浪
---------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
0.平台搭建
--------------------------------------------------------------------------------------
下载 VMware11
下载 Ubutun 14
安装
解决 gedit 中文乱码
终端输入:
gsettings set org.gnome.gedit.preferences.encodings auto-detected "[‘GB18030‘, ‘GB2312‘, ‘GBK‘, ‘UTF-8‘, ‘BIG5‘, ‘CURRENT‘, ‘UTF-16‘]"
--------------------------------------------------------------------------------------
1.dnw工具安装
--------------------------------------------------------------------------------------
sudo apt-get install libusb-dev
dnw.c
#include <stdio.h>
#include <usb.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define TQ2440_SECBULK_IDVENDOR 0x5345
#define TQ2440_SECBULK_IDPRODUCT 0x1234
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( TQ2440_SECBULK_IDVENDOR==dev->descriptor.idVendor
&& TQ2440_SECBULK_IDPRODUCT==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: dnw <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;
}
printf("Filename : %s\n", filename);
printf("Filesize : %d bytes\n", fs.st_size);
*((u_int32_t*)write_buf) = 0x30008000; //download address
*((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size;
*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, 0x03, 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;
}
5编译: gcc -o dnw dnw.c -lusb
6.将文件copy到/usr/local/bin目录
# sudo cp dnw /usr/local/bin
----------------------------------------------------------------------------------------------
2. ARM-linux-gcc 安装
----------------------------------------------------------------------------------------------
sudo apt-get install gcc-arm-linux-gnueabi
arm-linux-gnueabi-gcc -v
记住:同时将 Makefile中修改为:
arm-linux-gnueabi-gcc -g -c -o led_on.o led_on.S
arm-linux-gnueabi-ld -Ttext 0x0000000 -g led_on.o -o led_on_elf
arm-linux-gnueabi-objcopy -O binary -S led_on_elf led_on.bin
----------------------------------------------------------------------------------------------
3. linux 串口助手 安装
----------------------------------------------------------------------------------------------
sudo apt-get minicom
CTRL+A+Z
设置串口无流控: ttyUSB0
--------------------------------------------------------------------------------
4. minicom 发送文件
--------------------------------------------------------------------------------
Ctrl+A S 选择要发送的文件
-----------------------------------------------------------------------------------
5. make menuconfig *** [scripts/kconfig/dochecklxdialog] 编译内核
------------------------------------------------------------------------------------
sudo apt-get install ncurses-dev
-----------------------------------------------------------------------
6. undefined reference to `__stack_chk_fail‘
undefined reference to `__stack_chk_guard‘
-----------------------------------------------------------------------
CFLAGS后面加上了-fno-stack-protector
-----------------------------------------------------------------------
7. GUI开发
下载 qt-creator-opensource-linux-x86_64-3.4.0
下载 qtcreator
-----------------------------------------------------------------------
------------------------------------------------------------------------
8.U-boot 移植 Linux Kernel 移植
-----------------------------------------------------------------------
在对应目录写驱动程序 xx_dev.c (gpio_dev.c)
然后写应用程序 xx.c (gpio.c)
同一目录下:
Kconfig
在内核源代码中添加对内核的支持
config TQ2440_GPIO_TEST
tristate "EmbedSky SKY2440/TQ2440 Board GPIO Test(control LED)"
depends on ARCH_S3C2440
default y if ARCH_S3C2440
help
GPIO control for EmbedSky SKY2440/TQ2440 Board.
Makefile: 内核目录修改为开发板的目录
配置编译该驱动
obj-$(CONFIG_TQ2440_GPIO_TEST) += dev_gpio.o
配置内核:make menuconfig
将其选择为 M 模块
编译内核 make zImage
编译模块 make SUBDIR = drivers/char/ modules
在对应目录找到 xx.ko 将其复制到开发板
insmod xx.ko
rmmod xx.ko
dmesg
--------------------------------------------------------------------------------