Beagle Bone Black 的一些笔记

相关链接

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

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

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

编译源码

/* 安装编译器 */
sudo apt-get install gcc-arm-linux-gnueabi
/* 一些需要的工具 */
sudo apt-get install git

sudo apt-get install lzop

sudo apt-get install libssl-dev

sudo apt-get install u-boot-tools

sudo apt-get install bc

sudo apt-get install gcc
/* 克隆代码 */
git clone git://github.com/beagleboard/linux.git
cd linux

/* 如果你的开发板已经有了系统,可以在开发板上查看一下内核版本 */
uname -r

/* 并在 git 仓库 checkout 到对应版本 */
git checkout "kernel version"
/* 使用默认配置 */
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- bb.org_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 Makefile

ARCH            ?= 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.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/Documents/codes/kernel/hello/hello.mod.o
  LD [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   hello.mod.c  hello.o
Module.symvers  hello.ko  hello.mod.o  modules.order
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.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值