OpenWrt introduction and compilation basic tutorial

About OpenWrt

OpenWRT is a highly modular and highly automated embedded Linux system with powerful network components and scalability, and is often used in industrial control equipment, phones, small robots, smart homes, routers, and VOIP devices. At the same time, it also provides more than 100 compiled software, and the number is still increasing, and the OpenWrt SDK simplifies the process of developing software.

Unlike many other distributions for routers, OpenWRT is a fully-featured, easily moddable router operating system written from scratch. In practice, this means that you can use the features you want without adding additional baggage, and the support for these features is linux kernelfar newer than most distributions.

Advantages of OpenWrt

If you have a certain understanding of Linux systems and want to learn or get in touch with embedded Linux, OpenWRT is very suitable. Moreover, OpenWRT supports various processor architectures, whether it is ARM, X86, PowerPC or MIPS. It has as many as 3,000 kinds of software packages, including toolchain (toolchain), kernel (linux kernel), software package (packages), and root file system (rootfs), so that users only need a simple make Commands can easily and quickly customize an embedded system with specific functions to make firmware.

Generally, the development process of embedded Linux, whether it is an ARM, PowerPC or MIPS processor, must go through the following development process:

  1. Create a Linux cross-compilation environment;
  2. Build Bootloader;
  3. Porting the Linux kernel;
  4. Create Rootfs (root file system);
  5. Install the driver;
  6. install software;

After familiarizing with the basic development process of these embedded Linux, you are no longer limited to [ MIPS ] processors and wireless routers, you can try to transplant embedded Linux on other processors, or non-wireless router systems, customize your own application software, and Build a complete embedded product.

Compile OpenWrt preamble

The process of compiling OpenWrt is like a repeater, except for selecting system components, almost every compilation is to copy and paste the same command. And understand the function of each command and when to execute it, so as to better solve the problems encountered in the compilation and compile the firmware more smoothly.

Compile OpenWrt Basic Tutorial

1. Prepare the compilation environment

First install the Ubuntu 64bit system, Ubuntu 20.04 LTS x64 is recommended.
Do not use rootuser!

adduser openwrt
usermod -a -G sudo openwrt
su openwrt

2. Install compilation dependencies

Terminal command line input sudo apt-get update, then enter

sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync

3. Pull the source code

1:lede source code git clone https://github.com/coolsnowwolf/lede

2: Official source code git clone https://git.openwrt.org/openwrt/openwrt.git

3: Tianling source code git clone -b branch you want to pull --single-branch https://github.com/immortalwrt/immortalwrt

git clone (representing the meaning of cloning and pulling) is the open source address of the source code

4. Update and download feeds (take lede source code as an example)

Add third-party feeds source

Add in feeds:

src-git kenzok https://github.com/kenzok8/openwrt-packages
src-git small https://github.com/kenzok8/small

Find the file lede/feeds.conf.default

Copy the above two paragraphs into it and save

feeds is an extended software package, independent of the OpenWrt source code, so it needs to be pulled and updated separately.

Terminal cd lede to enter the source code directory:

./scripts/feeds update -a (更新feeds源)
./scripts/feeds install -a (安装feeds源)
# 为了保险建议打两遍和一样就没问题了

5. Configuration file settings

make menuconfig

insert image description here

Graphical configuration interface

OpenWrt Configuration【OpenWrt配置】

Target System (x86)> 目标系统(x86)

Subtarget (x86_64)> 子目标(x86_64)

Target Profile (Generic)>目标配置文件(通用)

Target Images —> 保存目标镜像的格式

Enable experimental features by default —> 默认情况下启用实验功能

Global build settings —> 全局构建设置

Advanced configuration options (for developers) ---- 高级配置选项(适用于开发人员)

Build the OpenWrt Image Builder 构建OpenWrt图像生成器

Build the OpenWrt SDK构建OpenWrt SDK

Package the OpenWrt-based Toolchain打包基于OpenWrt的工具链

Image configuration —>图像配置

Base system —> 基本系统

Administration —> 管理

Boot Loaders —>引导加载程序

Development —> 开发

Extra packages —> 额外包

Firmware —>固件

Fonts —>字体

Kernel modules —> 内核模块

Languages —>语言

Libraries —> 图书馆

LuCI —> LuCI 软件包

Mail —>邮件

Multimedia —>多媒体

Network —>网络

Sound —> 声音

Utilities —>实用程序

Xorg —>Xorg

Select the CPU architecture of your router.
It is recommended to only select the architecture for the first compilation, and leave nothing else, so that the compilation success rate will be higher. If you do not intend to adjust the components, enter make defconfig, which will detect the compilation environment and generate a default compilation configuration file.

6. Download the dl (dependency) library

#下载dl库(国内请尽量全局科学上网)
make -j8 download V=s 

j8 represents the number of your CPU threads 8=8 threads

But it seems that there is an upper limit. The actual speed of more than 5 threads is not much different. In the case of a good (scientific) network, the download can basically be completed within 5 minutes.

find dl -size -1024c -exec ls -l {
    
    } ;

This command can list incompletely downloaded files (according to my experience of compiling many times, files smaller than 1k are incompletely downloaded), if such files exist, you can use find dl -size -1024c -exec rm -f {} ; command to delete them, and then re-execute make download to download and check repeatedly to confirm that all files are complete, which can greatly improve the success rate of compilation and avoid wasting time. (This paragraph can not be executed)

7. Compile the firmware

make -j1 V=s

-j1: Use single-threaded compilation. Novices recommend single-threaded compilation, firstly because metaphysical problems may have a high success rate, and secondly because it is convenient to view error logs.
V=s: Output detailed logs, used to find errors when compilation fails. Moreover, the full-screen code can be pretended to be running, and it takes several hours to run, and the pretending is more durable. (also mentioned above)

Output path after compilation is complete:bin/targets

8. Reconfigure if necessary

rm -rf ./tmp && rm -rf .config
make menuconfig
make -j(((((nproc) + 1)) V=s   #(多线程编译失败后自动进入单线程编译,失败则输出详细日志)

9. Compile and replace the firmware of other CPU architectures (recommended operation)

Clear old build artifacts

make clean

Execute after a large-scale update of the source code or a kernel update to ensure the compilation quality. This action deletes files in the /bin and /build_dir directories.

Clear old compilation products, cross-compilation tools, tool chains and other directories

make dirclean

It must be executed before compiling to change the architecture. This operation deletes files in the /bin and /build_dir directories (make clean) as well as files in /staging_dir, /toolchain, /tmp, and /logs.

Clean up files other than OpenWrt source code (optional)

make distclean

Unless you are doing development and plan to push to a remote warehouse like GitHub, it is almost useless. This operation is equivalent to make dirclean plus delete /dl, /feeds directory and .config file.

Restore OpenWrt source code to initial state (optional)

git clean -xdf

If the source code is changed, or it has not been compiled for a long time, it will be used.

clear temporary files

rm -rf tmp

Delete some temporary files generated after executing make menuconfig, including retrieval information of some software packages. After deletion, the software packages in the package directory will be reloaded. If it is not deleted, some newly added software packages will not be displayed.

Delete the compilation configuration file

rm -f .config

If some components are deselected without deletion, their dependent components will not be automatically cancelled, so it is recommended to delete them when components need to be adjusted.

All operations do not require root users

That's all for today's tutorial, and I will talk about personalized customization later.

The compiled network disk is available and can be used directly. Download address: https://pan.wwang.pw

information, the software packages in the package directory will be reloaded after deletion. If it is not deleted, some newly added software packages will not be displayed.

Delete the compilation configuration file

rm -f .config

If some components are deselected without deletion, their dependent components will not be automatically cancelled, so it is recommended to delete them when components need to be adjusted.

All operations do not require root users

That's all for today's tutorial, and I will talk about personalized customization later.

Guess you like

Origin blog.csdn.net/u010674953/article/details/129280724