Open-Wrt: Adding patches to an application

In this section, you are going to learn

What is patch ?

How to create patches ?

How to add patches to an application ?

How to add patches using diff command ?

Topics in this section,

In this section you will learn how to add custom application

  • Make sure the current directory “openwrt”

    $ pwd
    
      /home/test/openwrt
    
  • Make sure the current directory “openwrt”

    $ cd package
    
    $ mkdir -p mypackages/examples/helloworld
    
    $ cd mypackages/examples/helloworld/helloworld
    
  • Create helloworld.c file using vim command

    vim helloworld.c
    
  • Content of helloworld.c

    #include <stdio.h>
    
    void app_fun(void)
    {
            printf("Hi, application\n");
    }
    
    int main(void)
    {
            printf("Hello, world!\n");
            app_fun();
    
            return 0;
     }
    
  • Create Makefile file using vim command

    vim Makefile
    
  • Content of Makefile

    include $(TOPDIR)/rules.mk
    
    PKG_NAME:=helloworld
    PKG_VERSION:=1.0
    PKG_RELEASE:=1
    
    SOURCE_DIR:=$(TOPDIR)/package/mypackages/examples/helloworld
    
    include $(INCLUDE_DIR)/package.mk
    
    define Package/helloworld
    SECTION:=examples
    CATEGORY:=Examples
    TITLE:=Hello, World!
    endef
    
    define Package/helloworld/description
    A simple "Hello, world!" -application.
    endef
    
    define Build/Prepare
            mkdir -p $(PKG_BUILD_DIR)
            cp $(SOURCE_DIR)/helloworld.c $(PKG_BUILD_DIR)
            cp $(SOURCE_DIR)/Makefile $(PKG_BUILD_DIR)
            $(Build/Patch)
    endef
    
    define Build/Compile
            $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
            $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
    endef
    
    define Package/helloworld/install
            $(INSTALL_DIR) $(1)/usr/bin
            $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
    endef
    
    $(eval $(call BuildPackage,helloworld))
    
  • Explanation of include $(TOPDIR)/rules.mk

    include $(TOPDIR)/rules.mk
    
  • The $(TOPDIR) is expected to be the top-level directory of the project

  • /rules.mk - The path to the file to be included

What is $(TOPDIR) ?

  • Explanation of Package Name, Version and Release number Block

PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
  • The name and version of your package are used to define the variable to point to the build directory of your package (Ex: helloworld-1.0)

  • Explanation of SOURCE_DIR

SOURCE_DIR:=$(TOPDIR)/package/mypackages/examples/helloworld

What is SOURCE_DIR ?

  • Give path of the source directory

  • SOURCE_DIR is used in Build/Prepare

  • Explanation of include $(INCLUDE_DIR)/package.mk

include $(INCLUDE_DIR)/package.mk
  • $(INCLUDE_DIR) - Directory containing include files

  • /package.mk: The path to the file to be included

What is $(INCLUDE_DIR) ?

  • Explanation of Package Information

define Package/helloworld
SECTION:=examples
CATEGORY:=Examples
  • This block defines the package information as section, category, and title

  • SECTION: examples: This line tells the section to which the package belongs. In this case, the package will come under the “examples” section.

  • CATEGORY: Examples: This line tells the category to which the package belongs. In this case, the category is set to “Examples

  • TITLE: Hello, world This line tells, title or name of the package. In this case, the title is set to “Hello, world!”.

  • endef: This line will be the end of the define block.

What all information included in Package Information Block ?

  • Explanation of Package Description

define Package/helloworld/description
A simple "Hello, world!" -application.
endef
  • This function defines of package.

What is Package Description Block ?

  • Explanation of Build/Prepare

define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        cp $(SOURCE_DIR)/helloworld.c $(PKG_BUILD_DIR)
        cp $(SOURCE_DIR)/Makefile $(PKG_BUILD_DIR)
        $(Build/Patch)
endef
  • mkdir -p $(PKG_BUILD_DIR): This line creates the build directory

  • cp $(SOURCE_DIR)/helloworld.c $(PKG_BUILD_DIR): This line copies the contents from SOURCE_DIR (source) to PKG_BUILD_DIR (destination)

  • $(Build/Patch): This line includes a call to $(Build/Patch), which is a variable or macro typically defined elsewhere in the Makefile. It is used to apply any necessary patches to the source code.

What is -r ?

Which path $(PKG_BUILD_DIR) ?

What is SOURCE_DIR ?

  • Explanation of Build/Compile

define Build/Compile
        $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
        $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef
  • This block defines the compilation process.

  • $(TARGET_CC): It is said to arm cross compiler and it is defined globally

  • $(TARGET_CFLAGS): It is used for additional flags

  • -o $(PKG_BUILD_DIR)/helloworld.o: Takes .c input file and generates .o output file in location $(PKG_BUILD_DIR)

  • -o $(PKG_BUILD_DIR)/$1: The final helloworld binary will be placed in the build directory ($(PKG_BUILD_DIR)).

What is $(TARGET_CC) ?

What is $(TARGET_CFLAGS) ?

  • Explanation of Package Install

define Package/helloworld/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
  • $(INSTALL_DIR): It used for creating a directory and it is commonly used in build systems like OpenWrt.

  • $(INSTALL_BIN): It used for copying an executable file.

  • /usr/bin: It is the destination directory, binary file will be installed.

What is $(INSTALL_DIR) ?

What is $(INSTALL_BIN) ?

What is $(1)/usr/bin ?

  • Explanation of Package Build

$(eval $(call BuildPackage,helloworld))
  • BuildPackage: It is function call with helloworld as parameter.

In this section you will learn how to add menuconfig

  • Make sure the current directory is “openwrt”

  • Create new feeds.conf file using vim command in openwrt directory

$ vim feeds.conf
  • Inside feeds.conf

src-link <name> <path>
  • Make sure the current directory is “openwrt”

  • Create new feeds.conf file using vim command in openwrt directory

src-link mypackages /home/test/openwrt/package/mypackages

In this section you will learn how to install and update feeds

  • Installs the most recent packages, replacing any earlier versions that were already on your system

$ ./scripts/feeds update -a

$ ./scripts/feeds install -a -f

In this section you will learn how to enable in menuconfig

  • Select your category that reflects in menuconfig

  • Go inside examples and select helloworld

Diagram Diagram
Diagram
Diagram

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

  • In .config file package should be enabled in ‘y’

  • Below line should be present in .config file

    CONFIG_PACKAGE_helloworld=y
    
  • Make sure the current directory “openwrt”

    $HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl
    
    $ ls -l
    
     drwxr-xr-x 2 sysadmin sysadmin 4096 Dec 23 02:58 bin
     drwxr-xr-x 3 sysadmin sysadmin 4096 Dec 23 03:39 include
     lrwxrwxrwx 1 sysadmin sysadmin    6 Dec 23 03:39 lib -> ../lib
     lrwxrwxrwx 1 sysadmin sysadmin    8 Dec 23 03:20 lib64 -> ../lib64
     lrwxrwxrwx 1 sysadmin sysadmin   10 Dec 23 03:39 sys-include -> ../include
    
  • Make sure the current directory is ‘openwrt’

    $HOME/openwrt
    
    $ make package/helloworld/compile
    
  • Below is the path for helloworld directory is copied in “Package Build Directory ($(PKG_BUILD_DIR))”

  • Make sure the current directory is ‘openwrt’

  • Path for helloworld is called source directory/original directory

$HOME/openwrt/package/mypackages/examples/helloworld
  • Make sure the current directory is ‘openwrt’

  • $(PKG_BUILD_DIR) path is called like modified/duplicate directory

$HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0
$ ls -l

-rwxr-xr-x 1 sysadmin sysadmin 72824 Jan 10 18:20 helloworld
-rw-r--r-- 1 sysadmin sysadmin    83 Jan 10 18:20 helloworld.c
-rw-r--r-- 1 sysadmin sysadmin  1704 Jan 10 18:20 helloworld.o
drwxr-xr-x 3 sysadmin sysadmin  4096 Jan 10 18:20 ipkg-aarch64_cortex-a72
-rw-r--r-- 1 sysadmin sysadmin  1267 Jan 10 18:20 Makefile
  • In this path $HOME/openwrt/package/mypackages/examples/helloworld - helloworld directory has been copied in $(PKG_BUILD_DIR) path with helloworld-1.0

  • Steps to create patches

  • Step 7.1.1: Edit the file which needs to be modified.

  • Step 7.1.2: Generate a patch file using the diff command.

  • Syntax for diff command

diff -urNB <original_file_name> <modified_file_name> > <patch_file_name.patch>
  • -u: lines of unified context

  • r: recursively compare any subdirectories found

  • N: New file: treat absent files as empty

  • B: ignore blank lines: ignore changes where lines are all blank

What is “diff” ?

What is a patch ?

What is use of diff command ?

What is the command to generate patch file ?

What is use of patch command ?

  • Make sure the current directory is “helloworld-1.0”

  • First add changes in helloworld.c in “helloworld-1.0” directory

  • Content of helloworld.c without any changes in “helloworld-1.0” directory

    #include <stdio.h>
    
    void app_fun(void)
    {
            printf("Hi, application\n");
    }
    
    int main(void)
    {
            printf("Hello, world!\n");
            app_fun();
    
            return 0;
     }
    
  • Make sure the current directory is “helloworld-1.0”

  • Content of helloworld.c with changes in “helloworld-1.0” directory

#include <stdio.h>

void fun_hello(void)
{
        printf("Goodbye world\n");
}

void app_fun(void)
{
        printf("Hi, application\n");
}

int main(void)
{
        printf("Hello, world!\n");
        app_fun();
        fun_hello();

        return 0;
 }
  • Make sure the current directory is “helloworld-1.0”

  • Give the path of original and modified paths

    $ diff -urNB $HOME/openwrt/package/mypackages/examples/helloworld/helloworld.c /home/test/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0/helloworld.c  > add_fun_hello.patch
    
    $ ls -l
    
    -rw-rw-r-- 1 sysadmin sysadmin     0 Jan 10 18:59 add_fun_hello.patch
    -rwxr-xr-x 1 sysadmin sysadmin 72824 Jan 10 18:20 helloworld
    -rw-r--r-- 1 sysadmin sysadmin    83 Jan 10 18:20 helloworld.c
    -rw-r--r-- 1 sysadmin sysadmin  1704 Jan 10 18:20 helloworld.o
    drwxr-xr-x 3 sysadmin sysadmin  4096 Jan 10 18:20 ipkg-aarch64_cortex-a72
    
  • Content of add_fun_hello.patch

    --- /home/test/openwrt/package/mypackages/examples/helloworld/helloworld.c     2024-01-10 19:50:14.297322306 +0530
    +++ /home/test/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0/helloworld.c    2024-01-10 19:59:27.982128613 +0530
    
    #include <stdio.h>
    
    +void fun_hello(void)
    +{
    +       printf("Goodbye, world\n");
    +}
    +
    void app_fun(void)
    {
            printf("Hi, application\n");
    }
    
    int main(void)
    {
            printf("Hello, world!\n");
            app_fun();
    +       fun_hello();
    
            return 0;
    }
    
  • move path file to original directory path

    $ mv ./add_fun_hello.patch /home/test/openwrt/package/mypackages/examples/helloworld/
    
    $ ls -l
    
    -rwxr-xr-x 1 sysadmin sysadmin 72824 Jan 10 18:20 helloworld
    -rw-r--r-- 1 sysadmin sysadmin    83 Jan 10 18:20 helloworld.c
    -rw-r--r-- 1 sysadmin sysadmin  1704 Jan 10 18:20 helloworld.o
    drwxr-xr-x 3 sysadmin sysadmin  4096 Jan 10 18:20 ipkg-aarch64_cortex-a72
    
  • Path for helloworld is called original directory

    $ pwd
    
    $HOME/openwrt/package/mypackages/examples/helloworld
    
    $ ls -l
    
    -rw-rw-r-- 1 sysadmin sysadmin  529 Jan 10 19:51 add_fun_hello.patch
    -rw-rw-r-- 1 sysadmin sysadmin  177 Jan 10 19:50 helloworld.c
    -rw-rw-r-- 1 sysadmin sysadmin 1267 Jan 10 18:17 Makefile
    
  • Make sure the current directory is helloworld (original directory)

    $ pwd
    
    $HOME/openwrt/package/mypackages/examples/helloworld
    
    $ ls -l
    
    -rw-rw-r-- 1 sysadmin sysadmin  529 Jan 10 19:51 add_fun_hello.patch
    -rw-rw-r-- 1 sysadmin sysadmin  177 Jan 10 19:50 helloworld.c
    -rw-rw-r-- 1 sysadmin sysadmin 1267 Jan 10 18:17 Makefile
    
  • Make sure the current directory is helloworld (original directory)

  • Add patch command in Makefile

  • In Makefile add patch command in Build/Compile

  • Add patch command before compiling ($(TARGET_CC)) in Build/Compile

  • Makefile will compile in below path

    $ pwd
    
    $HOME/openwrt/package/mypackages/examples/helloworld
    
  • Changes should be done in $(PKG_BUILD_DIR)/helloworld.c path is called like modified/duplicate directory

    $ pwd
    
    $HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0
    
  • In Makefile change directory to $(PKG_BUILD_DIR) and then apply patch file

define Build/Compile
        cd $(PKG_BUILD_DIR); patch < add_fun_hello.patch
        $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
        $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef
  • Before compiling, patch will apply in $(PKG_BUILD_DIR)/helloworld.c and then it will compile

  • Make sure the current directory is “helloworld-1.0”

$ pwd

$HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0

$ ls -l

-rw-r--r-- 1 sysadmin sysadmin   598 Jan 10 20:34 add_fun_hello.patch
-rwxr-xr-x 1 sysadmin sysadmin 72920 Jan 10 20:34 helloworld
-rw-r--r-- 1 sysadmin sysadmin   277 Jan 10 20:40 helloworld.c
-rw-r--r-- 1 sysadmin sysadmin  2208 Jan 10 20:34 helloworld.o
drwxr-xr-x 3 sysadmin sysadmin  4096 Jan 10 20:34 ipkg-aarch64_cortex-a72
-rw-r--r-- 1 sysadmin sysadmin  1270 Jan 10 20:34 Makefile
  • Content of $(PKG_BUILD_DIR)helloworld.c

#include <stdio.h>

void fun_hello(void)
{
        printf("Goodbye world\n");
}

void app_fun(void)
{
        printf("Hi, application\n");
}

int main(void)
{
        printf("Hello, world!\n");
        app_fun();
        fun_hello();

        return 0;
 }
  • Applied patch succesfully in “$(PKG_BUILD_DIR)/helloworld.c”

In this section you will learn about post build checks

  • Make sure the current directory is ‘helloworld-1.0’

$ pwd

   $HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0

$ ls -l

  -rw-r--r-- 1 sysadmin sysadmin   598 Jan 10 20:34 add_fun_hello.patch
  -rwxr-xr-x 1 sysadmin sysadmin 72920 Jan 10 20:34 helloworld
  -rw-r--r-- 1 sysadmin sysadmin   177 Jan 10 20:45 helloworld.c
  -rw-r--r-- 1 sysadmin sysadmin  2208 Jan 10 20:34 helloworld.o
  drwxr-xr-x 3 sysadmin sysadmin  4096 Jan 10 20:34 ipkg-aarch64_cortex-a72
  -rw-r--r-- 1 sysadmin sysadmin  1270 Jan 10 20:34 Makefile

See that binary called helloworld is present inside directory ?

  • Let check objdump” output of the application binary file

  • objdump -t : Displays the symbols of application binary file

  • Check if “main” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -t helloworld | grep -i main

00000000004004f0 g     F .text     0000000000000024              main

What is “-t” option is used in “objdump” command ?

What “objdump” command does ?

  • Check if “app_fun” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -t helloworld | grep -i app_fun

00000000004005c0 g     F .text   000000000000000c              app_fun
  • Check if “fun_hello” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -t helloworld | grep -i fun_hello

00000000004005c4 g     F .text   000000000000000c              fun_hello
  • Symbols “main”, “fun_hello” and “app_fun” are present in application binary file

  • Hence we can confirm application is compiled successfully

  • objdump -S : Display source code intermixed with disassembly

  • Check if “main” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -S helloworld | grep -i main

00000000004004f0 <main>:

What is “-S” option is used in “objdump” command ?

What is the purpose of “objdump” command ?

  • Check if “app_fun” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -S helloworld | grep -i app_fun

400504: 9400002f        bl      4005c0 <app_fun>
00000000004005c0 <app_fun>:
  • Check if “fun_hello” is present or not in the “objdump”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/objdump -S helloworld | grep -i fun_hello

400508:  9400002f        bl      4005c4 <fun_hello>
00000000004005c4 <fun_hello>:
  • Symbols “main”, “fun_hello” and “app_fun” are present in application binary file

  • Hence we can confirm application is compiled successfully

  • readelf -s: Display the symbol table

  • Check if “main” is present or not in the “readelf”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/readelf -s helloworld | grep -i main

79: 00000000004004f0    36 FUNC    GLOBAL DEFAULT   12 main

What is “-s” option is used in “readelf” command ?

What “readelf” command does ?

What is the purpose of “readelf” command ?

  • Check if “app_fun” is present or not in the “readelf”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/readelf -s helloworld | grep -i app_fun

81: 00000000004005c0    12 FUNC    GLOBAL DEFAULT   12 app_fun
  • Check if “fun_hello” is present or not in the “readelf”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/readelf -s helloworld | grep -i fun_hello

81: 00000000004005c4    12 FUNC    GLOBAL DEFAULT   12 fun_hello
  • Symbols “main”, “fun_hello” and “app_fun” are present in application binary file

  • Hence we can confirm application is compiled successfully

  • nm -S: Print both value and size of defined symbols for the “bsd” output style

  • Check if “main” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -S helloworld | grep -i main

00000000004004f0 0000000000000024 T main

What is “-S” option is used in “nm” command ?

What “nm” command does ?

What is the purpose of “nm” command ?

  • Check if “app_fun” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -S helloworld | grep -i app_fun

00000000004005c0 000000000000000c T app_fun
  • Check if “fun_hello” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -S helloworld | grep -i fun_hello

00000000004005c4 000000000000000c T fun_hello
  • Symbols “main”, “fun_hello” and “app_fun” are present in application binary file

  • Hence we can confirm application is compiled successfully

  • nm -s: When listing symbols from archive members, include the index: a mapping of which modules contain definitions for which names.

  • Check if “main” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -s helloworld | grep -i main

00000000004004f0 T main

What is “-s” option is used in “nm” command ?

  • Check if “app_fun” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -s helloworld | grep -i app_fun

00000000004005c0 T app_fun
  • Check if “fun_hello” is present or not in the “nm”

$HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/aarch64-openwrt-linux-musl/bin/nm -s helloworld | grep -i fun_hello

00000000004005c4 T fun_hello
  • Symbols “main”, “fun_hello” and “app_fun” are present in application binary file

  • Hence we can confirm application is compiled successfully

  • file: Determine file type

$ file helloworld

helloworld: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-aarch64.so.1, with debug_info, not stripped

Why “file” command is used ?

  • size: List section sizes and total size of binary files

$ size helloworld

  text    data     bss     dec     hex filename
  1251     648      56    1955     7a3 helloworld

What “size” command does ?

  • strings - print the sequences of printable characters in files

  • As we can see string output are added in the program are confirmed.

$ strings helloworld | grep -i Goodbye

  Goodbye, world

What “strings” command does ?

  • Make sure the current directory “openwrt”

$HOME/openwrt/staging_dir/packages/bcm27xx
$ ls -l | grep -i "helloworld"

 lrwxrwxrwx 1 sysadmin sysadmin 126 Jan 10 20:34 helloworld_1.0-1_aarch64_cortex-a72.ipk -> /home/test/openwrt/bin/packages/aarch64_cortex-a72/mypackages/helloworld_1.0-1_aarch64_cortex-a72.ipk
  • ipk file: It is compressed archive format derived from the Debian package (. DEB) format

What is “IPK” file ?

  • Make sure the current directory “openwrt”

$HOME/openwrt/staging_dir/packages/bcm27xx
  • Command to extract .ipk file is below

$ tar -xzf helloworld_1.0-1_aarch64_cortex-a72.ipk
$ ls

  control.tar.gz
  data.tar.gz
  debian-binary

what is the command to extract IPK file ?

  • First extract control.tar.gz and data.tar.gz

  • Command to check content for control.tar.gz file is below

$ tar -xzvf control.tar.gz

./control
./postinst
./prerm
  • Check ./control using “vim command”

$ vim ./control
  • Content of ./control

Package: helloworld
Version: 1.0-1
Depends: libc
Source: package/mypackages/examples/helloworld
SourceName: helloworld
Section: examples
SourceDateEpoch: 1703276774
Architecture: aarch64_cortex-a72
Installed-Size: 1244
Description:  A simple "Hello, world!" -application.
  • Check inside for other files ./postinst and ./prerm using “vim” command

  • Command to check content for control.tar.gz file is below

$ tar -xzvf data.tar.gz

 ./usr/
 ./usr/bin/
 ./usr/bin/helloworld
  • Check ./usr/bin/helloworld is a binary file

In this section you will learn how to build full openwrt

  • Make sure the current directory “openwrt”

$HOME/openwrt
$ make -j1 V=s
  • It compile all packages

  • -j1: This option tells the build system work on one task at a time.

  • V=s: This sets the verbosity level to ‘s’, which means “silent” or “verbose.” When set to ‘s’, it makes the build system display more detailed information about what it’s doing. You’ll see the commands it’s running and the files it’s working on. This verbose output is helpful for understanding and debugging the build process.

  • Make sure the current directory “openwrt”

  • To check package is successfully compiled, below is the path

$HOME/openwrt/bin/targets/bcm27xx/bcm2711
  • To check the image file is present or not

$ ls -l

-rw-r--r-- 1 sysadmin sysadmin     1652 Jan 10 20:45 config.buildinfo
-rw-r--r-- 1 sysadmin sysadmin       71 Jan 10 20:45 feeds.buildinfo
-rw-r--r-- 1 sysadmin sysadmin 17117064 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
-rw-r--r-- 1 sysadmin sysadmin 17117911 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-ext4-sysupgrade.img.gz
-rw-r--r-- 1 sysadmin sysadmin     4207 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4.manifest
-rw-r--r-- 1 sysadmin sysadmin 15351033 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img.gz
-rw-r--r-- 1 sysadmin sysadmin 15351880 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-sysupgrade.img.gz
drwxr-xr-x 2 sysadmin sysadmin     4096 Jan 10 20:34 packages
-rw-r--r-- 1 sysadmin sysadmin     2141 Jan 10 20:35 profiles.json
-rw-r--r-- 1 sysadmin sysadmin      912 Jan 10 20:35 sha256sums
-rw-r--r-- 1 sysadmin sysadmin       18 Jan 10 20:45 version.buildinfo
  • As we can see “image” is present then it is confirmed that fully image is successfull

  • Image file is openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz

  • To extract image file command and pathis below

  • Make sure the current directory “openwrt”

$HOME/openwrt/bin/targets/bcm27xx/bcm2711
$ ls -l

-rw-r--r-- 1 sysadmin sysadmin     1652 Jan 10 20:45 config.buildinfo
-rw-r--r-- 1 sysadmin sysadmin       71 Jan 10 20:45 feeds.buildinfo
-rw-r--r-- 1 sysadmin sysadmin 17117064 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
-rw-r--r-- 1 sysadmin sysadmin 17117911 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-ext4-sysupgrade.img.gz
-rw-r--r-- 1 sysadmin sysadmin     4207 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4.manifest
-rw-r--r-- 1 sysadmin sysadmin 15351033 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img.gz
-rw-r--r-- 1 sysadmin sysadmin 15351880 Jan 10 20:34 openwrt-bcm27xx-bcm2711-rpi-4-squashfs-sysupgrade.img.gz
drwxr-xr-x 2 sysadmin sysadmin     4096 Jan 10 20:34 packages
-rw-r--r-- 1 sysadmin sysadmin     2141 Jan 10 20:35 profiles.json
-rw-r--r-- 1 sysadmin sysadmin      912 Jan 10 20:35 sha256sums
-rw-r--r-- 1 sysadmin sysadmin       18 Jan 10 20:45 version.buildinfo
  • Command to extract full image file

$ gunzip -d openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
  • Content of full image file

  • The du (disk usage) that allows users to analyze and report on disk usage within directories and files.

  • Displays sizes in human-readable format, using units such as KB, MB, GB, etc.

    $ du -h openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
    
    17M     openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
    
  • As we can see size of image file is around 17M