openwrt源码编译环境搭建-安装Luci

openwrt系统源码编译环境搭建并安装Luci

简述

OpenWrt是一个基于Linux内核的开源嵌入式操作系统,专为路由器和嵌入式设备设计,具有高度模块化、可定制性和丰富的网络功能。

  • 核心特点

    可写文件系统:采用OverlayFS与SquashFS/JFFS2结合,支持软件包自由扩展,无需重新编译固件 。

    模块化设计:通过OPKG包管理系统(类似APT)管理超过3000个软件包,支持动态加载驱动和功能插件 。 ‌

    开源协议:遵循GPL协议,代码基于Linux内核、BusyBox等开源项目 。 ‌

  • 应用场景

    路由器:支持IPv6、动态防火墙、多WAN口等高级功能,适用于家用或企业级网络 。 ‌

    嵌入式设备:广泛用于工控、智能家居、VOIP设备等,提供定制化开发环境 。 ‌

openwrt官网
https://openwrt.org/

编译环境安装依赖库

安装编译需要的依赖库:

bash 复制代码
sudo apt-get update

sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install binutils
sudo apt-get install patch
sudo apt-get install bzip2
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install make
sudo apt-get install autoconf
sudo apt-get install gettext
sudo apt-get install texinfo
sudo apt-get install unzip
sudo apt-get install sharutils
sudo apt-get install subversion
sudo apt-get install libncurses5-dev
sudo apt-get install ncurses-term
sudo apt-get install zlib1g-dev
sudo apt-get install gawk
sudo apt-get install asciidoc
sudo apt-get install libz-dev
sudo apt-get install libssl-dev
sudo apt-get install ocaml-nox

下载源码

git克隆地址
https://git.openwrt.org/openwrt/openwrt.git

bash 复制代码
git clone  https://git.openwrt.org/openwrt/openwrt.git

cd openwrt
git branch -a # 查看远端分支
git checkout openwrt-24.10 # 切换到指定版本分支,这里使用最新版本

编译源码

bash 复制代码
cp feeds.conf.default feeds.conf # 拷贝fedd配置文件,后面有新的src-git可添加到此文件
./scripts/feeds update -a # 更新feed
./scripts/feeds install -a # 安装feed 依赖包

安装LUCI

openwrt默认没有安装LuCI,按装luci

bash 复制代码
./scripts/feeds update packages luci
./scripts/feeds install -a -p luci

openwrt源码编译环境搭建-安装Luci

编译配置

bash 复制代码
make defconfig # 生成默认配置文件
make menuconfig # 配置主板

配置开启uhttpd

bash 复制代码
-> Network                
	-> Web Servers/Proxies   
  	<*> uhttpd

配置uhttpd后才可以看到luci, 配置luci选项:

bash 复制代码
LuCI -->
          Collections -->
               < * > luci
          Applications-->
              <* > luci-app-ddns
              <* > luci-app-firewall
              <* > luci-app-ntpc
              <* > luci-app-samba 
<* > luci-app-uhttpd
          Themes-->全选
  • 编译固件
bash 复制代码
make download # 预先获取依赖包(可选但推荐)
make V=s # 编译固件,第一次编译,不推荐使用-j多线程选项
make -j$(nproc) V=s # 编译固件,之后可以使用-j选项加速
  • 烧录固件scp+sysupgrade命令

编译完成在/openwrt/bin/targets/XXX/xxx/目录下生成

文件结尾是-initramfs-kernel.bin用于跑RAM的固件

文件结尾是-squashfs-sysupgrade.bin用于跑升级的固件

用scp命令把xxx-sysupgrade.bin文件拷贝到设备/tmp目录下,root@192.168.1.1 为设备的IP地址

bash 复制代码
scp  openwrt-xxx-squashfs-sysupgrade.bin root@192.168.1.1:/tmp/

使用sysupgrade命令升级设备

bash 复制代码
sysupgrade /tmp/ openwrt-xxx-squashfs-sysupgrade.bin
  • 烧录固件tftpd工具
  1. 先把本机IP设置为192.168.1.2,只要和设备的IP在一个段域内即可。
  2. 设备连接串口工具如Xshell,SecureCRT等软件,设备上电后根据提示输入任意键进入Uboot界面,设置当前环境变量(即设置服务器IP和开发板本地客户端IP):
    setenv serverip 192.168.1.2
    setenv ipaddr 192.168.1.1(若与自己路由器ip冲突可以另外设置)
  3. 打开tftpd软件设置下烧写bin文件,以及当前服务器IP地址(即PC的本地IP):
  4. 串口工具uboot界面输入tftp命令传输bin文件到设备指定RAM地址:
    tftp 0x80000000 openwrt-xxx-squashfs-sysupgrade.bin
  5. 擦出Flash原有固件区域:
    erase 0x9f020000 +0x7c0000,
  6. 将tftp命令存储到RAM地址的固件数据写入刚擦除的原固件区域:
    cp.b 0x80000000 0x9f020000 0x7c0000
  7. reset命令重启或重新上电设备

SDK文件目录结构:

bash 复制代码
openwrt
├── bin # 编译固件存放目录
├── BSDmakefile
├── build_dir
├── config
├── Config.in
├── COPYING
├── dl
├── feeds
├── feeds.conf
├── feeds.conf.default
├── include
├── LICENSES
├── Makefile
├── package
├── README.md
├── rules.mk
├── scripts
├── staging_dir
├── target
├── tmp
├── toolchain
└── tools
相关推荐
Apipi*4 小时前
30天速通Linux 第六章信号及信号处理
linux·运维·信号处理
天启HTTP5 小时前
爬虫防封核心原理:IP轮换机制与风控规避逻辑
linux·服务器·网络·爬虫·tcp/ip
fly_sunnn5 小时前
STM32-GPIO
stm32·单片机·嵌入式硬件
广州浮点FLOATLIC7 小时前
许可证服务器迁移后软件打不开:研发 IT 怎样定位连接问题
linux·服务器·数据库
BLUcoding8 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom
AIgorithmGEEK8 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Nil2088 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)8 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter6258 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器
宵时待雨9 小时前
STM32基础1:嵌入式历史与生态
stm32·单片机·嵌入式硬件