Introduction to Nandflash-based Bootloader Development

Source: Internet
Author: User

S3C2410 supports direct start from NAND Flash, so NAND bootloader is used.

Most NAND bootloaders are divided into nboot and eboot. Code dependent on the CPU architecture is put in nboot, which is usually implemented in assembly language + C language; while eboot is usually implemented in C language, which can implement complex functions, in addition, the Code has better readability and portability.

Nboot:
  1. Hardware Device initialization:

    • Block all interruptions. You can write the Interrupt Mask register or Status Register of the CPU (CPSR register in arm.
    • Set the CPU speed and clock rate.
    • Ram initialization. Including Correctly Setting the system's memory controller function registers and various memory library control registers.
    • Initialize the LED. Typically, gpio is used to drive LEDs. The purpose is to indicate whether the system status is correct or incorrect. You can also initialize UART to print the logo character information of NAND bootloader to the serial port to complete the test.
    • Disable CPU Internal commands/data cache.
  2. Prepare Ram space for loading the eboot of NAND bootloader;
    • To achieve better execution speed, eboot is usually loaded into the ram space for execution. Therefore, an available Ram space range must be prepared.
    • The space size is preferably a multiple of the memory page size (usually 4 kb.
    • Because the C language executes the Code, in addition to the size of the stage2 executable image, the stack space must also be taken into account (usually 1 MB) when considering the size of the space ).
    • Eboot_end = eboot_start + eboot_size
    • Make sure that the specified address range is a read/write Ram space. Therefore, you need to test the specified address range. Test method: Assume that memory page is the unit of test, and test whether the two words starting from each page can be read and written.
  3. Copy the eboot of the NAND bootloader to the ram space. When copying an image, determine the starting address and ending address of the executable image of eboot on the solid state storage device, and the starting address of the ram space.
  4. Set the stack pointer sp. Generally, the SP value is set to eboot_end-4, and the stack grows down.
  5. Jump to the C entry point of eboot. In arm, you can change the PC address to an appropriate address.

 

Eboot:
  1. Initialize the hardware device to be used in this phase: at least one serial port must be initialized for I/O output information with end users.
  2. Memory Map ):
    • Memory ing refers to the address ranges allocated in the entire 4 GB physical address space (32-bit bus) for addressing the system's Ram unit.
    • In S3C2410, The 8000,000 M address space from 0 x to 0xa000, 000 is used as the system's RAM address space.
    • However, on a specific development board, it may not necessarily implement all the RAM address spaces reserved by the CPU.
    • We can see from the above that the system memory ing is checked to know which RAM address units are truly mapped to all the RAM address spaces reserved by the CPU.
  3. Load the kernel image:
    • Plan the layout of memory usage, mainly considering the size of the base address and kernel image. In TOC, the TOC is located in the 1st block of NAND Flash. For more information about TOC, see my "table of content (TOC) Data Structure".
    • Copy the kernel image from flash. Because the storage of the kernel on NAND Flash is in the unit of Sector (512 bytes), the data read from nboot is also in the unit of sector.
    • The basic function for reading data is fmd_readsector:
      Fmd_readsector (<br/> sector_addr startsectoraddr, // start position of sector <br/> lpbyte distributed ctorbuff, // The buffer address allocated for storing data <br/> export ctorinfo into ctorinfobuff, // buffer address for storing the Sector Information <br/> DWORD dwnumsectors // number of sector s read <br/>)
    • The specific procedures for copying images are as follows:
      // <Br/> // Load the disk image directly into RAM <br/> // BUGBUG: recover from read failures <br/> // <br/> I = 0; <br/> while (dwSectorsNeeded & I <MAX_SG_SECTORS) <br/> {<br/> dwSector = toc. id [dwEntry]. sgList [I]. dwSector; <br/> dwLength = toc. id [dwEntry]. sgList [I]. dwLength; <br/> // read each sg segment <br/> while (dwLength) {</p> <p> if (! FMD_ReadSector (dwSector, <br/> (LPBYTE) dwRAM, <br/> NULL, 1) <br/>{< br/> Uart_SendString ("ERR_DISK_OP_FAIL2 :"); <br/> Uart_SendDWORD (dwSector, TRUE); </p> <p> dwSector ++; <br/> continue; </p> <p >}</p> <p> dwSector ++; <br/> dwLength --; <br/> dwRAM ++ = SECTOR_SIZE; <br/>}</p> <p> dwSectorsNeeded-= toc. id [dwEntry]. sgList [I]. dwLength; <br/> I ++; <br/>}
  4. Call the kernel. The method for Bootloader to call the system kernel is to jump to the kernel startup address, which is obtained by the eboot program based on the information provided by the kernel image during the image download process, then store it in TOC. Nboot can read this address and convert it to a physical address. When the kernel is loaded into the memory and the pointer jumps to this address, the kernel starts. Generally, the kernel loading address is not the kernel startup address, and there is an offset. This is because the system reserves a space to place system parameters (such as interrupt vectors ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.