Beagle Bone Black 的一些笔记

阅读: 评论:0

Beagle Bone Black 的一些笔记

Beagle Bone Black 的一些笔记

相关链接

这是 beagle bone black 的一些官方资料  包括硬件原理图等

这是 beagle bone black 的内核源码   进行驱动开发时可以用到,也可用它编译,制作系统 img 镜像。

这是源码编译,制作镜像的教程。

编译源码

/* 安装编译器 */
sudo apt-get install gcc-arm-linux-gnueabi
/* 一些需要的工具 */
sudo apt-get install gitsudo apt-get install lzopsudo apt-get install libssl-devsudo apt-get install u-boot-toolssudo apt-get install bcsudo apt-get install gcc
/* 克隆代码 */
git clone git://github/beagleboard/linux.git
cd linux/* 如果你的开发板已经有了系统,可以在开发板上查看一下内核版本 */
uname -r/* 并在 git 仓库 checkout 到对应版本 */
git checkout "kernel version"
/* 使用默认配置 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- bb_defconfig /* 编译 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4/* 制作镜像 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage dtbs LOADADDR=0x80008000 -j4/* make modules */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules -j4
/* 安装驱动到当前系统的 /lib/modules,用于驱动开发 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install/* 如果你是为了制作目标系统,并准备好了跟文件系统,可以用下面的命令 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=/home/cpeacock/export/rootfs modules_install

驱动编程示例

#include <linux/init.h>
#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{printk(KERN_ALERT "cs say hello world.");return 0;
}
static void hello_exit(void)
{printk(KERN_ALERT "cs say goodbye.");
}module_init(hello_init);
module_exit(hello_exit);
/* Makefile 里的路径根据这个结果 */
root@9df41fc004cc:~/Documents/codes/kernel/hello# ls /lib/modules/
4.14.108+
obj-m:=hello.o
KERNELDIR=/lib/modules/4.14.108+/build
PWD:=$(shell pwd)modules:$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

编译:

/* 编译之前将源码顶层的 Makefile 改为目标系统的架构和编译器 */
vim MakefileARCH            ?= arm
CROSS_COMPILE   ?= arm-linux-gnueabi-
root@9df41fc004cc:~/Documents/codes/kernel/hello# make
make -C /lib/modules/4.14.108+/build M=/root/Documents/codes/kernel/hello modules
make[1]: Entering directory '/root/Documents/kernel/linux'CC [M]  /root/Documents/codes/kernel/hello/hello.oBuilding modules, stage 2.MODPOST 1 modulesCC      /root/Documents/codes/kernel/d.oLD [M]  /root/Documents/codes/kernel/hello/hello.ko
make[1]: Leaving directory '/root/Documents/kernel/linux'
root@9df41fc004cc:~/Documents/codes/kernel/hello# ls
Makefile        hello.c   d.c  hello.o
Module.symvers  hello.ko  d.o  der
root@9df41fc004cc:~/Documents/codes/kernel/hello#

将在 docker 容器中编译好的 hello.ko 复制到宿主机: 

/* 查询正在运行的容器 name */
[wlb@Arco ~]$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS          PORTS     NAMES
d961fcf03def   ubuntu    "/bin/bash"   3 hours ago   Up 50 seconds             iubuntu/* 由 name 获取容器 id */
[wlb@Arco ~]$ sudo docker inspect -f '{{.ID}}' iubuntu
d961fcf03def1ad107a43df9d5b99018ff1c22bbe6174deb0ea9958d10c637d6/* 通过 id 来传递文件 */
[wlb@Arco ~]$ sudo docker cp d961fcf03def1ad107a43df9d5b99018ff1c22bbe6174deb0ea9958d10c637d6:/root/Documents/codes/kernel/hello/hello.ko ./[wlb@Arco ~]$ ls
Desktop  Documents  Downloads  hello.ko  Music  Pictures  Public  Templates  Videos/* 复制到开发板上 */
[wlb@Arco ~]$ scp hello.ko root@192.168.7.2:/root/

再将驱动程序复制到目标板里执行:

root@beaglebone:~# ls
cantool  codes	hello.ko/* 插入模块 */
root@beaglebone:~# insmod hello.ko /* 查看日志,有驱动程序 init 的输出 */
root@beaglebone:~# dmesg | grep hello
[12794.410293] hello: loading out-of-tree module taints kernel.
[12794.419633] cs say hello world.
[13521.043716] cs say hello world./* 移除模块 */
root@beaglebone:~# rmmod hello/* 查看日志,有驱动程序 exit 的文字输出 */
root@beaglebone:~# dmesg | grep good  
[12828.107863] cs say goodbye.
[13552.400169] cs say goodbye.

 

本文发布于:2024-01-30 21:27:03,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170662122622957.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:笔记   Beagle   Bone   Black
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23