1.访问Github下载CoreMP135源码, 本项目使用buildroot externel的方式编译, 与buildroot源码分别独立。
git clone https://github.com/m5stack/CoreMP135_buildroot.git
git clone https://github.com/m5stack/CoreMP135_buildroot-external-st.git
2.将两个工程放在同级目录下
├── Core135_buildroot
├── Core135_buildroot-external-st
1.进入Core135_buildroot目录
make BR2_EXTERNAL=../Core135_buildroot-external-st/ m5stack_coremp135_defconfig
make -j4
2.编译完成后, 在output/images
目录可以获取生成的sdcard.img
镜像文件。
1.CoreMP135的buildroot工程中将屏幕驱动等内容通过补丁方式加入到了源码工程,内核中已经整机上所有外设的驱动.后续的开发中,你可能会需要使用到自己开发的模块,下面以hello_world驱动举例.进行编译, 你可以通过以下方式编译,并安装到设备中.
1.创建一个hello_world_driver文件夹, 并包含以下文件Makefile
, hello_world_driver.c
//hello_world_driver.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple hello world kernel module");
static int __init hello_world_init(void)
{
printk(KERN_INFO "Hello, world!\n");
return 0;
}
static void __exit hello_world_exit(void)
{
printk(KERN_INFO "Goodbye, world!\n");
}
module_init(hello_world_init);
module_exit(hello_world_exit);
2.将Makefile文件中的内核地址指向buildroot目录中的linux内核路径, 工具链指向buildroot中使用的工具链路径。注意:请按照你实际工程路径修改
//Makefile
KERN_DIR := /home/sean/workspace/mp135/release/Core135_buildroot/output/build/linux-custom
CROSS_COMPILE := /home/sean/workspace/mp135/release/Core135_buildroot/output/host/bin/arm-none-linux-gnueabihf-
MODULE_NAME := hello_world_driver
PWD := $(shell pwd)
obj-m := $(MODULE_NAME).o
default:
$(MAKE) ARCH=arm -C $(KERN_DIR) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) modules
clean:
$(MAKE) ARCH=arm -C $(KERN_DIR) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) clean
3.运行以下指令进行模块编译, 将会输出模块.ko
文件
make