1.插入环境变量:
cd /etc
vim profile
在末尾加入:export PATH=<sdk path>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin:$PATH
Rebuild source using the top-level makefile in the SDK rootdirectory.
· make allrebuilds all components in the SDK
· makelinux configures and builds the kernel
· makeu-boot-spl builds u-boot and u-boot-spl
2.清除Kernel源码
make ARCH=armCROSS_COMPILE=arm-linux-gnueabihf- distclean
3.配置内核
在编译内核之前,需要配置哪些组件成内核镜像,哪些模块作为动态模块,
3.1默认配置
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- defconfig
After the configuration step has run the full configuration file is saved to the root of the kernel tree as .config.
e.g: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-am335x_evm_defconfig
3.2定制化配置
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
3.3编译内核
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage
This will result in a kernel image filebeing created in the arch/arm/boot/directory called zImage.
3.4编译设备树
在arch/arm/boot/dts/目录下:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- am335x-evmsk .dtb
3.5编译内核模块
很多驱动没有集成到zImage里面,而是在动态模块中。
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules
这会生成kernel object(.ko)文件。
4.安装kernel
4.1 将zImage 、 dtb 拷贝在文件夹(从这里开始读)Installing the Kernel Image and Device TreeBinaries。
cd <kernelsources dir>
sudo cparch/arm/boot/zImage <rootfs path>/boot
sudo cparch/arm/boot/dts/<dt file>.dtb <rootfs path>/boot
例如:
if you wanted to copy the kernel image and BeagleBone Black devicetree file to the rootfs partition of a SD card you would enter the below commands
cd <kernelsources dir>
sudo cparch/arm/boot/zImage arch/arm/boot/dts/am335x-boneblack.dtb /media/rootfs/boot
4.2安装模块
sudomake ARCH=arm INSTALL_MOD_PATH=<pathto root of file system> modules_install
For example if you are installing the moduleson the rootfs partition of the SD card you would do:
sudo make ARCH=arm INSTALL_MOD_PATH=/media/rootfsmodules_install
5.GPIO
http://processors.wiki.ti.com/index.php/Processor_SDK_Linux_GPIO_Driver_Overview
IRQ handling:
irq_num = gpio_to_irq(30)
- Request IRQ, make sure that irq_num should be non-error value
request_irq(irq_num, handler, 0,"gpio_test", NULL);
- Set IRQ type Raising/Falling/Level triggered
set_irq_type(irq_num, IRQ_TYPE_EDGE_RISING);
- During the clean-up path free the IRQ and gpio
free_irq(irq_num, NULL);
gpio_free(30);
Kernel Level
err = gpio_request(30,"sample_name");
gpio_direction_input(30);
Make pin 30 as output and set the value ashigh.
gpio_direction_output(30, 1);
Exporting that particular pin (30) to sysfsentry then use this API
gpio_export(30, true);
gpio_get_value(30);
User Space - Sysfs control
Enable GPIO sysfs support in kernelconfiguration and build the kernel
Device Drivers ---> GPIOSupport ---> /sys/class/gpio/...(sysfs interface)
Sysfs entries
Export the particular GPIO pin for usercontrol. GPIO30 is taken as example.
$ echo 30 >/sys/class/gpio/export
Change the GPIO pin direction to in/out
$ echo "out"> /sys/class/gpio/gpio30/direction
or
$ echo "in"> /sys/class/gpio/gpio30/direction
Change the value
$ echo 1 >/sys/class/gpio/gpio30/value
or
$ echo 0 >/sys/class/gpio/gpio30/value
Unexport the GPIO pin
$ echo 30 >/sys/class/gpio/unexport
查看GPIO被请求的情况
Run these commands for knowing what are theGPIO's already requested in the drivers.
$ mount -t debugfs debugfs /sys/kernel/debug
$ cat /sys/kernel/debug/gpio
查看设备号
$ cat /proc/devices
$ mknod /dev/设备名 c 主设备号 0