Compile specific OpenWRT version and change the mtdlayout

1. Clone OpenWRT project from github
git clone https://github.com/openwrt/openwrt.git

2. Find the release info from their github page. Click the 'X releases' tab can copy the commit number of the release you want.

3. Enter the folder of your cloned openwrt and reset header to that release.
git reset --hard <commit number>

4. Install feeds.
./scripts/feeds update -a
./scripts/feeds install -a

5. Config. You must choose your target according to your router.
make menuconfig
e.g.: For router Netgear WNDR4300
* Target System => Atheros AR7xxx/AR9xxx
* Subtarget  => Generic devices with nand flash
* Target Profile => Netgear WNDR4300v1
* You may need LuCi Web admin interface. Please choose LuCi/Collections/luci

6. Download all packages before make
make download

7. Make. (If you are in China, you may encounter some errors caused by GFW. Try to use a proxy to solve the problem.)
make

8. The image will be in ./bin/targets/<your target>/<your subtarget>

9. Try to flash the image to your router to check if your build configuration is right.

10. If the image works well. Then let's try to modify the mtdlayout.
* Find the flash configuration Make file in target/linux/<your target>/image/Makefile
e.g. : My router is Netgear WNDR4300. The Make file is target/linux/ar71xx/image/Makefile

According to my subtarget setting, the line 'include ./nand.mk' in that Makefile is where the make process will go. So open nand.mk and find 4300 relate lines.

Then we get 'define LegacyDevice/WNDR4300V1'. Obviously, this is a kind of 'LegacyDevice'. So let got legacy.mk to see real settings. 

Open legacy.mk and search for 4300. Notice the line 
'wndr4300_mtdlayout=mtdparts=ar934x-nfc:256k(u-boot)ro,256k(u-boot-env)ro,256k(caldata)ro,512k(pot),2048k(lan guage),512k(config),3072k(traffic_meter),2048k(kernel),23552k(ubi),25600k@0x6c0000(firmware),256k(caldata_ba ckup),-(reserved)' 
which is what we need. 

For WNDR4300 the default mtdlayout is 


OEM default layout

Netgear WNDR4300
Layer0 Atheros NAND Flash Controller: Micron NAND 128MiB 3,3V 8-bit [128MB]
Layer1 mtd0 u-boot 256KiB mtd1 u-boot-env 256KiB mtd2 caldata 256KiB mtd3 pot 512KiB mtd4 language 2MiB mtd5 config 512KiB mtd6 traffic_meter 2MiB mtd10 firmware 25MiB mtd11 caldata_backup 256KiB mtd12 reserved 96MiB
Layer2 mtd7 kernel 1152KiB mtd8 rootfs 24448KiB
mountpoint / /jffs
filesystem mini_fo/overlayfs
Layer3 mtd9 rootfs_data 15616KiB
mountpoint /rom /overlay
filesystem none none none none none none none none SquashFS JFFS2 none JFFS2

Openwrt default layout

Netgear WNDR4300
Layer0 Atheros NAND Flash Controller: Micron NAND 128MiB 3,3V 8-bit [128MB]
Layer1 mtd0 u-boot 256KiB mtd1 u-boot-env 256KiB mtd2 caldata 256KiB mtd3 pot 512KiB mtd4 language 2MiB mtd5 config 512KiB mtd6 traffic_meter 2MiB mtd9 firmware 25MiB mtd10 caldata_backup 256KiB mtd11 reserved 96MiB
Layer2 mtd7 kernel 2048KiB mtd8 ubiroot 23MiB
wear-leveling ubi and gluebi/overlayfs
Layer3 mtd12 rootfs 1860KiB* mtd13 rootfs_data 17980KiB*
mountpoint /rom /overlay
filesystem none none none none none none none none SquashFS JFFS2 none none
(These two tables are from https://openwrt.org/toh/netgear/wndr4300)

I want to enlarge mtd8 ubiroot (add 90M to ubiroot).
So change the mtdlayout setting to:
'wndr4300_mtdlayout=mtdparts=ar934x-nfc:256k(u-boot)ro,256k(u-boot-env)ro,256k(caldata)ro,512k(pot),2048k(lan guage),512k(config),3072k(traffic_meter),2048k(kernel),115712k(ubi),117760k@0x6c0000(firmware),256k(caldata_ba ckup),-(reserved)'

Then remake the openwrt image and flash it to the router to see if it works.

Please refer to the specific version of OpenWRT for Netgear WNDR4300v1 on this page: https://github.com/gongwan33/Netgear-WNDR4300-Openwrt

评论

此博客中的热门博文

Openwrt路由器上配置shadowsocks透明代理+gfwlist(PAC)

Configure shadowsocks transparent proxy + gfwlist(PAC) on OpenWRT Router

Using Haproxy + shadowsocks (ha + ss) to setup multi ss backend and load balance