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,
Step 1: Add custom application
Step 2 : Add application package to menuconfig
Step 3 : Update and install feeds
Step 4 : Enable application package in menuconfig
Step 6: Build application package
Step 8: How to add patch using diff command
Step 9.2: Check the “objdump” output of the application binary file
Step 9.3: Check the “readelf” output of the application binary file
Step 9.4: Check the “nm” output of the application binary file
Step 9.5: Check the “file” command output of application binary file
Step 9.6: Check the “size” command output of application binary file
Step 9.7: Check the “strings” command output of application binary file
Step 10: Build full openwrt - Incremental
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.cContent 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 MakefileContent 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) ?
See Answer
$(TOPDIR) path is /home/test/openwrt
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 ?
See Answer
SOURCE_DIR is relative or absolute path of directory
In this case path of SOURCE_DIR $HOME/openwrt/package/mypackages/examples/helloworld
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) ?
See Answer
$(INCLUDE_DIR) - It will search for included files
In this case path of $(INCLUDE_DIR) $HOME/openwrt/include
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 ?
See Answer
It includes section, category, and title
Explanation of Package Description
define Package/helloworld/description A simple "Hello, world!" -application. endef
This function defines of package.
What is Package Description Block ?
See Answer
Instructs on how and where our package will appear in the overall configuration menu
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 ?
See Answer
-r is recursive copy.
Which path $(PKG_BUILD_DIR) ?
See Answer
In this case path of $(PKG_BUILD_DIR) $HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0
What is SOURCE_DIR ?
See Answer
In this case path of SOURCE_DIR $HOME/openwrt/package/mypackages/examples/helloworld
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) ?
See Answer
It is said to arm cross compiler
In this case path of $(TARGET_CC) $HOME/openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/bin
What is $(TARGET_CFLAGS) ?
See Answer
It is used for additional flags
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) ?
See Answer
It used for creating a directory
In this case $(INSTALL_DIR) install -d -m0755
Install command is used to copy files and set attributes.
-d, –directory : It will act as directory names towards all arguments.
m, –mode=MODE : Set permission mode (as in chmod).
What is $(INSTALL_BIN) ?
See Answer
It used for copying an executable file.
In this case $(INSTALL_BIN) install -m0755
m, –mode=MODE : Set permission mode (as in chmod).
What is $(1)/usr/bin ?
See Answer
/usr/bin: It is the destination directory where the binary executable will be installed.
In this case path of $(1)/usr/bin $HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0/.pkgdir/helloworld/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
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” ?
See Answer
diff: Compare files line by line
What is a patch ?
See Answer
It is a file or set of changes made to a source code of program to modify or update it.
Used to fix bugs or add new features to existing ones.
What is use of diff command ?
See Answer
Command use to compare two files line by line.
What is the command to generate patch file ?
See Answer
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
What is use of patch command ?
See Answer
Applies changes to the source code by reading the diff file.
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 MakefileSee that binary called helloworld is present inside directory ?
See Answer
$HOME/openwrt/build_dir/target-aarch64_cortex-a72_musl/helloworld-1.0
$ ls -l
-rwxr-xr-x 1 sysadmin sysadmin 72920 Jan 10 20:34 helloworld
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 ?
See Answer
-t: Displays the symbols of application binary file
What “objdump” command does ?
See Answer
objdump: Display information from object files
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 ?
See Answer
-S : Display source code intermixed with disassembly
What is the purpose of “objdump” command ?
See Answer
The main purpose of the objdump tool is to debug and understand the executable file
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 ?
See Answer
-s: Display the symbol table
What “readelf” command does ?
See Answer
readelf: Display information about ELF files
What is the purpose of “readelf” command ?
See Answer
The main purpose of the readelf tool is to display the headers of an ELF (Executable and Linkable Format) files
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 ?
See Answer
-S: Print both value and size of defined symbols for the “bsd” output style
What “nm” command does ?
See Answer
nm is used to dump the symbol table and their attributes from a binary executable file.
What is the purpose of “nm” command ?
See Answer
The main purpose of the nm tool is to display information about symbols in the specified File, which can be an object file, an executable file, or an object-file library.
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 ?
See Answer
-s: When listing symbols from archive members, include the index: a mapping of which modules contain definitions for which names.
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 ?
See Answer
file command is used to determine the file type.
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 ?
See Answer
size command will display the output that will give you information on the size command in 5 values like data, text, dec, bss, and hex
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 ?
See Answer
strings command is used to return the string characters into files.
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 ?
See Answer
IPK file is a compressed archive format derived from the Debian package (. DEB) format
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 ?
See Answer
tar -xzf helloworld_1.0-1_aarch64_cortex-a72.ipk
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