OpenWrt system development notes

  openWrt English official website: https://openwrt.org/ Chinese official website: http://www.openwrt.org.cn/

1. Development environment and compilation

  There are two source codes on github that are used more.
  One is lede, the address is: https://github.com/coolsnowwolf/lede
  The other is the official source code of OpenWrt: https://github.com/lede-project
  Download lede The source code method is:

git clone https://github.com/coolsnowwolf/lede

  The official source code method for downloading OpenWrt is:

git clone https://github.com/openwrt/openwrt.git

2. Compile the module

  Compile a module separately, take myapp_test as an example

make package/myapp_test/clean          // 清除编译生成的文件  
make package/myapp_test/prepare        // 编译准备,下载、解压缩、打补丁  
make package/myapp_test/configure      // 根据设置选项配置生成Makefile  
make package/myapp_test/compile        // 根据Makefile进行编译  
make package/myapp_test/install        // 生成安装包  

3. Source directory

  OpenWrt top-level directory meaning:

config/         // 编译选项配置文件  
docs/           // 文档目录  
include/        // 包含准备环境脚本、下载脚本、编译Makefile以及编译指令  
package/        // 各种功能的安装包  
scripts/        // 包含准备环境脚本、下载脚本、编译Makefile以及编译指令  
target/         // 嵌入式平台  
toolchain/      // 编译器和C库等  
tools/          // 通用命令,用来生成固件的辅助工具  

  In the openWrt firmware, almost everything is a package, which can be compiled into an installation package ending in .ipk, so that it can be easily installed, upgraded and uninstalled.
  The meaning of the directory generated by openWrt compilation:

dl/             // 编译时下载软件代码包临时目录  
feeds/          // 扩展软件包目录  
bin/            // 编译完成后的最终成果目录  
build_dir/      // 编译中间文件目录  
staging_dir/    // 编译安装目录  
log/            // 如果打开了log选项,则编译log保存在该目录下  

Four, openWrt system package management

  After installing and entering the openWrt system, the openWrt package management method is:

4.1. Software package management

opkg update		// 更新可以安装的软件包列表
opkg install	// 安装软件包,需要第三个参数传递一个软件包的名称。如 opkg install file
opkg remove		// 卸载安装包,需要第三个参数传递一个软件包的名称。autoremove可以将不需要的安装包也删除。如 opkg remove file --autoremove
opkg upgrade	// 升级软件包,需要第三个参数传递一个软件包的名称。一般只用来升级应用(非内核软件)。

4.2. Query information:

opkg list					// 列出所有可使用的软件包
opkg list-installed			// 列出系统中已经安装的软件包
opkg list-changed-conffiles	// 列出用户修改过的配置文件
opkg files <pkg>			// 列出属于这个软件包中的所有文件
opkg search <file>			// 列出提供file的软件包,需要传递文件的绝对路径
opkg find <regexp>			// 列出软件包名称和regexp匹配的软件包
opkg info [pkg]				// 显示已安装pkg软件包的信息
opkg download <pkg>			// 将软件包pkg下载到当前目录
opkg print-architecture		// 列出安装包的架构
opkg whardepends [-A] [pkg]	// 针对已安装的软件包,输出依赖这个软件包的软件包

  opkg command options:
  -A Query all software packages
  -d <dest_name> Use dest_name as the root directory of package installation
  -f <conf_file> Use conf_file as opkg configuration file
  --nodeps Do not install according to dependencies, only install the package itself
  --autoremove automatically uninstall unused packages when uninstalling packages
  --force-reinstall force reinstall packages

Five, openWrt system configuration (UCI interface)

  The MVC (Model-View-Control) pattern is a classic web development programming pattern. openWrt also adopts this design pattern, and the model layer adopts the unified configuration interface UCI (Unified Configuration Interface).
  The core configuration files of the openWrt system are located in the /etc/config/ directory.
  For example, modify the network ip:

uci set network.lan.ipaddr=192.168.6.1
uci commit network

  Changes take effect by running the following command:

/etc/init.d/network restart

  As shown in the figure:
insert image description here
insert image description here
  common function configuration file meaning:

/etc/config/dhcp        // dnsmasq软件包配置,包含dhcp和dns设置  
/etc/config/dropbear    // SSH服务器选项  
/etc/config/firewall    // 防火墙设置,包含网络地址转换、包过滤、端口转发等  
/etc/config/network     // 网络配置,包含桥接、接口、路由配置  
/etc/config/system      // 系统配置,包含主机名称、网络时间同步等  
/etc/config/timeserver  // rdate的时间服务列表  
/etc/config/luci        // 基本的LuCI配置  
/etc/config/wireless    // 无限设置和wifi网络定义  
/etc/config/uhttpd      // web服务器选项配置  
/etc/config/upnpd       // miniupnpd UPnP服务设置  
/etc/config/qos         // 网络服务质量的配置文件定义  

Six, openWrt kernel configuration

6.1、sysctl

  sysctl.conf is the kernel configuration file preloaded by the system. The file location of sysctl.conf is in the directory of the openwrt source code file: package/base-files/files/etc/sysctl.conf. After compiling, generate /etc/sysctl.d/* in the openwrt system.
  In the openwrt system, it can be read and set through the sysctl command. For example:

/sbin/sysctl -a								# 显示所有的内核配置
/sbin/sysctl -n kernel.hostname				# 查询kernel.hostname的值
/sbin/sysctl -w kernel.hostname="zhangsan"	# 修改系统主机名称为zhangsan
/sbin/sysctl -p /etc/sysctl.conf			# 加载配置

insert image description here

6.2, /proc/sys/ directory

  Most available kernel parameters are in the /proc/sys/ directory. For example:
  query whether to enable route forwarding:

cat /proc/sys/net/ipv4/ip_forward

  Open the routing forwarding settings:

echo "1" > /proc/sys/net/ipv4/ip_forward

6.3. System configuration files

  System configuration file introduction:

/etc/rc.local       // 想要在开机后就执行的命令可以写入该文件  
/etc/profile        // 为系统的每个登陆用户设置环境变量  
/etc/shells         // openWrt采用的shell是 /bin/ash  
/etc/fstab          // 各种文件系统的描述信息  
/etc/services       // 互联网网络服务类型列表  
/etc/protocols      // 协议定义描述文件 

Guess you like

Origin blog.csdn.net/xxxx123041/article/details/132684562