Openwrt固件编译(网件路由器netgear R6260)

作者: 胖宅 分类: Openwrt 发布时间: 2022-04-02 22:01

一、操作系统安装

  • 安装ubuntu20.04lts操作系统
  • 设置时区
root@ubuntu:~# timedatectl set-timezone Asia/Shanghai
  • 增加非root用户(openwrt编译过程最好不要用root用户)
root@ubuntu:~# adduser pangzhai
Adding user `pangzhai' ...
Adding new group `pangzhai' (1001) ...
Adding new user `pangzhai' (1001) with group `pangzhai' ...
Creating home directory `/home/pangzhai' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for pangzhai
Enter the new value, or press ENTER for the default
	Full Name []: panghz^H^[[3~
	Room Number []: abc
	Work Phone []: abc
	Home Phone []: abc
	Other []: abc
chfn: name with non-ASCII characters: 'pangh'
Is the information correct? [Y/n] y
root@ubuntu:~# adduser pangzhai sudo
Adding user `pangzhai' to group `sudo' ...
Adding user pangzhai to group sudo
Done.

二、编译涉及的软件包安装

  • 用pangzhai用户登陆
  • 设置国内源(采用阿里源)
pangzhai@ubuntu:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak
[sudo] password for pangzhai: 
pangzhai@ubuntu:~$ sudo vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
  • 更新源索引并安装依赖
pangzhai@ubuntu:/etc/apt$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Get:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [108 kB]
Get:4 http://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 Packages [915 kB]
Fetched 1,251 kB in 1s (1,618 kB/s)
Reading package lists... Done
pangzhai@ubuntu:/etc/apt$ sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext \
> git libncurses5-dev libz-dev patch python3.5 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 ccache mercurial cmake libjpeg8-dev

三、Openwrt工程下载并修改分支

  • 切换到用户根目录
  • 下载openwrt源码
pangzhai@ubuntu:/etc/apt$ cd
pangzhai@ubuntu:~$ git clone https://git.openwrt.org/openwrt/openwrt.git 
Cloning into 'openwrt'...
remote: Enumerating objects: 101726, done.
remote: Counting objects: 100% (150/150), done.
remote: Compressing objects: 100% (104/104), done.
remote: Total 101726 (delta 64), reused 119 (delta 42), pack-reused 101576
Receiving objects: 100% (101726/101726), 268.76 MiB | 13.88 MiB/s, done.
Resolving deltas: 100% (54652/54652), done.
Updating files: 100% (12443/12443), done.
  • 进入工程目录
  • 查看分支情况(git branch -a)
  • 切换所需要的分支(git tag查看分支列表,git checkout 切换分支)
  • 注:切换过程如果和本地版本冲突,可执行提交操作(git stash)
pangzhai@ubuntu:~/openwrt$ git branch -a
pangzhai@ubuntu:~/openwrt$ git tag
pangzhai@ubuntu:~/openwrt$ git stash
pangzhai@ubuntu:~/openwrt$ git checkout v21.02.1

四、添加所需包进行编译

  • 添加所需的feed源
pangzhai@ubuntu:~$ cd /home/pangzhai/openwrt/
pangzhai@ubuntu:~/openwrt$ vi feeds.conf.default 
src-git packages https://github.com/coolsnowwolf/packages
src-git luci https://github.com/coolsnowwolf/luci
src-git routing https://git.openwrt.org/feed/routing.git
src-git telephony https://git.openwrt.org/feed/telephony.git
src-git kenzo https://github.com/kenzok8/openwrt-packages
src-git small https://github.com/kenzok8/small
  • 更新并安装软件包(此过程可重复执行,出现warning可再执行一次,有些补丁包)
pangzhai@ubuntu:~/openwrt$ ./scripts/feeds update -a && ./scripts/feeds install -a
  • 配置固件及内核
pangzhai@ubuntu:~/openwrt$ make menuconfig 
  • 首次编译选择硬件型号及版本即可
  • 软件包、驱动包、内核包可根据需要勾选
  • 保存后生成.config配置文件
1、前三项设置硬件型号,内核及软件根据需要勾选
2、勾选需要安装的软件或者主题(*代表编入固件,M代表只编译不打包)
3、内核模块根据需要勾选(比如涉及usb功能加载usb驱动,涉及uvc设备加载video驱动等)
  • 鉴于部分安装包或者依赖太遥远,先进行下载操作,下载无误后再编译
  • 该操作主要是下载文件,文件存储目录为/home/pangzhai/openwrt/dl
  • 如果程序自动下载失败,可手动下载放入该目录
  • 为方便国内网友使用,参考(https://repository.pangzhai.cn/dl/
make download V=s
  • 最后一步执行编译操作(建议先多线程编译,出错后单线程找问题)
  • make -j1 V=s IGNORE_ERRORS=m (-j1代表单线程,V=s输出详细日志,忽略只编译出错的包)
make -j1 V=s IGNORE_ERRORS=m

五、重新编译

  • 生成的固件及安装包在/home/pangzhai/openwrt/bin下
  • 如果需要再次编译,删除/home/pangzhai/openwrt/tmp 及/home/pangzhai/openwrt/.config文件
  • 重新make menuconfig
  • make clean 清除前面编译的文件,免得出错
  • make -j5 V=s
  • 以上只是简单的固件编译步骤,特殊需求及详细定制化需要摸索,熟能生巧!
  • 编译的过程各种意外出错,非常邪乎,习以为常即可!

六、FAQ