OpenWrt compilation steps and commands in detail

OpenWrt compilation steps and commands in detail

Preface

The process of compiling OpenWrt is like a repeater. In addition to selecting system components, almost every compilation is to copy and paste the same commands. And understand the role of each command and when to execute it, so that we can better solve the problems encountered in the compilation and compile the firmware more smoothly.

Compile for the first time

  • Clone the OpenWrt source code

    git clone https://github.com/coolsnowwolf/lede openwrt
    Let's take Lean's source code repository as an example. After all, many people are using it. Plus the end of the command openwrt is clone the code refers to the openwrt directory, the purpose of standardization, because sometimes not compile the source code.
  • Enter the source directory

    cd openwrt
  • Download the package source code in the feeds source

    ./scripts/feeds update -a
    Feeds are extended packages, independent of the OpenWrt source code, so they need to be pulled and updated separately.
  • Install packages in feeds

    ./scripts/feeds install -a
  • Adjust OpenWrt system components

    make menuconfig
    It is recommended to select only the architecture for the first compilation, and leave the others alone, so that the compilation success rate will be higher. If you do not intend to adjust the component, enter make defconfig it, and it will detect the compilation environment and generate a default compilation configuration file.
  • Pre-download the required packages for compilation

    make download -j8 V=s
    -j8 It means to download using 8 threads. In theory, the higher the number, the faster the download, but there seems to be an upper limit. Actually, the speed of 5 threads or more is not much different. In the case of a good network, the download can be completed within 5 minutes.
  • Check file integrity

    find dl -size -1024c -exec ls -l {} \;
    This command can list downloaded an incomplete file (based on my experience with multiple compilations drawn less than 1k file belongs to download incomplete), if there is such a file can use the find dl -size -1024c -exec rm -f {} \; command to delete them, then re-execute the make download download and double-checked, Confirming that all files are complete can greatly increase the success rate of compilation and avoid wasting time.
  • Start compiling

    make -j1 V=s
    -j1 : Use single-threaded compilation. Novices recommend single-threaded compilation, one is because metaphysics problems may have a high success rate, and the other is to check the error log easily.

     

    V=s: Output detailed logs, used to find errors when compilation fails. Moreover, the full screen code can be loaded when running, and it takes a few hours to run, and the loading is more durable.

Compile again

  • Enter the source directory (if not in this directory)

    cd openwrt

Update

TIPS: You  can ignore the update step if you recompile in the short term.
  • Update system software package

    sudo sh -c "apt update && apt upgrade -y"
    The main function is to update the compilation components installed when the compilation environment is set up
  • Pull OpenWrt source code update

    git pull
  • Update the package source code in the feeds source

    ./scripts/feeds update -a
  • Install packages in feeds

    ./scripts/feeds install -a

File cleanup

  • Clean up old compilation products (optional)

    make clean
    Execute after a large-scale update of the source code or kernel update to ensure compilation quality. This will remove /bin and /build_dir files in the directory.
  • Clear the old compilation products, cross compilation tools and tool chains and other directories (optional)

    make dirclean
    It must be executed before the replacement architecture is compiled. This will remove /bin and /build_dir (directory files make clean ) as well as /staging_dir , /toolchain , /tmp and /logs files.
  • Clear files other than OpenWrt source code (optional)

    make distclean
    Unless you are doing development and plan to push to a remote repository like GitHub, it is almost useless. This action is equivalent make dirclean plus delete /dl , /feeds directories and .config files.
  • Restore OpenWrt source code to initial state (optional)

    git clean -xdf
    Use it if the source code is broken, or if it has not been compiled for a long time.
  • Clear temporary files

    rm -rf tmp
    Delete perform make menuconfig some temporary files generated after retrieving information including a number of packages, after deletion will reload package the package directory. If it is not deleted, some newly added software packages will not be displayed.
  • Delete the compilation configuration file

    rm -f .config
    If you deselect certain components without deleting, the dependent components will not be automatically canceled, so it is recommended to delete them if you need to adjust the components.

Compile

  • Adjust OpenWrt system components

    make menuconfig
    If you do not intend to adjust the component, enter make defconfig it, and it will detect the compilation environment and automatically adjust the compilation configuration file according to the update.
  • Pre-download the required packages for compilation

    make download -j8 V=s
  • Check file integrity

    find dl -size -1024c -exec ls -l {} \;
    This command can list downloaded an incomplete file (based on my experience with multiple compilations drawn less than 1k file belongs to download incomplete), if there is such a file can use the find dl -size -1024c -exec rm -f {} \; command to delete them, then re-execute the make download download and double-checked, Confirming that all files are complete can greatly increase the success rate of compilation and avoid wasting time.
  • Start compiling

    make -j$(nproc) || make -j1 || make -j1 V=s
    After multi-threaded compilation fails, it will automatically enter single-threaded compilation. If it fails, it will output detailed logs.

Guess you like

Origin blog.csdn.net/hailangnet/article/details/114909215