Search code examples
linuxlinux-kernelembedded-linuxopenwrtu-boot

How can I build u-boot and OpenWRT so that they are ready for production?


EDIT: As stated in the comments, the question seems too broad to answer, so I'll leave the explanation of the problem and the questions, because they haven't changed, but I have changed the title (it doesn't seem good yet, but it's better than before) so they are more in tune.

What lead me to the question

I want to compile OpenWRT for my board. At the moment I am compiling it to a beagle bone black, and it's quite straight forward since there are tutorials available for that, but it got me thinking. How would I build it for a completely bare board? Like it or not BBB comes with u-boot and a version of linux (Amstrong if I'm not mistaken) so when I build OpenWRT for it maybe many things have already been taken care of for me.

I know that I need to first set up the board to boot from somehere, then it must have the bootloader and finally the kernel (there is the SPL and all that, but ok, let' leave it aside for now).

Hypothetical system

Let's imagine I have a hardware similar to the beaglebone, except it has a dipswitch connected to the boot pins in order to select from where I'm going to boot my device from. Imagine I have set it to boot from ethernet, which means that on startup a bootloader located in ROM will receive a binary file and store it in flash, all that via TFTP.

The questions

  • At this point I imagine that the binary file given via TFTP is the bootloader, am I right?
  • So after that I'd need to give the bootloader the kernel?
  • Does this mean that it is a 2 step process? First load the bootloader an dthen the kernel?
  • Is it possible to compile both at the same time and load it into the microprocessor?

  • Does OpenWRT build u-boot as well or do I need to compile it separately? I know it downloads the kernel and compiles it.

  • How would I build this for production? Imagining that I have to build u-boot and openwrt separately, would I create a script that compiles both and then does the entire process of downloading it into the microprocessor?
  • Is it possible to pre-configure the kernel so that it doesn't need to be configured after the code is downloaded? I mean, for example, compile it with initialization scripts instead of connecting to the device and configuring this. Is it possible or do I have to connect to the board and configure it manually?

PS: Sorry for such basic questions, but it's my first time compiling the kernel for real, and I've only worked with microcontrollers and RTOSs at most


Solution

  • Let's try to answer the queries one by one

    At this point I imagine that the binary file given via TFTP is the bootloader, am I right?
    

    No, It should be the firmware(kernel+HLOS). TFTP is available in uboot or only after SBL(Secondary boot loader) is loaded into memory.

    So after that I'd need to give the bootloader the kernel?
    

    bootloader needs to be present in the memory and if required it can get the firmware from ethernet, This can be simply done by changing the uboot env(bootcmd), can also be configured at compile time.

    Does this mean that it is a 2 step process? First load the bootloader an dthen the kernel?
    

    Yes, bootloader needs to be loaded earlier, but if you designing a custom board, you can combine the images in a big file and then flash/load that file at once.

    Is it possible to compile both at the same time and load it into the microprocessor?
    Does OpenWRT build u-boot as well or do I need to compile it separately? I know it downloads the kernel and compiles it.
    

    Yes, Openwrt is very flexible and it compiling uboot, kernel, userspace package at once and create a desired image(based upon user configuration).

    How would I build this for production? Imagining that I have to build u-boot and openwrt separately, would I create a script that compiles both and then does the entire process of downloading it into the microprocessor?
    

    You can configure the openwrt to generate the appropriate image(based upon the flash and system requirement) and then flash that image in production(so, simple).

    Is it possible to pre-configure the kernel so that it doesn't need to be configured after the code is downloaded? I mean, for example, compile it with initialization scripts instead of connecting to the device and configuring this. Is it possible or do I have to connect to the board and configure it manually?
    

    Yes, use make kernel_menuconfig to configure the kernel parameter at compile time. Hope, I have answered all the queries!!!