Boot loader is a [iece of software which is executed only under 2 conditions
1. Power ON
2. Hardware reset
1. As a first step, the bootloader gets programmed in the program memory. A good location for the bootloader is the end of the memory space, but a little part of it will always have to be at the first address location, as the bootloader will have to start running when the micro comes out of reset:
2. the watch dog timer is set.
2. Once the bootloader is in place, and the micro comes out of reset, The bootloader can execute the ISP command handler or the user application code.
3. the bootloader will initialise the internal peripherals of the controller, and will check if they are working properly or not.
4. then it will check the RAM and ROM memory.
5. check if the watch dog is set or underflow.
6. if it has underflown then user program is executed check if a valid user program exists.
7. if WDT is not set or underflown then it enters ISP mode and prepares controller in programming mode.
8. It runs the auto baud rate generator for downloading the hex file from system.
9. check if the auto baud rate is successful, if yes receive the hex file and store it inside, or else go and run the auto baud rate again.
10. after download is over it waits for user reset and then finds a valid user code and executes it.
then it would make the default UART into execution mode. the bootloader will start listening to one of the micro interfaces (like UART, SPI, I2C, CAN etc) for incoming bytes. Sometimes, “listening” might not be the proper way to describe this, as the bootloader might need to generate some clock pulses on the SPI clock line, or it would have to initiate the I2C protocol. If data does come through in the format expected by the bootloader, it starts writing the incoming bytes in the program memory. However, due to the fact that a few locations at the reset vector are occupied by the bootloader code itself, the data of the incoming program that would normally be written there will have to be relocated at a known address
Once the whole incoming program has been written to the flash program memory, the bootloader will execute a jump at the known address , and the program that was sent to the micro will start running. In case no data will came through the intended interface, the bootloader will wait for a while, and then execute the jump to the known address anyway, based on the supposition that the user just wants to run a program that was already burned in the program memory at a previous stage.