When a micro-controller is booting, does it fetch the instructions directly from the flash memory? But sometimes a boot-loader is used.

If so why do we use a boot-loader to dump the flash memory data into RAM?

How can I know whether the micro controller fetches the first boot instructions directly from the flash memory or through RAM?

Edit: My question is about bootloader! This is not duplicate at all.

  • \$\begingroup\$ The micro data sheet should tell you where it will first start running after a reset. You need a boot loader when you have code in a place that the micro cannot direcly execute from, for example if you have a memory card with code on it, you would need a bootloader to access the memory card and load the code into executable memory. \$\endgroup\$ Commented Feb 16, 2016 at 15:35
  • 3
    \$\begingroup\$ "microcontroller" is very non-specific. There are literally millions. Some boot from flash (execute in place), some use boot copiers (to copy from flash to RAM), some have bootloaders for programming the flash or loading a boot image. \$\endgroup\$ Commented Feb 16, 2016 at 15:35
  • \$\begingroup\$ @TomCarpenter are you saying the bootloader's job is not copying the boot instructions from flash memory to RAM? because that was what I understood from it. \$\endgroup\$
    – user16307
    Commented Feb 16, 2016 at 15:38
  • 1
    \$\begingroup\$ Possible duplicate of Is program code copied to SRAM from flash on microcontroller? \$\endgroup\$
    – Eugene Sh.
    Commented Feb 16, 2016 at 15:43
  • 1
    \$\begingroup\$ There are different terms for the same thing. Generally something which simply copies the machine code from the flash to the RAM for execution is either called a boot copier or bootloader. The latter seems more common, but maybe confusing as in a computer setting a bootloader is used to load the OS/software. People also use the term bootloader to describe a tool which allows you to program the memory (e.g. Arduino bootloader). \$\endgroup\$ Commented Feb 16, 2016 at 15:46

3 Answers 3


"Boot loader" has many different meanings.

  • In some (generally slower) microcontrollers the instruction data is stored within on-chip flash memory and executed directly from there. This obviously requires that the flash can be read as fast as the MCU executes instructions. A boot loader in these chips is a chunk of code in a reserved address range which is executed before the main program and whose purpose is to rewrite the rest of the program flash when necessary. For example, AVR-based arduinos contain a bootloader that allows the chips to reprogram themselves over the UART when uploading a "sketch".

  • In other (generally faster) microcontrollers the instruction data is still stored within the on-chip flash, but it is transfered to on-chip RAM prior to execution. This is because designing flash fast enough to run from directly would be impractical. In these cases the bootloader still refers to a piece of code for rewriting the flash, as the data transfer is done in hardware.

  • In others still there is just enough flash(or ROM/EEPROM) for storing the bootloader, whose sole purpose is to copy instructions from external memory (usually SPI/I2C flash) into RAM prior to execution.


The wikipedia page for bootloader does an okay job, is focused more on pc things, but still okay.

The loader part of the word (or standalone word if you type boot loader vs bootloader, I dont know if one is right or wrong) implies that not only does it boot the system, but it also allows for loading as in a tool for bootloader or other developers to get in and change things or do experiments before the application or operating system is started, basically interfere with the boot process if desired. Otherwise it just bootstraps the system.

Understand the bootloader itself is just a program. The processor doesnt know a bootloader from a hole in the wall, it is just machine code to run placed in the right place when the power comes on or reset is deasserted.

They can serve many purposes and the ones like uboot that prep you for linux are almost or in some cases are operating systems themselves with the massive size of the source. heavy on that loader side, allowing full tcp/ip stacks to reach across networks to pull down experimental binaries. support for various file systems, etc.

the typical use case for a microcontroller is not to use a bootloader, you boot right into the application and run it from flash. which is why the flash size to ram size ratio is so high, your program is meant to live in and run from flash. read disturb and other flash problems cannot be present in those chips for them to be successful products. for in circuit programming though the trend is to have an alternate boot method either from the chip vendor themselves or always something you can add yourself using a gpio pin. strap the pins a certain way and some other code boots, a bootloader that allows you ideally to reprogram the main application in flash, in circuit. the old days you removed the microcontroller from its DIP socket, stuck it in a programmer or eraser and ultimately reprogrammed it, or wrote your own bootloader and used a gpio pin or pressed esc or something within seconds of booting (on a uart), that kind of thing.

the bootloader is as mentioned on the wikipedia page also can be and sometimes is used to put the system in a known state for the applications that follow. not really that interesting for a microcontroller, but definitely for something bigger, initialize dram and the network interface maybe enumerate the pci bus or usb, etc. stuff that would be common to any operating system that follows so that the operating system can just run and not have to do those things.

Some microcontrollers the factory programmed bootloader (often in a flash you cannot change or requires different steps than the app flash to change) only runs with pins strapped a certain way. Other solutions the bootloader flash always runs, scans the app flash and decides if there is an application there and jumps to it and/or remaps and does a soft or not complete reset. Why on the NXP I think it is the first so many words have to have a valid checksum. Others anything non-0xFF it will try to boot.

for booting linux for example the bootloader would be the one that copies the root file system over and kernel to ram then branches to the kernel. For a microcontroller though, the bootloader really shouldnt be doing that your application should if any data has to move at all do the move. the bootstrap code before you branch to main() would copy the .data section over to ram if you have .data and zero the .bss section, set the stack pointer and branch to main.

in short in a microcontroller you dont need a bootloader, if there it is usually there for in system programming/upgrades. your application runs from flash and only variables and other read/write items live in ram.


However some microcontroller will not support flash to flash programming, in such case also you need to copy bootloader to RAM. Then the bootloader in RAM will be capable of erasing the writing the application in the flash area.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.