Sandstone Firmware Code Structure
Sandstone Firmware Code Structure
Sandstone Firmware Code Structure
ASSIGNMENT-2
SUBJECT:MICROCONTROLLERS
SUBJECT CODE:BCS402
Submitted By:
Name:Sujan Kumar K
USN:4MW22CS164
Submitted To:
Mrs.Bharthi Panjwani
Assistant Professor
This report details the Sandstone firmware code structure, focusing on the five critical steps
involved in the firmware's execution flow. Each step is accompanied by relevant code snippets
and explanations of their functions, providing a comprehensive understanding of the firmware
initialization process.
The firmware starts with a reset exception, an event triggered when the device is powered on or
reset. The reset vector, a specific memory address, directs execution to the hardware
initialization code. During this phase, all other exceptions, such as errors or interrupts, are
directed to dummy handlers that loop indefinitely. This prevents interference with the hardware
setup.
Code Explanation:
sandstone_start
B sandstone_init1 ; reset vector - jumps to hardware initialization
B ex_und ; undefined vector - loops indefinitely
B ex_swi ; software interrupt vector - loops indefinitely
B ex_pabt ; prefetch abort vector - loops indefinitely
B ex_dabt ; data abort vector - loops indefinitely
NOP ; not used...
B int_irq ; interrupt request vector - loops indefinitely
B int_fiq ; fast interrupt request vector - loops indefinitely
Result:
• Dummy handlers are set up.
• Control is passed to code to initialize the hardware.
Step 2: Hardware Initialization
The firmware then sets up the essential hardware components. This step involves configuring
system registers to prepare the hardware. For instance, on the ARM Evaluator-7T board, a
seven-segment display is configured to show firmware activity. The base address for system
registers is set to separate peripherals from memory, ensuring smooth operation.
Code Explanation:
sandstone_init1
LDR r3, =SYSCFG ; Load system configuration base address into r3
LDR r4, =0x03fffaf0 ; Load configuration value into r4
STR r4, [r3] ; Store the configuration value from r4 to the address in r3
LDR r3, =SYSCFG: Loads the system configuration base address into register r3.
LDR r4, =0x03fffaf0: Loads the configuration value into register r4.
STR r4, [r3]: Stores the configuration value from r4 into the address pointed by r3.
Result:
• The system registers are st from a known base address—0x03fff000.
• The segment display is configured.
After hardware initialization, the firmware adjusts the memory map. This step ensures that the
firmware operates from the correct memory locations. Initially, the platform starts with flash ROM
assigned in the memory map, and SRAM banks are unavailable. The code remaps the memory,
initializing SRAM and transitioning execution from flash ROM to SRAM.
Code Explanation:
Once the memory is remapped, the firmware sets up the communication hardware. This
involves configuring the serial port with specific settings, such as a 9600 baud rate, no parity,
one stop bit, and no flow control. This setup is essential for enabling data exchange between
the firmware and other systems. The firmware then outputs a standard banner message through
the serial port, indicating its status and readiness.
Result:
• Serial port initialized with the specified settings.
• Sandstone banner output through the serial port:
+ booting payload …
Finally, the bootloader executes. This step involves loading the main application or payload into
memory and transferring control to it. The firmware sets up registers for block copying the
payload, assuming it to be a plain binary image. The payload is then copied to SRAM, and
control is transferred to its entry point. This process involves looping through memory copy
instructions until the entire payload is copied. Once complete, the system is fully booted, and
the main application begins execution.
Code Explanation:
sandstone_load_and_boot
MOV r13, #0 ; Set destination address to 0 in r13
LDR r12, =payload_start_address ; Load payload start address into r12
LDR r14, =payload_end_address ; Load payload end address into r14
_copy
LDMIA r12!, {r0-r11} ; Load multiple registers from the address in r12 and increment
STMIA r13!, {r0-r11} ; Store multiple registers to the address in r13 and increment
CMP r12, r14 ; Compare r12 with the end address
BLT _copy ; If r12 is less than r14, repeat the copy process
MOV pc, #0 ; Transfer control to the address 0 (start of the payload)
Result:
• Payload copied to SRAM address 0x00000000.
• Control of the pc is relinquished to the payload; pc set to payload entry address.
• System completely booted. Output on serial port: