Openwrt from a rookie perspective (2) Complete a small goal of compiling openwrt firmware

   In the last article, we got to know bootloader and openwrt and understood the relationship between them.

   In order to have a sense of accomplishment, let's compile an openwrt firmware. When you see the openwrt firmware compiled by yourself running, you will sigh "that's it", I believe your interest in openwrt will increase unabated.
   
   In order to test your firmware, you must first have a board, or a router that supports openwrt, I used the YDH-MT76X8kit evaluation board, bought from Tmall, less than 100 (there is an advertisement here, in fact, I just bought it Home, but in order to write clearly the compilation process, it is better to make it clear).
   It's worth buying a board to get a sense of accomplishment as quickly as possible, especially for work. Because merchants generally provide sdk matching the board, the possibility of successful compilation is almost 100%, and it will not hit the fragile mind of the beginner.
   
    Of course, you can also not want the real thing, just to experience the process of compiling. If the compilation is successful, you can also get a certain sense of achievement.
   
   What needs to be mentioned is:
       The compilation environment of openwrt is linux environment, so you need to know at least a few linux commands!
         If you want to do application development under openwrt, it is necessary to know a few linux commands!
       Ubuntu is the most used environment when searching for the openwrt compilation environment on the website, mainly because ubuntu is too convenient to install application software.

         The ubuntu system is used in the business documentation.
         Because I have CentOS6.8_X86 ready-made on my computer, I don't want to change the system, so I set up the environment on it with the attitude of trying it out, and it turned out to be successful.

   Please explain:
       1) The download address of the supporting SDK development kit is provided in the documentation provided by the merchant: https://github.com/ivotten/YDH.git
       2) Various packages that need to be downloaded during the compilation process are used in the compilation process. The merchant has already downloaded them for us. Contact the merchant to obtain this package.
       3) Due to network limitations, you download these packages during the compilation process. On the one hand, it affects the compilation speed; For the old bird, various methods may be used to solve the problem; while for the rookie, once the compilation fails, a compilation error may make you give up learning, and it may take a long time to get the motivation to restart. This will greatly dampen our confidence in learning openwrt, which is why we recommend buying a development board from a vendor supported by technology. Take me as an example, learning openwrt again, it has been two years since the last time I started school!

     
       4) There are three commands to get the source code from the source address of YDH and enter the ubuntu branch of the source code:
      cd dir_sdk_study dir_sdk_study is the working directory we created to compile openwrt
    git clone https://github.com/ivotten/YDH.git this The command will download the entire source code repository to dir_sdk_study, which takes a long time, just wait patiently.
      git check ubuntu This command will obtain the source code of the ubuntu branch from the source code repository, which is used to compile the openwrt firmware under the linux system


       Note that the ubuntu branch is just a name given by the merchant to the openwrt                                                                         source code branch compiled by the linux system. It is not only used under ubuntu. I compiled the source code of this branch under CentOS. machine file, very large. But every time I started running, the merchant said that my computer configuration was low and I couldn’t run it, so I decided to try it on my 64-bit CentOS6.8 first, if it didn’t work, I installed the ubuntu system, and the result was successful, so I don’t need to change the system. . Later, my colleague successfully ran the virtual machine on the i5 CPU. According to him, there is another setting in the bios, I forgot.


      Well, now I will introduce the process of my compilation:

      1) Install source code download and compilation environment

        //Download the domestic software warehouse file of CentOS, so that if you use the domestic mirror website, the installation software will be faster
    wget http://mirrors.163.com /.help/CentOS6-Base-163.repo                
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
    mv CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo

    //Update the package information in the software repository
    yum clean all //            
    yum makecache
    yum update

    //Install the software package. As a rookie, I know that git is used to download the source code. In fact, I don't know which packages are needed. Anyway, I searched the Internet and used this under CentOS. Ok
      //When I installed CentOS, I chose the "software development workstation" option, and many development-related packages should be installed, such as the following packages gcc and gcc-c++, but I will record according to the original operation, just Unchanged
    yum install binutils bzip2 gawk gcc gcc-c++ gettext makencurses-devel patch unzip wget zlib-devel git subversion screen


      2) Upgrade gcc compiler
          What to upgrade?
          The version of gcc that CentOS6.8 comes with is very low, it is version 4.4, it seems that it does not even support the compilation standard of C++11.
             I didn't upgrade the compiler at first, but later found out that the compilation failed. After upgrading to 4.8, it still didn't work. I checked the ubunbu compiler, and it was already 5:00. Well, let's escalate to 5:00.

        //The following statement adds the software repository source of the gcc compiler for CentOS, and then installs gcc 5.2 and changes the system default compiler to the newly installed compiler     
       wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum .repos.d/devtools-4.repo
       yum install devtoolset-4-gcc devtoolset-4-binutils devtoolset-4-gcc-c++ -y
       source /opt/rh/devtoolset-4/enable

         
      3) Download the source code repository and enter the source code The ubuntu branch, this has been mentioned before, and it is repeated here, rookie!
      cd dir_sdk_study dir_sdk_study is the working directory we created to compile openwrt
    git clone https://github.com/ivotten/YDH.git This command will download the entire source code repository to dir_sdk_study, which takes a long time, just wait patiently and
      git check ubuntu This command will obtain the source code of the ubuntu branch from the source code repository, which is used to compile the openwrt firmware under the linux system


      4) The openwrt source package information update, the purpose is to download the latest openwrt package update information from the openwrt official (for example, adding the xx package) for selection when configuring the openwrt component, probably this is what it means, anyway, just do it
    . /scripts/feeds update -a This will take a while, just smoke!
    ./scripts/feeds install -a
          
      5) To configure the components that openwrt needs to compile, just follow the development documentation provided by the manufacturer.
         For rookies, it must be a bit confusing, but remember, our current goals are: Compile an openwrt firmware, and don't care about the others.
         However, in order to illustrate the function of make menuconfig, let's take an example: For
              example, if I want to compile openwrt to support U disk, then I need to select the USB driver and some supporting drivers when configuring the kernel. If you do not choose, edit The stuff that comes out doesn't know your U disk         
                      . If I don't want the stuff I compiled to support sound playback, don't select the support for the sound card when I configure it.

         For my board, executing make menuconfig starts to enter the firmware configuration of openwrt. Because of the graphical configuration interface, make menuconfig will first compile a small program to realize the final configuration.

         In order to achieve the small goal of "compiling an openwrt firmware", I only made the following configuration
        1) Item 1 in the pop-up make menuconfig main menu: Select the target system type, which is the
            Ralink RT288x/RT3xxx MCU chip system
        2) Item 2 in the pop-up make menuconfig main menu: Select the type of development board
            MT7628 based boards
        3) In the third item of the pop-up make menuconfig main menu: Select the profile file that contains some default configuration items. The profile file provides us with some default configurations. Choose
            YDH iot Board

        as a rookie, in fact, we will never understand the end What is configured, why bother?
        Anyway, it is: suitable for this chip, suitable for this board, with some basic functions (such as network support)

        , when you figure it out, you have entered another level, and you don't need to read articles on this level. .
        In fact, many boards were originally prototype boards provided by chip manufacturers, or some modifications were made.
        The original source of using openwrt is also the original version provided by those openwrt fanatics, you and I are rookies, why bother?
        The meal must be eaten one bite at a time, and the road must be taken step by step.


         Interlude: As mentioned earlier, in make menuconfig, make menuconfig will first compile a small program to perform the graphical configuration function, and a compilation error will occur:
        lxdialog/checklist.o: undefined reference to symbol 'acs_map'
                indicates that the acs_map function cannot exist. After searching online, the acs_map function is in the library file libtinfo. As for why there is no such prompt under ubuntu, I don't know.
                Friends who are familiar with the C language know that this is because the corresponding library link is missing in the ld connection command, because the makefile is really a book for novices. Where should the connection parameters be added?
                The previous line of the error message:
                Entering directory `/home/MT7628/YDH/scripts/config'
                Well, I will go to the /home/MT7628/YDH/scripts/config directory to find the Makefile and try my luck.
                Search ld and find this line:
                 $(CC) -o $@ $^ $(call check_lxdialog,ldflags $(CC))
            ldflags should be the connection parameter, where is ldflags defined? Every time I find it for a long time, forget it, just add it directly to the tail.
                 $(CC) -o $@ $^ $(call check_lxdialog,ldflags $(CC)) -ltinfo Execute
                again: make menuconfig
                The configuration menu appeared successfully.

             **Later I looked at the makefile again and found this line:
        check_lxdialog = $(shell $(SHELL) $(CURDIR)/lxdialog/check-lxdialog.sh -$(1))
             Is it really the file check-lxdialog.sh inside?
             Open the file, ldflags() looks like a function, I can't understand it, maybe under ubuntu and CentOS, the execution result of this ldflags() is a bit different!

            *** Later, I execute the make_kernel_menuconfig command, and the same problem occurs again:
        scripts/kconfig/lxdialog/checklist.o: undefined reference to symbol 'acs_map' The
            solution is the same, and it is observed that
        Entering directory `/home/MT7628/YDH/ build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.29'
            open the directory, scripts/kconfig/lxdialog/Makefile, search for ld, and find a line:
        $(shell $(CONFIG_SHELL) $(check- lxdialog) -ldflags $(HOSTCC))
        Or add -ltinfo
            $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) -ltinfo
            again:
        make_kernel_menuconfig will do.
        

    6) Before compiling
             and executing the compilation, first unzip the dl.tar.gz compressed package provided by the merchant to the dl directory of the working directory, so that there is no need to download the source code of the software package online when compiling, which greatly speeds up the compilation speed
          Command make V=99

       During the compiling process, when compiling cmake-2.8.12.2, there is a prompt that a function cannot exist. The reason is that the libtinfo library file cannot be found.
              At this time, you need to find the following file in the build directory build_dir:
        build_dir/host /cmake-2.8.12.2/Source/CMakeFiles/ccmake.dir/link.txt
            Add the connection parameters to the last line of the file: -ltinfo

            and make V=99 again.


       7) Check the compilation result:
            bin sub in the working directory Under contents
            bin/ramips/openwrt-ramips-mt7628-ydh-squashfs-sysupgrade.bin is our target.
            
           If you don't have a development board, you have also completed a small target to compile the "openwrt" firmware.


       8) Upgrading the firmware on
             the development board This development board uses a bootloader called breed, which is powerful and can upgrade the firmware through a browser.
             Of course, you need to connect the PC and the board with a network cable, and set the IP address of the same network segment to
             input: http:/xxx.xxx.xxx.xxx
             According to the prompts on the web page, after upgrading the openwrt firmware
             , restart the development board, The initial IP of the development board is 192.168.1.1
             After the board is started, execute ping 192.168.1.1
             If it is successful, it proves that your firmware is running normally!  
             Now do you think it's so easy to compile an openwrt firmware, all you need is a little bit of waiting time.
             If you go to the Enshan forum again and face the introduction of various firmware, do you feel that it is not as mysterious as it used to be?

            Reminder:
             The openwrt official website provides many ready-made modules, which can be installed through the openwrt opkg package management command
                  I accidentally downloaded a USB camera driver and found that it could not be used. Later, I added USB camera support in the compilation configuration and it can be used normally.
                  I guess the compiler version is different, anyway, I can edit the firmware myself, everything is easy!




    


         






 

   

 
 

      
             


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325838063&siteId=291194637