Open-Wrt: Base Build and Flash Steps

In this section, you are going to learn

How to build a base image for openwrt ?

How to generate full base openwrt image for RPI-4B ?

How to flash full base openwrt image for RPI-4B ?

How to run minicom and work remotely with RPI-4B ?

How to do pre-build and post-build checks ?

Topics in this section,

  • In this section, we will see how to clone and add configurations for openwrt build directory

$ cd $HOME
  • Clone the directory inside the sources directory

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

$ cd openwrt
  • In this secion, we will see how to intialize,add build configurations and set locale settings

$ pwd

$HOME/openwrt
  • Update and Install latest feeds

$ ./scripts/feeds update -a

$ ./scripts/feeds install -a

In this section you will learn how to enable in menuconfig

$ make menuconfig
  • Make sure the current directory is “openwrt”

* In Target System select Broadcom BCM27xx
        Target System (Broadcom BCM27xx)
                BCM2711 boards (64 bit)

* In Subtarget select BCM2711 boards (64 bit)
        Subtarget
                (X) BCM2711 boards (64 bit)

* In Target Profile select (X) Raspberry Pi 4B/400/CM4 (64bit)
        Target Profile (Raspberry Pi 4B/400/CM4 (64bit))
                 (X) Raspberry Pi 4B/400/CM4 (64bit)

* In Network select below options and click "y" to select
          <*> ethtool......................... Display or change ethernet card settings
          <*> fping................... sends ICMP ECHO_REQUEST packets to network hosts
          <*> iperf......................... Internet Protocol bandwidth measuring tool
          [*] Enable multicast support
          <*> iperf3........................ Internet Protocol bandwidth measuring tool
          <*> iputils-arping............................................ iputils-arping
          <*> iputils-ping................................................ iputils-ping
          [*] Install legacy ping4 and ping6 symlinks
          <*> tcpdump..................... Network monitoring and data acquisition tool


* In Network select WirelessAPD and enable below options
        Network
          WirelessAPD
                <*> hostapd........................ IEEE 802.1x Authenticator (built-in full)
                <M> hostapd-basic.............. IEEE 802.1x Authenticator (WPA-PSK, 11r, 11w)
                <M> hostapd-basic-openssl... IEEE 802.1x Authenticator (WPA-PSK, 11r and 11w)
                <M> hostapd-basic-wolfssl... IEEE 802.1x Authenticator (WPA-PSK, 11r and 11w)
                <*> wpa-supplicant............................ WPA Supplicant (built-in full)
                <*> wpa-cli...................... WPA Supplicant command line control utility
                <M> wpa-supplicant-basic........................... WPA Supplicant (11r, 11w)
                <M> wpa-supplicant-mini............................. WPA Supplicant (minimal)
                <M> wpa-supplicant-openssl..................... WPA Supplicant (OpenSSL full)
                <M> wpa-supplicant-p2p.................... WPA Supplicant (Wi-Fi P2P support)
                <M> wpa-supplicant-wolfssl..................... WPA Supplicant (wolfSSL full)
                <M> wpad-basic-wolfssl....... IEEE 802.1x Auth/Supplicant (wolfSSL, 11r, 11w)

* In Base System select below options
        <*> procd-ujail.................................. OpenWrt process jail helper
        <*> swconfig.................................... Switch configuration utility
        <*> uci................ Utility for the Unified Configuration Interface (UCI)
        <*> urandom-seed...................... /etc/urandom.seed handling for OpenWrt
        <*> urngd (NEW)
        <*> wireless-tools.......... Tools for manipulating Linux Wireless Extensions


* In Utilities select below options
        <*> file..................................... File type determination utility
        <*> findutils....................................... GNU Find Utilities (all)
        -*- findutils-find......................... GNU Find Utilities - find utility
        -*- findutils-locate........ GNU Find Utilities - locate and updatedb utility
        -*- findutils-xargs....................... GNU Find Utilities - xargs utility
        <*> grep.................................. grep search utility - full version



* In Utilities select Disc and enable below options
        <*> fdisk.................................... manipulate disk partition table
  • Save all the configuration settings

  • Exit once the configurations are saved

  • In this section you will learn how to do Pre-build checks

  • Below are the options should be enabled

  • In Broadcom BCM27xx option are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • In Network category options are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • Inside Network category WirelessAPD options are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • In Base System category options are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • In Utilities category options are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • Inside Utilities category Disc options are enabled

    • Make sure the current directory is “openwrt”

    • Check those lines in .config file

  • TODO


  • Once all the configurations is added run from build directory to build the base openwrt image.

$ cd $HOME/openwrt

$ make

In this section you will learn how to do Post-build checks

  • In this section we will know locations of .config file and tool chain

$ cd $HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/linux-bcm27xx_bcm2711/linux-6.1.69

$ cat .config
$ cd $HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin

$ ls -l bin

-rwxr-xr-x 2 test 2226840 Dec 23 02:58 ar
-rwxr-xr-x 2 test 3467944 Dec 23 02:58 as
-rwxr-xr-x 4 test 4025768 Dec 23 02:58 ld
-rwxr-xr-x 4 test 4025768 Dec 23 02:58 ld.bfd
-rwxr-xr-x 2 test 2217128 Dec 23 02:58 nm
-rwxr-xr-x 2 test 2353136 Dec 23 02:58 objcopy
-rwxr-xr-x 2 test 3870336 Dec 23 02:58 objdump
-rwxr-xr-x 2 test 2226872 Dec 23 02:58 ranlib
-rwxr-xr-x 2 test 1284528 Dec 23 02:58 readelf
-rwxr-xr-x 2 test 2353136 Dec 23 02:58 strip
  • Explanation of individual tools in bin

  • ar: Create, Modify, and Extract from archives

  • as: The portable GNU assembler

  • ld: The GNU linker

  • ld.bfd: The linker accesses object and archive files using the BFD (Binary File Descriptor) libraries.

  • nm: List symbols from object files

  • objcopy: Copy and translate object files

  • objdump: Display information from object files

  • ranlib: Generate an index to an archive

  • readelf: Display information about ELF (Executable and Linkable Format) files

  • strip: Discard symbols and other data from object files

  • In this section we will see how to do static image verification checks

  • Make sure the current directory is “openwrt”

$ pwd

$HOME/openwrt/bin/targets/bcm27xx/bcm2711


$ ls -l

-rw-r--r-- 1 test     1652 Jan 16 14:18 config.buildinfo
-rw-r--r-- 1 test       83 Jan 16 14:18 feeds.buildinfo
-rw-r--r-- 1 test 17117078 Jan 16 14:20 openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
-rw-r--r-- 1 test 17117925 Jan 16 14:20 openwrt-bcm27xx-bcm2711-rpi-4-ext4-sysupgrade.img.gz
-rw-r--r-- 1 test     4207 Jan 16 14:20 openwrt-bcm27xx-bcm2711-rpi-4.manifest
-rw-r--r-- 1 test 15350996 Jan 16 14:20 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img.gz
-rw-r--r-- 1 test 15351843 Jan 16 14:20 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-sysupgrade.img.gz
drwxr-xr-x 2 test     4096 Jan 16 14:20 packages
-rw-r--r-- 1 test     2141 Jan 16 14:20 profiles.json
-rw-r--r-- 1 test      912 Jan 16 14:20 sha256sums
-rw-r--r-- 1 test       18 Jan 16 14:20 version.buildinfo
  • Explanation of image files

  • config.buildinfo: Creating a config from .config backup or config.buildinfo

  • feeds.buildinfo: Collection of packages.

  • openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz: In this openwrt image is built

  • openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz: In this openwrt image is built

  • ext4: This firmware contains a regular ext4 Linux partition

  • factory: Use when flashing

  • img: image file

  • gz: extension for gzip

  • sysupgrade: sysupgrade is designed to be flashed from OpenWrt/LEDE itself

  • manifest:

  • squashfs: This firmware contains a type of partition that is compressed and mounts read-only

  • profiles.json: A profile is a set of documents with a profile relationship to the profile.

  • json: JavaScript Object Notation

  • sha256sums: An SHA-256 checksum is a sequence of numbers and letters that you can use to check that your copy of a downloaded update file is identical to the original

  • version.buildinfo: It will be version of the openwrt

$ du -h openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz

17M     openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
  • To extract image file following are the commands

$ pwd

$HOME/openwrt/bin/targets/bcm27xx/bcm2711
  • After extracting you will get openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img

$ gunzip openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz

$ ls -l

-rw-r--r-- 1 test      1652 Jan 16 19:57 config.buildinfo
-rw-r--r-- 1 test        71 Jan 16 19:57 feeds.buildinfo
-rw-r--r-- 1 test 184549376 Jan 16 20:02 openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img
-rw-r--r-- 1 test  17117911 Jan 16 19:58 openwrt-bcm27xx-bcm2711-rpi-4-ext4-sysupgrade.img.gz
-rw-r--r-- 1 test      4207 Jan 16 19:58 openwrt-bcm27xx-bcm2711-rpi-4.manifest
-rw-r--r-- 1 test  15351033 Jan 16 19:58 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img.gz
-rw-r--r-- 1 test  15351880 Jan 16 19:58 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-sysupgrade.img.gz
drwxr-xr-x 2 test      4096 Jan 16 19:58 packages
-rw-r--r-- 1 test      2141 Jan 16 19:59 profiles.json
-rw-r--r-- 1 test       912 Jan 16 19:59 sha256sums
-rw-r--r-- 1 test        18 Jan 16 19:57 version.buildinfo
$ file openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img

openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img: DOS/MBR boot sector; partition 1 : ID=0xc, active, start-CHS (0x20,2,3), end-CHS (0x228,2,34), startsector 8192, 131072 sectors; partition 2 : ID=0x83, start-CHS (0x249,0,37), end-CHS (0x196,1,25), startsector 147456, 212992 sectors

* There are 2 partitions are there in .img file
  • kpartx: Create device maps from partition tables

$ sudo apt-get install kpartx
  • -a: Add partition mappings

  • -v: Operate verbosely

$ sudo kpartx -av openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img

add map loop29p1 (253:0): 0 131072 linear 7:29 8192
add map loop29p2 (253:10): 0 212992 linear 7:29 147456
$ sudo mkdir -p /mnt/boot

$ sudo mount /dev/mapper/loop29p1 /mnt/boot

$ sudo mkdir -p /mnt/root

$ sudo mount /dev/mapper/loop29p2 /mnt/root
$ ls -l /mnt/boot

-rwxr-xr-x 1 root root    54477 Dec 21 15:56 bcm2711-rpi-400.dtb
-rwxr-xr-x 1 root root    54388 Dec 21 15:56 bcm2711-rpi-4-b.dtb
-rwxr-xr-x 1 root root    54997 Dec 21 15:56 bcm2711-rpi-cm4.dtb
-rwxr-xr-x 1 root root       90 Dec 21 15:56 cmdline.txt
-rwxr-xr-x 1 root root      581 Dec 21 15:56 config.txt
-rwxr-xr-x 1 root root      496 Dec 21 15:56 COPYING.linux
-rwxr-xr-x 1 root root      638 Dec 21 15:56 distroconfig.txt
-rwxr-xr-x 1 root root     3171 Dec 21 15:56 fixup4cd.dat
-rwxr-xr-x 1 root root     5394 Dec 21 15:56 fixup4.dat
-rwxr-xr-x 1 root root     8378 Dec 21 15:56 fixup4x.dat
-rwxr-xr-x 1 root root 12068872 Dec 21 15:56 kernel8.img
-rwxr-xr-x 1 root root     1594 Dec 21 15:56 LICENCE.broadcom
drwxr-xr-x 2 root root    24576 Dec 21 15:56 overlays
-rwxr-xr-x 1 root root   803644 Dec 21 15:56 start4cd.elf
-rwxr-xr-x 1 root root  2248864 Dec 21 15:56 start4.elf
-rwxr-xr-x 1 root root  2996328 Dec 21 15:56 start4x.elf

$ ls -l /mnt/root

drwxr-xr-x  2 root root 4096 Dec 21 15:56 bin
drwxr-xr-x  2 root root 4096 Dec 21 15:56 dev
drwxr-xr-x 23 root root 4096 Dec 21 15:56 etc
drwxr-xr-x 11 root root 4096 Dec 21 15:56 lib
lrwxrwxrwx  1 root root    3 Dec 21 15:56 lib64 -> lib
drwx------  2 root root 4096 Jan  1  1970 lost+found
drwxr-xr-x  2 root root 4096 Dec 21 15:56 mnt
drwxr-xr-x  2 root root 4096 Dec 21 15:56 overlay
drwxr-xr-x  2 root root 4096 Dec 21 15:56 proc
drwxrwxr-x  2 root root 4096 Dec 21 15:56 rom
drwxr-x---  2 root root 4096 Dec 21 15:56 root
drwxr-xr-x  2 root root 4096 Dec 21 15:56 sbin
drwxr-xr-x  2 root root 4096 Dec 21 15:56 sys
drwxrwxrwt  2 root root 4096 Dec 21 15:56 tmp
drwxr-xr-x  7 root root 4096 Dec 21 15:56 usr
lrwxrwxrwx  1 root root    3 Dec 21 15:56 var -> tmp
drwxr-xr-x  2 root root 4096 Dec 21 15:56 www
$ umount /mnt/boot

$ umount /mnt/root
  • TODO

  • Flash footprint of full image

    • Flash footprint of Rootfs

    • Flash foot print of kernel

    • Flash footprint of application

  • RAM footprint of full image

    • RAM footprint of Rootfs

    • RAM foot print of kernel

    • RAM footprint of application

  • In this section, we will how to flash image

Diagram
Diagram
Diagram
  • Insert fresh SD card.

  • After inserting the new SD card reader to the Linux desktop machine.

$ sudo dmesg | grep -i sdb

[ 2540.447070] sd 1:0:0:0: [sdb] 124669952 512-byte logical blocks: (63.8 GB/59.4 GiB)
[ 2540.449600] sd 1:0:0:0: [sdb] Write Protect is off
[ 2540.449611] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[ 2540.450101] sd 1:0:0:0: [sdb] No Caching mode page found
[ 2540.450106] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[ 2540.460715]  sdb:
[ 2540.460865] sd 1:0:0:0: [sdb] Attached SCSI removable disk
  • Startup fdisk in the administrative mode with the command

  • As it is fresh SD card there is no partitions

$ sudo fdisk -l

Disk /dev/sdb: 29.84 GiB, 32044482560 bytes, 62586880 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
  • Startup fdisk in the administrative mode with the command

$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
  • Within fdisk, use the “n” command to create a new partition.

  • “n” for new

Command (m for help): n
Partition type
    p   primary (0 primary, 0 extended, 4 free)
    e   extended (container for logical partitions)
  • Then we enter “p” to specify that the new partition will be a primary partition.

Select (default p): p
Partition number (1-4, default 1):
  • Next select 1 to specify the partition number.

  • The next prompt will ask for the first sector. Just press Enter to accept the default value

Partition number (1-4, default 1): 1
First sector (2048-31116287, default 2048):
  • After that it will ask for the last sector. Give the value as 128M

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-31116287, default 31116287): +128M

Created a new partition 1 of type "Linux" and of size 128 MiB.
Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
  • Now you have to type “n” to create another new partition

Command (m for help): n
Partition type
    p   primary (1 primary, 0 extended, 3 free)
    e   extended (container for logical partitions)
  • Then we enter “p” to specify that the new partition will be a primary partition.

Select (default p): p
Partition number (1-4, default 1):
  • Next select 2 to specify the partition number.

  • The next prompt will ask for the first sector. Just press Enter to accept the default value

Partition number (1-4, default 1): 2
First sector (2048-31116287, default 2048):
  • After that it will ask for the last sector. Give the value as 1G

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-31116287, default 31116287): +1G

Created a new partition 2 of type "Linux" and of size 12 GiB.

Command (m for help): p
Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
  • Enter “t” to file system type

Command (m for help): t
Partition number (1-3, default 3):
  • Next we select 1 to specify the partition number.

Partition number (1-2, default 3): 1
Hex code (type L to list all codes):
  • Enter “c” to change type of partition from Linux to FAT32

Hex code (type L to list all codes): c

Changed type of partition "Linux" to "W95 FAT32 (LBA)".

Command (m for help):
  • Now, use the p command to print the partitions to verify

Command (m for help): p
Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdb1         2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/sdb2       264192 25430015 25165824   1G 83 Linux

Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.

Command (m for help):
  • Now, use the “w”command to print the partitions to verify

  • “w” for write

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks
$ sudo dmesg | grep -i sdb

[    4.256065] sd 1:0:0:0: [sdb] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[    4.256831] sd 1:0:0:0: [sdb] Write Protect is off
[    4.256841] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[    4.257513] sd 1:0:0:0: [sdb] No Caching mode page found
[    4.257522] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[    4.266266]  sdb:
[    4.266319] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[   59.384131] sd 1:0:0:0: [sdb] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[   59.386652] sd 1:0:0:0: [sdb] Write Protect is off
[   59.386665] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[   59.387301] sd 1:0:0:0: [sdb] No Caching mode page found
[   59.387313] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[   59.406416]  sdb:
[   59.406602] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[  366.387970]  sdb: sdb1 sdb2
  • Startup fdisk in the administrative mode with the command

$ sudo fdisk -l

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdb1         2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/sdb2       264192 25430015 25165824    1G 83 Linux
  • Format boot partition

$ sudo mkfs.vfat -F 32 -n boot /dev/sdb1

  mkfs.fat 4.2 (2021-01-31)
  mkfs.fat: Warning: lowercase labels might not work properly on some systems
  • Format root partition

 $ sudo mkfs.ext4 -L root /dev/sdb2

mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 3145728 4k blocks and 786432 inodes
Filesystem UUID: 6783772d-0e9c-4402-be07-61a4cc6d1986
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
$ sudo mkdir -p /mnt/boot
$ sudo mkdir -p /mnt/root
  • Mount both partitions

$ sudo mount /dev/sdb1 /mnt/boot/
$ sudo mount /dev/sdb2 /mnt/root/
$ mount | grep -i sdb

/dev/sdb1 on /mnt/boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/sdb2 on /mnt/root type ext4 (rw,relatime)
$ umount /dev/sdb1
$ umount /dev/sdb2


$ mount | grep -i /dev/sdb1
$ mount | grep -i /dev/sdb2
$ sudo reboot
  • Insert USED SD card

  • After inserting the SD card reader to the Linux desktop machine

  • There will be sdb1 and sdb2 are present

$ sudo dmesg | grep -i sdb

[    4.256065] sd 1:0:0:0: [sdb] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[    4.256831] sd 1:0:0:0: [sdb] Write Protect is off
[    4.256841] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[    4.257513] sd 1:0:0:0: [sdb] No Caching mode page found
[    4.257522] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[    4.266266]  sdb:
[    4.266319] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[   59.384131] sd 1:0:0:0: [sdb] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[   59.386652] sd 1:0:0:0: [sdb] Write Protect is off
[   59.386665] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[   59.387301] sd 1:0:0:0: [sdb] No Caching mode page found
[   59.387313] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[   59.406416]  sdb:
[   59.406602] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[  366.387970]  sdb: sdb1 sdb2
[  922.420875] EXT4-fs (sdb2): mounted filesystem cad58498-1fe6-44e9-b6f1-8ee10854b1b9 r/w with ordered data mode. Quota mode: none.
[ 1633.623879] EXT4-fs (sdb2): unmounting filesystem cad58498-1fe6-44e9-b6f1-8ee10854b1b9.
[ 1647.742896]  sdb: sdb1 sdb2
  • Startup fdisk in the administrative mode with the command

$ sudo fdisk -l

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdb1  *      2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/sdb2       264192 25430015 25165824    1G 83 Linux
$ mount | grep -i sdb

/dev/sdb1 on /mnt/boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/sdb2 on /mnt/root type ext4 (rw,relatime)
  • Startup fdisk in the administrative mode with the command

  • “p” for print

 $ sudo fdisk /dev/sdb

 Welcome to fdisk (util-linux 2.37.2).
 Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.

 Command (m for help): p

 Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
 Disk model: USB SD Reader
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: dos
 Disk identifier: 0x5452574f

 Device     Boot  Start    End Sectors  Size Id Type
/dev/sdb1   *      8192 139263  131072   64M  c W95 FAT32 (LBA)
/dev/sdb2        147456 360447  212992  104M 83 Linux
  • Enter “d” to delete “First Partition” from the system.

  • “d” for delete

Command (m for help): d
Partition number (1,2, default 2): 1
Partition 1 has been deleted.
  • Now, use the “p” command to print the partitions to verify

Command (m for help): p
Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f

Device     Boot  Start    End Sectors  Size Id Type
/dev/sdb2       147456 360447  212992  104M 83 Linux
  • Enter “d” to delete “Second Partition” from the system.

  • “d” for delete

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
  • Now, use the “p” command to print the partitions to verify

Command (m for help): p
Disk /dev/sdb: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: USB SD Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
  • Now, use the “w” command to print the partitions to verify

  • “w” for write

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo dmesg | grep -i sdb

[    4.288903] sd 1:0:0:0: [sdb] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[    4.289723] sd 1:0:0:0: [sdb] Write Protect is off
[    4.289733] sd 1:0:0:0: [sdb] Mode Sense: 03 00 00 00
[    4.291604] sd 1:0:0:0: [sdb] No Caching mode page found
[    4.291614] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[    4.310222]  sdb:
[    4.310373] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[  340.147025]  sdb:
$ sudo mount | grep -i sdb
  • Startup fdisk in the administrative mode with the command

$ sudo fdisk -l
  • Deleted partitions on an USED SD card will make it appear as a5

  • hello

  • If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer

  • Download the Balena Etcher tool from the link https://www.balena.io/etcher/ and extract it and run the binary.

  • Extract the zip and run the binary

  • It will launch “Balena Etcher” GUI, select the image “openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz” and the SD card and click on flash button

    Diagram Diagram Diagram Diagram Diagram Diagram Diagram
$ ls -l /media/test/root

drwxr-xr-x  2 root root 4096 Dec 21 15:56 bin
drwxr-xr-x  2 root root 4096 Jan  1  1970 boot
drwxr-xr-x  2 root root 4096 Dec 21 15:56 dev
drwxr-xr-x 23 root root 4096 Dec 21 15:56 etc
drwxr-xr-x 11 root root 4096 Dec 21 15:56 lib
lrwxrwxrwx  1 root root    3 Dec 21 15:56 lib64 -> lib
drwx------  2 root root 4096 Jan  1  1970 lost+found
drwxr-xr-x  2 root root 4096 Dec 21 15:56 mnt
drwxr-xr-x  2 root root 4096 Dec 21 15:56 overlay
drwxr-xr-x  2 root root 4096 Dec 21 15:56 proc
drwxrwxr-x  2 root root 4096 Dec 21 15:56 rom
drwxr-x---  2 root root 4096 Dec 21 15:56 root
drwxr-xr-x  2 root root 4096 Dec 21 15:56 sbin
drwxr-xr-x  2 root root 4096 Dec 21 15:56 sys
drwxrwxrwt  2 root root 4096 Dec 21 15:56 tmp
drwxr-xr-x  7 root root 4096 Dec 21 15:56 usr
lrwxrwxrwx  1 root root    3 Dec 21 15:56 var -> tmp
drwxr-xr-x  2 root root 4096 Dec 21 15:56 www
$ ls -l /media/test/boot

-rw-r--r-- 1 test test 54477 Dec 21 15:56 bcm2711-rpi-400.dtb
-rw-r--r-- 1 test test 54388 Dec 21 15:56 bcm2711-rpi-4-b.dtb
-rw-r--r-- 1 test test 54997 Dec 21 15:56 bcm2711-rpi-cm4.dtb
-rw-r--r-- 1 test test 90 Dec 21 15:56 cmdline.txt
-rw-r--r-- 1 test test 581 Dec 21 15:56 config.txt
-rw-r--r-- 1 test test 496 Dec 21 15:56 COPYING.linux
-rw-r--r-- 1 test test 638 Dec 21 15:56 distroconfig.txt
-rw-r--r-- 1 test test 3171 Dec 21 15:56 fixup4cd.dat
-rw-r--r-- 1 test test 5394 Dec 21 15:56 fixup4.dat
-rw-r--r-- 1 test test 8378 Dec 21 15:56 fixup4x.dat
-rw-r--r-- 1 test test 12068872 Dec 21 15:56 kernel8.img
-rw-r--r-- 1 test test 1594 Dec 21 15:56 LICENCE.broadcom
drwxr-xr-x 2 test test 24576 Dec 21 15:56 overlays
-rw-r--r-- 1 test test 803644 Dec 21 15:56 start4cd.elf
-rw-r--r-- 1 test test 2248864 Dec 21 15:56 start4.elf
-rw-r--r-- 1 test test 2996328 Dec 21 15:56 start4x.elf
$ ls -l /media/test/boot/overlays
$ umount /dev/sdb1

$ umount /dev/sdb2
  • In this section, we will how to boot the image

  • Run minicom

$ sudo minicom -D /dev/ttyUSB0 -b 115200
  • Click ctrl+shift+A and shift+O

  • Go to Serial port setup and enter

    Diagram
  • Inside Hardware flow control default will be “Yes”

    Diagram
  • Click “F” Hardware flow control will change from “Yes” to “No”

    Diagram
  • Save the configuration

    Diagram
  • Exit the configuration

    Diagram
  • Insert the micro SD card in micro SD slot of RPI 4 model

  • Power on the RPI 4b

  • Boot logs are shown below

  • Confirm you are on linux prompt if the console display looks like below

root@OpenWrt:/#
  • In this section, we will how to do runtime image verification checks

  • In this section, we will know versions

root@OpenWrt:/# cat /etc/os-release | grep BUILD_ID

BUILD_ID="r24685-4a2ff73177"
  • Check the linux kernel version using the following command

root@OpenWrt:/# uname -a

Linux OpenWrt 6.1.69 #0 SMP Thu Dec 21 10:26:35 2023 aarch64 GNU/Linux
  • Check the openwrt version using the following command

root@OpenWrt:/# cat /etc/openwrt_release

DISTRIB_ID="OpenWrt"
DISTRIB_RELEASE="SNAPSHOT"
DISTRIB_REVISION="r24685-4a2ff73177"
DISTRIB_TARGET="bcm27xx/bcm2711"
DISTRIB_ARCH="aarch64_cortex-a72"
DISTRIB_DESCRIPTION="OpenWrt SNAPSHOT r24685-4a2ff73177"
DISTRIB_TAINTS="no-all override"
  • In this section, we will know binaries loaded

root@OpenWrt:/# lsmod
root@OpenWrt:/# find / -iname "*.ko"
root@OpenWrt:/# find / -iname "*.so"
root@OpenWrt:/# find / -iname "*.a"
root@OpenWrt:/# find /usr/bin
root@OpenWrt:/# find /usr/sbin
root@OpenWrt:/# cd bin
root@OpenWrt:/# cd sbin
  • In this section, we will know the list of threads

  • ps: Displays information about a selection of the active processes

root@OpenWrt:/# ps
  • TODO


  • TODO


  • TODO


root@OpenWrt:/# top
  • TODO


  • In this section, we will know the file systems and partitions

root@OpenWrt:/# mount
root@OpenWrt:/# fdisk -l
  • In this section, we will know RAM usage

root@OpenWrt:/# free

total        used         free      shared        buff/cache   available
Mem:        3892552       43880     3830560         140       18112     3803272
Swap:             0           0           0
  • In this section, we will know Network Interfaces

root@OpenWrt:/# ifconfig -a

br-lan    Link encap:Ethernet  HWaddr E4:5F:01:3C:F4:21
inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fddb:1aa5:ff14::1/60 Scope:Global
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr E4:5F:01:3C:F4:21
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:320 errors:0 dropped:0 overruns:0 frame:0
TX packets:320 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24960 (24.3 KiB)  TX bytes:24960 (24.3 KiB)

wlan0     Link encap:Ethernet  HWaddr E4:5F:01:3C:F4:22
BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
root@OpenWrt:/# iw dev

phy#0
      Interface wlan0
            ifindex 3
            wdev 0x1
            addr e4:5f:01:3c:f4:22
            type managed
            channel 34 (5170 MHz), width: 20 MHz, center1: 5170 MHz
root@OpenWrt:/# iwconfig

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     no wireless extensions.

br-lan    no wireless extensions.