当前位置:网站首页>Openwrt (VIII) application layer development

Openwrt (VIII) application layer development

2022-06-25 22:29:00 Embedded software development communication


One 、 The application and kernel layer

Many people begin to learn embedded system only after learning MCU Linux Of , At the beginning, I couldn't understand why writing two programs can light up LED, In the past, a single-chip computer only needed to write a program to go in LED You can control it ? This is the idea of layering brought about by the operating system . In fact, we can also directly control in the drive , But this loses the meaning of the operating system .

The driver is in the kernel layer , The application is in the application layer . Relationship between them :

application ——》 drive ( Call the driver to operate the underlying hardware )

Two 、 Application instance

Examples can best explain knowledge , Our application program calls the character driver in the previous section . The following content can be used as a template in the future .

1、 stay package Create a new folder chardrv_app Folder

2、 stay chardrv_app Create a new folder Makefile file , The contents are as follows :

       
#
# Copyright (C) 2009-2010 Jo-Philipp Wich <[email protected]>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=chardrv_app
PKG_RELEASE:=9

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/chardrv_app
SECTION:=utils
CATEGORY:=Utilities
TITLE:=CharDrv_app
DEPENDS:=+libncurses
endef

define Package/chardrv_app/description
This package contains an character driver.
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
endef

define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall" \
LDFLAGS="$(TARGET_LDFLAGS)"
endef

define Package/chardrv_app/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/chardrv_app $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,chardrv_app))
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.

above Makefile And driven Makefile Basically similar , It can be downloaded from package For other modules Makefile To make changes , I use the above nvram Of Makefile To modify .

3、 stay chardrv_app Create a new folder src Folder , stay src So let's make a new one Makefile file , The content is :

       
all: chardrv_app
OBJS = chardrv_app.o

CC = gcc
CCFLAGS = -Wall -c -o

%.o: %.c
$(CC) $(CCFLAGS) [email protected] $< $(LDFLAGS)

chardrv_app: $(OBJS)
$(CC) -o [email protected] $(OBJS) $(LDFLAGS)

clean:
rm -f rbcfg *.o
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

4、 stay src Under the new chardrv_app.c file . The contents are as follows :

       
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>

int main(int argc , char** argv)
{
// device handle
int fd;
int num = 1;

// Open the driver module
fd = open("/dev/chardrv" , O_RDWR|O_NONBLOCK);
if(fd < 0)
{
printf("can't open /dev/chardrv\n");
return -1;
}

// Function test
write(fd,&num,1);
read(fd,&num,1);
ioctl(fd,1,1);
close(fd);

return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.

5、make menuconfig Select module

OpenWRT( 8、 ... and ) Application layer development _ application

OpenWRT( 8、 ... and ) Application layer development _ The firmware _02

6、 Execute the following statements in turn to compile

make package/chardrv_app/compile V=99

make package/chardrv_app/install V=99

make package/index V=99

The compiled file is in openwrt/bin/ramips/packages/base/ Next , file name

chardrv_app_9_ramips_24kec.ipk

7、 Put the compiled firmware on the development board , Then test according to the following picture .

OpenWRT( 8、 ... and ) Application layer development _ application _03

3、 ... and 、 Problems and solutions

The following problems occurred while installing the app :

OpenWRT( 8、 ... and ) Application layer development _openwrt_04

resolvent :​ Reuse make V=99 compile openwrt The firmware , Then download to the development board . The above problem is that the firmware is the previous one , It's not the latest . The drivers and applications should be compiled before the routing firmware is recompiled , Otherwise, there will be this problem .

* When compiling, if the permission is insufficient , To add sudo, So you can compile and pass .



原网站

版权声明
本文为[Embedded software development communication]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181043571067.html

随机推荐