一)环境
a)ubuntu18.04
b)arm-linux-gnueabi-gcc 7.5.0 / gcc 7.5.0
c)FriendlyArm tiny4412 标准版
d)linux-5.5
二)目标
a)hello驱动
b)hello应用
三)步骤
a)hello驱动
1)在drivers目录下新建文件夹tiny4412.
2)在tiny4412目录下新建文件hello.c,并做如下编码:
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
static int hello_probe(struct platform_device *pdev)
{
pr_info("enter %s\n", __func__);
return 0;
}
static int hello_remove(struct platform_device *pdev)
{
pr_info("enter %s\n", __func__);
return 0;
}
static void hello_shutdown(struct platform_device *pdev)
{
pr_info("enter %s\n", __func__);
return ;
}
static int hello_suspend(struct platform_device *pdev, pm_message_t state)
{
pr_info("enter %s\n", __func__);
return 0;
}
static int hello_resume(struct platform_device *pdev)
{
pr_info("enter %s\n", __func__);
return 0;
}
static const struct of_device_id tiny4412_hello_dt_match[] = {
{ .compatible = "tiny4412, hello" },
{},
};
static struct platform_driver tiny4412_hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = "hello",
.of_match_table = tiny4412_hello_dt_match,
},
};
module_platform_driver(tiny4412_hello_driver);
MODULE_LICENSE("GPL v2");
3)在tiny4412目录下新建文件Makefile,并做如下编码:
obj-$(CONFIG_TINY4412_HELLO) += hello.o
4)在tiny4412目录下新建文件Kconfig,并做如下编码:
menuconfig TINY4412_DRIVER
bool "TINY4412 DRIVER Support"
help
Select [Y] to enable tiny4412 driver.
if TINY4412_DRIVER
config TINY4412_HELLO
tristate "HELLO Support"
help
This option enables hello_world in /tiny4412/hello.
You'll need this to open hello driver.
It can be built as a module.
endif # TINY4412_DRIVER
4)修改drivers/Makefile,并添加如下编码:
obj-$(CONFIG_TINY4412_DRIVER) += tiny4412/
5)修改drivers/Kconfig,并添加如下编码:
source "drivers/tiny4412/Kconfig"
6)make menuconfig
6-1)选[Device Drivers]->[TINY4412 DRIVER Support]->[HELLO Support]
7)在exynos4412-tiny4412.dts中,添加如下编码:
hello {
compatible = "tiny4412, hello";
status = "okay";
};
8)make
9)make dtbs
b)hello应用
1)新增文件hello.c,做如下编码:
#include <stdio.h>
int main()
{
printf("hello, linux APP!\n");
return 0;
}
2)arm-linux-gnueabi-gcc -o hello hello.c, then cp hello into rootfs/usr/bin
3)use arm-linux-gnueabi-readelf to check *.so
4)make libc.so.6 and ld-linux.so.3 in rootfs/lib , then make ramdisk.img
c)测试
1)使用上面生成的uImage, dtb, ramdisk.img, 从SD卡启动TINY4412.
2)在TINY4412中运行/usr/bin/hello,即可看到打印"hello, linux APP!".