linux pc is at?linux for循环
at91sam9261 linux_at91sam9g45_at91sam9260资料
AT91SAM9261和ATMEL其它型号的ARM处理器使用高度相似的USART外设,因而驱动程序也具有高度的相似性,而且USART硬件支持485模式,用RTS信号作为485的收发控制。在使用中,只要将其置为485模式,其余的操作和普通的232操作一模一样,RTS的翻转是自动的。
我的板子上使用USART0扩展了一个485接口,而Linux原有串口驱动只支持普通的232模式,为了在Linux下方便地使用485接口,需要对原来的驱动程序稍加改动。
有关的文件
arch/arm/mach-at91/目录下:
at91sam9261_devices.c中的相关函数(不用改):
at91_add_device_serial()
并在此文件中确认相关的引脚已被正确配置,在这里关心的是USART0的TXD,RXD和RTS引脚
static inline void configure_usart0_pins(void)
{
at91_set_A_periph(AT91_PIN_PC8, 1);/* TXD0*/
at91_set_A_periph(AT91_PIN_PC9, 0);/* RXD0*/
at91_set_A_periph(AT91_PIN_PC10, 0);/* RTS0*/
at91_set_A_periph(AT91_PIN_PC11, 0);/* CTS0*/
}
这是另一个相关的文件,也不用改
board-sam9261ek.c
include/asm-arm/arch-at91/目录下
gpio.h中有相关引脚和at91_set_A_periph的原形声明
extern int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_gpio_output(unsigned pin, int value);
extern int __init_or_module at91_set_deglitch(unsigned pin, int is_on);
extern int __init_or_module at91_set_multi_drive(unsigned pin, int is_on);
接下来需要确定在哪里修改USART0的配置。at91sam9261 linuxat91sam9261 linux在芯片手册中,可以找到相关的寄存器名,以此为关键字搜索源码树。
在Linux源码树下搜索:
grep-r US_MR./
找到:drivers/serial/atmel_serial.c
其中有对串口的初始化代码,在文件中查找UART_PUT_MR,找到atmel_set_termios()函数
该函数是用户程序设置串口参数时必须调用的
在其中判断;当操作USART0时,设置为485模式:
if(AT91SAM9261_BASE_US0==(port)->membase){// in include/asm-arm/arch-at91/at91sam9261.h
嵌入式linux和嵌入式android系统有什么区别和联系
嵌入式android源码架构:uboot+linux kernel+android(包含文件系统,虚拟机,UI)
嵌入式linux:这是大部分人认识的linux uboot+linux kernel+文件系统+QT(UI),
当然两者的linux内核因为上层UI的不同会稍有差别,不过还是非常接近的,做过linux的人可以无缝切换到android底层开发,所以大家说的学习android系统,其实最重要的就是学习linux驱动,再加一下android下的专门的HAL,JNI,java等等,不过大公司android相关部分也是专门的人做的了。
甚至连QT都不用了,因为linux很多设备都是没有UI的,所以要来干啥?直接无界面,照样是嵌入式linux。
现在大家说的什么嵌入式debian,ubuntu,其实也是站在linux巨人的肩膀上,其实都不算是linux的分支,只算是linux的延伸,小变化而已。看到这里大家知道嵌入式linux的强大了吧,反正是比wince强大N倍啊。
O(∩_∩)O~,所以啊,学习嵌入式android,其实底下就是学习uboot,linux内核啊,不会搞这些就像搞应用一样,所以大家以为android就是java,是非常片面的。
以前老的,说了一下区别,可以参考一下
ARCH--这是Android修改了arch/arm下面的一些文件:
arch/arm:
Chg: arch/arm/kernel/entry-armv.S
Chg: arch/arm/kernel/module.c
Chg: arch/arm/kernel/process.c
Chg: arch/arm/kernel/ptrace.c
Chg: arch/arm/kernel/setup.c
Chg: arch/arm/kernel/signal.c
Chg: arch/arm/kernel/traps.c
Chg: arch/arm/mm/cache-v6.S
Chg: arch/arm/vfp/entry.S
Chg: arch/arm/vfp/vfp.h
Chg: arch/arm/vfp/vfphw.S
Chg: arch/arm/vfp/vfpmodule.c
Goldfish--这是Android为了模拟器所开发的一个虚拟硬件平台。Goldfish执行arm926T指令(在2.6.29中,goldfish也支持ATMv7指令),但是在实际的设备中,该虚拟平台的文件不会被编译。
arch/arm/mach-goldfish:
New: arch/arm/mach-goldfish/audio.c
New: arch/arm/mach-goldfish/board-goldfish.c
New: arch/arm/mach-goldfish/pdev_bus.c
New: arch/arm/mach-goldfish/pm.c
New: arch/arm/mach-goldfish/switch.c
New: arch/arm/mach-goldfish/timer.c
YAFFS2--和PC把文件存储在硬盘上不一样,移动设备一般把Flash作为存储设备。尤其是NAND flash应用非常广泛(绝大多数手机用的都是NAND flash,三星的一些手机使用的是OneNAND)。NAND flash具有低成本和高密度的优点。
YAFFS2是“Yet Another Flash File System, 2nd edition"的简称。它提供在Linux内核和NAND flash设备之前高效率的接口。 YAFFS2并没有包含在标准的Linux内核中, Google把它添加到了Android的kernel
fs/yaffs2:
New: fs/yaffs2/devextras.h
New: fs/yaffs2/Kconfig
New: fs/yaffs2/Makefile
New: fs/yaffs2/moduleconfig.h
New: fs/yaffs2/yaffs_checkptrw.c
New: fs/yaffs2/yaffs_checkptrw.h
New: fs/yaffs2/yaffs_ecc.c
New: fs/yaffs2/yaffs_ecc.h
New: fs/yaffs2/yaffs_fs.c
New: fs/yaffs2/yaffs_getblockinfo.h
New: fs/yaffs2/yaffs_guts.c
New: fs/yaffs2/yaffs_guts.h
New: fs/yaffs2/yaffsinterface.h
New: fs/yaffs2/yaffs_mtdif1.c
New: fs/yaffs2/yaffs_mtdif1.h
New: fs/yaffs2/yaffs_mtdif2.c
New: fs/yaffs2/yaffs_mtdif2.h
New: fs/yaffs2/yaffs_mtdif.c
New: fs/yaffs2/yaffs_mtdif.h
New: fs/yaffs2/yaffs_nand.c
New: fs/yaffs2/yaffs_nandemul2k.h
New: fs/yaffs2/yaffs_nand.h
New: fs/yaffs2/yaffs_packedtags1.c
New: fs/yaffs2/yaffs_packedtags1.h
New: fs/yaffs2/yaffs_packedtags2.c
New: fs/yaffs2/yaffs_packedtags2.h
New: fs/yaffs2/yaffs_qsort.c
New: fs/yaffs2/yaffs_qsort.h
New: fs/yaffs2/yaffs_tagscompat.c
New: fs/yaffs2/yaffs_tagscompat.h
New: fs/yaffs2/yaffs_tagsvalidity.c
New: fs/yaffs2/yaffs_tagsvalidity.h
New: fs/yaffs2/yportenv.h
Bluetooth-- Google为Bluetooth打上了patch,fix了一些Bluetooth的bug
drivers/bluetooth:
Chg: drivers/bluetooth/bfusb.c
Chg: drivers/bluetooth/bt3c_cs.c
Chg: drivers/bluetooth/btusb.c
Chg: drivers/bluetooth/hci_h4.c
Chg: drivers/bluetooth/hci_ll.c
Scheduler--对于Scheduler的改变非常小,我对它并没有去研究。
Chg: kernel/sched.c
New Android Functionality--除了fix一些bug以及其他一些小的更改,Android增加了一些新的功能,介绍如下:
IPC Binder-- The IPC Binder is an Inter-Process Communication(IPC) mechanism. It allows processes to provide services to other processes via a set of higher-level APIs than are available in standard Linux. An Internet search indicated that the Binder concept originated at Be, Inc., and then made its way into Palm's software, before Google wrote a new Binder for Android.
New: drivers/staging/android/binder.c
Low Memory Killer-- Android adds a low-memory killer that, each time it's called, scans the list of running Linux processes, and kills one. It was not clear in our cursory examination why Android adds a low-memory killer on top of the already existing one in the standard Linux kernel.
New: drivers/staging/android/lowmemorykiller.c
Ashmem-- Ashmem is an Anonymous SHared MEMory system that adds interfaces so processes can share named blocks of memory. As an example, the system could use Ashmem to store icons, which multiple processes could then access when drawing their UI. The advantage of Ashmem over traditional Linux shared memory is that it provides a means for the kernel to reclaim these shared memory blocks if they are not currently in use. If a process then tries to access a shared memory block the kernel has freed, it will receive an error, and will then need to reallocate the block and reload the data.
New: mm/ashmem.c
RAM Console and Log Device-- To aid in debugging, Android adds the ability to store kernel log messages to a RAM buffer. Additionally, Android adds a separate logging module so that user processes can read and write user log messages.
New: drivers/staging/android/ram_console.c
Android Debug Bridge-- Debugging embedded devices can best be described as challenging. To make debugging easier, Google created the Android Debug Bridge(ADB), which is a protocol that runs over a USB link between a hardware device running Android and a developer writing applications on a desktop PC.
drivers/usb/gadget:
New: drivers/usb/gadget/android.c
Chg: drivers/usb/gadget/composite.c
Chg: drivers/usb/gadget/f_acm.c
New: drivers/usb/gadget/f_acm.h
New: drivers/usb/gadget/f_adb.c
New: drivers/usb/gadget/f_adb.h
New: drivers/usb/gadget/f_mass_storage.c
New: drivers/usb/gadget/f_mass_storage.h
Android also adds a new real-time clock, switch support, and timed GPIO support. We list the impacted files for these new modules at the end of this document.
Power Management-- Power management is one of the most difficult pieces to get right in mobile devices, so we split it out into a group separate from the other pieces. It's interesting to note that Google added a new power management system to Linux, rather than reuse what already existed. We list the impacted files at the end of this document.
kernel/power:
New: kernel/power/consoleearlysuspend.c
New: kernel/power/earlysuspend.c
New: kernel/power/fbearlysuspend.c
Chg: kernel/power/main.c
Chg: kernel/power/power.h
Chg: kernel/power/process.c
New: kernel/power/userwakelock.c
New: kernel/power/wakelock.c
Miscellaneous Changes-- In addition to the above, we found a number of changes that could best be described as,'Miscellaneous.' Among other things, these changes include additional debugging support, keypad light controls, and management of TCP networking
... id-to-a-new-device/
linux驱动编写过程中遇到的几个问题及解决
1、显示错误:unknown field'ioctl' specified in initializer
解决办法,查看内核include/linux/fs.h文件,发现里边定义的struct file_operations中没有ioctl,这里我们用.unlocked_ioctl取代,形参去掉 struct inode*。
2、在应用程序中,将ioctl替换为unlocked_ioctl后,会出现以下错误:undefined reference to `unlocked_ioctl'。因为系统调用ioctl是没有改变的,还是原来的系统调用接口,只是系统调用的实现中,ioctl()变成了unlocked_ioctl,在应用层你根本不用关注内核中的这些实现上的改变,你只需要按照系统调用的用法用就可以了。所以把应用程序里的unlocked_ioctl改为ioctl,编译,OK,通过。
3、驱动编译完成,在开发板上insmod,出现以下错误:
WARNING: at lib/kobject.c:595 kobject_put+0x50/0x64()
kobject:'扑'(cbc60a00): is not initialized, yet kobject_put() is being called.
---[ end trace da227214a82491b9 ]---
insmod: cannot insert'led_dev.ko': Cannot allocate memory
原来是忘了写内存申请的代码,添加kmalloc和memset。
4、再次insmod,出现下列错误代码:
Unable to handle kernel paging request at virtual address 7f008820
pgd= cbc70000
[7f008820]*pgd=00000000
Internal error: Oops: 5 [#1]
Modules linked in: led_dev(+)
CPU: 0 Tainted: G W(3.0.1#439)
PC is at led_init+0xa8/0x108 [led_dev]
LR is at kobj_map+0x144/0x154
pc: [<bf0020a8>] lr: [<c0246e70>] psr: 60000013
sp: cbc6bf10 ip: cbc6beb0 fp: cbc6bf24
r10: 00000000 r9: bf002000 r8: cbc6a000
r7: 00000000 r6: bf0002bc r5: 00000000 r4: 00000000
r3: 00000000 r2: 00000000 r1: 7f008000 r0: 00000000
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 00c5387d Table: 5bc70008 DAC: 00000015
Process insmod(pid: 112, stack limit= 0xcbc6a268)
Stack:(0xcbc6bf10 to 0xcbc6c000)
bf00: 00000000 c07463c0 cbc6bf7c cbc6bf28
bf20: c00343c8 bf00200c cbc6bf64 cbc6bf38 c0073e24 00000000 00000000 00000000
bf40: 00000000 0000ef52 000d5bf9 bf0002bc 00000000 0000ef52 000d5bf9 bf0002bc
bf60: 00000000 c0034ce8 cbc6a000 00000000 cbc6bfa4 cbc6bf80 c0085960 c0034398
bf80: c00e8738 c00e8610 402004a8 000dfcf8 00000000 00000080 00000000 cbc6bfa8
bfa0: c0034b40 c00858e0 402004a8 000dfcf8 00b5d038 0000ef52 000d5bf9 ffff5f01
bfc0: 402004a8 000dfcf8 00000000 00000080 00000069 00000001 be9c2e64 be9c2e68
bfe0: be9c2e68 be9c2b14 00021cfc 402c1d74 60000010 00b5d038 5fffe821 5fffec21
[<bf0020a8>](led_init+0xa8/0x108 [led_dev]) from [<c00343c8>](do_one_initcall+0x3c/0x188)
[<c00343c8>](do_one_initcall+0x3c/0x188) from [<c0085960>](sys_init_module+0x8c/0x1a4)
[<c0085960>](sys_init_module+0x8c/0x1a4) from [<c0034b40>](ret_fast_syscall+0x0/0x30)
Code: e59f0060 eb52980e ea00000b e59f1058(e5910820)
---[ end trace da227214a82491b9 ]---
Segmentation fault
最后是各种百度,各种谷歌,参考别人的驱动,发现它们的开发板硬件地址并不是自己写的头文件,而是调用mach中已经定义好的头文件,好吧,寻找相应开发板,相应端口的地址头文件,在驱动文件中添加以下头文件:
#include<mach/map.h>
#include<mach/regs-gpio.h>
#include<mach/gpio-bank-m.h>
Ok,打完收工,开发板,测试。运行无阻。完成。
5、在做到DS18B20温度测试模块驱动的时候,看到网上的代码有些函数可以直接对引脚的功能进行设置,比如:s3c2410_gpio_cfgpin(DQ_PIN, DQ_PIN_OUTP);但是对应于我的s3c6410的开发板就不知道用什么函数了,网上找了半天,发现以上函数是在#include<plat/gpio-cfg.h>中,6410中对应的函数为:extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
6、最近学习移植linux内核,移植了新的linux内核以及挂载了新的NFS之后,重新测试led驱动,发现安装模块以后,运行测试程序会出现以下错误:
-/bin/sh:./main: not found(main为主机上编译好的测试程序)
原因:
编译busybox的时候选择了静态编译:
Build Options->
Build BusyBox as a static binary(no shared libs)
Build with Large File Support(for accessing file>2GB)
如果选择 Build BusyBox as a static binary(no shared libs)方式进行编译时,所需的库已经与程序静态地链接在一起,这些程序不需要额外的库就可以单独运行,但是自己编写的程序在文件系统上运行必须采用静态编译,否则会报诸如:bin/sh: main:not found的错误。
静态编译如:
arm-linux-gcc–static main.c–o main
7.按照普通方法安装配置tftp,并且关闭了防火墙,但是在开发板上tftp主机,总会报错:
tftp: server error:(0) Permission denied
解决办法:
修改文件/etc/sysconfig/selinux,设定其中的
SELINUX=disabled
然后重启电脑即可