Capstone Step: Firmware Bring-Up
A new chip runs its first software. Do not start with the product. Start with four small programs, each one proving one more part.
You Will Be Able To
- Put bring-up programs in an order where each adds one new part of the chip.
- Name the suspect parts from the first step that fails.
- Find why an interrupt never arrives, or arrives only once, by walking its path.
- Lesson
- S6.16
- Time
- 26 min
- Runs on
- Your browser
- Check
- 6 questions
The first board of a new chip is on the bench. Someone loads the full product firmware. The console stays dark. The cause could be the clock, the processor, the memory, the UART or ten thousand lines of code.
Before You Start
You need The Boot Flow and Start-Up Code: what runs from reset, and the stack pointer.
You need The Interrupt Path, with claim and completion, and The Enable Bits. You need the machine timer of Timers and DMA.
| Question | |
|---|---|
| 1 | What is firmware bring-up, and why does it start small? |
| 2 | In which order do the four programs run, and what does each one prove? |
| 3 | Which parts are suspects when step 3 fails after steps 1 and 2 pass? |
| 4 | How do you find why an interrupt never arrives? |
| 5 | How do you find why an interrupt arrives once and never again? |
The Idea: A Ladder of Small Programs
A chip is built and verified block by block. The first time all the blocks run software together is called bring-up. It happens on the first silicon, and earlier on a simulation or an FPGA model.
The product firmware is the worst first program. It uses every part at once. When it fails, it tells you nothing about which part broke.
So bring-up starts with a program that uses almost nothing: the processor, Boot ROM and one output. Each next program adds one or two parts. Each ends with a check that reads a result.
Then a failure is small news. The steps that passed have cleared the parts they used. The suspects are the parts that the failing step added. That is the whole method of this page.
New Words
| Word | Meaning |
|---|---|
| Bring-up | The first runs of software on a new chip or a new board, to find out which parts work. |
| Bring-up program | A small program that uses a few parts of the chip and ends with a check of its result. |
| Bring-up checklist | The bring-up programs in order, each with its check. A step passes when its check holds. |
| Echo | Sending back each received byte, unchanged. |
| Polling | Reading a status bit in a loop until it changes. |
| Hang | A program that never reaches its end, so its check never runs. |
One Picture: The Checklist That Ticks
- Memory
- Processor
- Peripheral
- Clock / reset
- Bus
- Control / FSM
- Step 1 ticks: boot to hello
The processor fetches from Boot ROM and writes two bytes to UART0. "hi" appears. Reset, fetch and one device store all work.
- Step 2 ticks: a timer tick
The timer of ap_clint interrupts three times. The handler counts in SRAM. Trap entry, mret and the enable bits work.
- Step 3 ticks: UART echo by interrupt
Each received byte becomes a request of source 1. ap_plic passes it, and the handler sends the byte back. The external path works, there and back.
- Step 4 ticks: a DMA copy
The DMA copies six bytes inside SRAM, with no help from the processor. Its done request shows as a pending bit in ap_plic.
Read the diagram as text
- Boot ROM: the program, from address 0
- Processor: ap_rv32, after reset
- UART0: transmit in step 1, receive in step 3
- ap_clint timer: mtime and mtimecmp; a core-local request
- SRAM: a count, or the bytes of a copy
- ap_plic: external requests: UART0 is 1, DMA is 5
- DMA: a second manager on the bus
- Boot ROM → Processor: instructions
- Processor → UART0: bytes to send
- ap_clint timer → Processor: timer request
- Processor → SRAM: a count
- UART0 → ap_plic: source 1
- ap_plic → Processor: external request
- DMA → SRAM: copy, byte by byte
- DMA → ap_plic: source 5: done
The bring-up checklist of the lab. Each step uses parts that earlier steps proved, and adds new ones.
Read the four steps again. Steps 2 and 3 both interrupt the processor, by different roads. Step 2 uses the core-local road of ap_clint. Step 3 uses the external road through ap_plic.
The Smallest Example, Worked by Hand
List the parts of the chip, and mark what each program uses. "new" means that the program is the first to use the part.
| Part | Step 1: hello | Step 2: tick | Step 3: echo | Step 4: DMA |
|---|---|---|---|---|
| Processor and Boot ROM | new | uses | uses | uses |
| UART0 transmit | new | uses | ||
| SRAM | new | uses | uses | |
| Trap entry, mtvec and mret | new | uses | ||
| ap_clint timer and mie bit 7 | new | |||
| ap_plic and mie bit 11 | new | pending bit only | ||
| UART0 receive | new | |||
| DMA | new |
Worked out from the four programs of the lab. Step 4 reads the pending bit of the DMA in ap_plic. It takes no interrupt.
Now say steps 1 and 2 pass, and step 3 fails. Read down the column of step 3. The parts marked "uses" were cleared by steps 1 and 2. The parts marked "new" are the suspects: ap_plic, mie bit 11 and UART0 receive.
Three suspects, not eight. And each has a register you can read. That is what the order bought.
The Rules
Rule 1: Order the programs so that each adds little.
The first uses the processor, Boot ROM and one output. Each next one adds one or two parts.
Rule 2: End every program with a check that reads a result.
A text, a count in SRAM, a copied word. "It did not crash" is not a check.
Rule 3: When a step fails, suspect only what it added.
The steps that passed have cleared every part they used.
Rule 4: For a silent interrupt, walk the request path in order.
Device, then ap_plic: priority, enable, threshold. Then mip, mie and mstatus. The first stage that holds 0 is the break.
Rule 5: Check the way back as well.
One event served and the next one lost means a record was left behind, such as a missing completion.
Rule 6: Keep the programs.
Run them first on every new version of the chip, in simulation and on silicon.
Sources for These Rules
Mehta, ASIC/SoC Functional Design Verification, section 15.3.5, describes hardware bring-up. It is the first meeting of the chip with system software. The software team prepares a reduced image to test the logic and the interfaces. A fault found there is fixed in hardware or worked around in software.
The order of the steps and rules 1 to 3 and 6 are common practice. No source in our library lists them.
Rules 4 and 5 follow the interrupt path of S6.1 and the enable bits of S6.4. The addresses and source numbers are those of ap_soc.
Now Run It
The lab at the end of this page runs the four programs one after another. Each program is rows of instructions in Boot ROM. A small model of the processor runs them in front of ap_plic and the ap_clint timer, unchanged. UART0 and the DMA are test code.
step 1, boot to hello: PASS (UART0 text "hi")
step 2, a timer tick: PASS (3 ticks counted, 3 interrupts)
step 3, UART echo by interrupt: PASS (UART0 text "abc", 3 interrupts)
step 4, a DMA copy: PASS (destination 64636261 00006665)
bring-up: 4 of 4 steps passedEach program also runs alone, printing its events. The numbers after "t=" are ticks of the model: one instruction for each tick. Here is step 2.
t=208 | interrupt, machine timer: mcause=80000007 mepc=00000040, next is 00000054
t=214 | mret: back to 00000040
t=408 | interrupt, machine timer: mcause=80000007 mepc=00000044, next is 00000054
t=414 | mret: back to 00000044
t=608 | interrupt, machine timer: mcause=80000007 mepc=0000003c, next is 00000054
t=614 | mret: back to 0000003c
t=620 | the program stops at 00000050
ticks counted: 3, interrupts taken: 3The handler adds 200 to the old deadline, not to the time it runs. So the interrupts come exactly 200 ticks apart: at 208, 408 and 608. The mepc values differ, because each interrupt lands at another point of the wait loop.
Step 3, for the first byte only.
t=300 | UART0 receives 61 "a"
t=300 | interrupt, external: mcause=8000000b mepc=00000048, next is 00000060
t=300 | PLIC claim returns 1
t=302 | UART0 sends 61 "a"
t=306 | PLIC complete 1
t=307 | mret: back to 00000048Rule 5 at work: the handler claims, gets 1, sends the byte back, and completes with the same 1. Only then may source 1 ask again. Bytes b and c follow the same six rows.
t=18 | DMA starts: 6 bytes from 80000100 to 80000200
t=24 | DMA done
t=31 | the program stops at 00000064
destination: 64636261 00006665Work the copy out by hand. The source holds the bytes 61 to 68. Six of them are copied, and the destination was cleared. The first word holds 61 to 64, lowest byte first. The second holds 65 and 66, then two zeros.
The model stands in for the real processor. A probe ran the same four programs on the real five-stage ap_rv32 of this course, with ap_plic and ap_clint_timer behind its bus. Its final results were equal to the model in all four programs.
uart=hi gpio=0000 ram= stop=00000018 exceptions=0
uart= gpio=0000 ram=00000003 stop=00000050 exceptions=0
uart=abc gpio=0000 ram=00000003 stop=0000005c exceptions=0
uart= gpio=0000 ram=64636261,00006665 stop=00000064 exceptions=0These labs leave things out. There is no clock set-up, no flash and no C. A real first program also checks the clocks and the reset cause.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Four small programs | One full firmware image first | A failure names two or three parts. Four programs must be written and kept. |
| A check that a script reads | Watch the board and judge | The same check runs on every new version. Someone must write the expected result first. |
| Step 4 polls a pending bit | Step 4 takes the DMA interrupt | Step 4 then needs no handler, and fails only for the DMA. The processor waits and does nothing else. |
| Programs written in instructions | C with the full start-up code | Nothing runs that the step does not need. Bring-up moves to C once start-up code is proved. |
The Trap: Two Silent Failures
Back to the dark console. Say the clocks are fine, and step 1 now prints "hi". Two failures on interrupts are common next, and both are silent. Here is the timer program with its write to mie left out.
still running after 700 instructions, 0 exceptions and 0 interrupts
ticks counted: 0, interrupts taken: 0, mip=00000080 mie=00000000Walk the path of rule 4. mip is 00000080: bit 7, the timer request, is 1. So the timer works. mie is 0: the enable of bit 7 is missing. The program is not broken. It is waiting for an interrupt that it never allowed.
The second failure passes a quick test. Here is the echo program with the completion left out.
t=300 | UART0 receives 61 "a"
t=300 | interrupt, external: mcause=8000000b mepc=00000048, next is 00000060
t=300 | PLIC claim returns 1
t=302 | UART0 sends 61 "a"
t=306 | mret: back to 00000048
t=600 | UART0 receives 62 "b"
t=900 | UART0 receives 63 "c"
still running after 1499 instructions, 0 exceptions and 1 interrupts
UART0 text: "a", bytes counted: 1, interrupts taken: 1The first byte is echoed. Bytes b and c arrive, and no interrupt follows. The gateway of source 1 stays closed, because no completion named 1. A test that sends one byte passes. Send three, and count the interrupts.
At Scale
This section looks ahead. A product chip has hundreds of parts, so its bring-up checklist is longer. The method stays the same.
Before the silicon
The same programs run first in simulation and on an FPGA model. On first silicon they run again, unchanged.
In C
Real bring-up programs are C, built with the start-up code of S6.7 and the linker script of S6.17.
Hardware and software together
A fault found here may be fixed in the chip, or worked around in software. Mehta, section 15.3.5, describes this meeting.
The watchdog comes last
A watchdog that resets the chip during a slow step hides every other fault. The next lesson arms it as step 5.
The first tests
The bring-up programs become the first tests of every new version of the chip. A verification track grows them into register tests and interrupt test plans.
Try It
Run the lab. For each step, name the part of the chip it proves for the first time.
In program 2, the row at 02c puts 128 in x5 before the write to mie. Change 128 to 8. Predict which step fails, then run.
Put it back. In program 3, delete the completion: the store of x28 to offset 4 of x19. Compare the step 3 line with the trap on this page.
Add a fourth byte to step 3: board_sends(1200, "d"). Predict whether the step still passes, and why.
step 1, boot to hello: PASS (UART0 text "hi") step 2, a timer tick: PASS (3 ticks counted, 3 interrupts) step 3, UART echo by interrupt: PASS (UART0 text "abc", 3 interrupts) step 4, a DMA copy: PASS (destination 64636261 00006665) bring-up: 4 of 4 steps passedRead included file: ap_plic.sv
// One machine context, synchronous level sources. Register-side interface:
// commit pulses once at a successful word transfer's data edge.
module ap_plic #(parameter integer SOURCES = 16) (
input logic clk, reset_n, commit, write_en,
input logic [21:0] offset,
input logic [31:0] wdata,
input logic [SOURCES:1] level_irq,
output logic [31:0] rdata,
output logic notify_irq
);
localparam ENABLE = 'h2000, THRESHOLD = 'h200000, CLAIM = 'h200004;
logic [2:0] weight [1:SOURCES];
logic [2:0] threshold, best;
logic [SOURCES:1] pending, busy, enabled;
integer winner;
always_comb begin
best = 0;
winner = 0;
for (int id = 1; id <= SOURCES; id++) begin
if (pending[id] && enabled[id] && weight[id] > best) begin
best = weight[id];
winner = id;
end
end
notify_irq = best > threshold;
rdata = 0;
for (int id = 1; id <= SOURCES; id++) begin
if (offset == 4*id) rdata = weight[id];
if (offset == 'h1000 + 4*(id/32)) rdata[id%32] = pending[id];
if (offset == ENABLE + 4*(id/32)) rdata[id%32] = enabled[id];
end
case (offset)
THRESHOLD: rdata = threshold;
CLAIM: rdata = winner;
endcase
end
always_ff @(posedge clk) begin
if (!reset_n) begin
pending <= '0;
busy <= '0;
enabled <= '0;
threshold <= 0;
for (int id = 1; id <= SOURCES; id++) weight[id] <= 0;
end else begin
for (int id = 1; id <= SOURCES; id++) begin
if (level_irq[id] && !busy[id]) begin
pending[id] <= 1;
busy[id] <= 1;
end
if (commit && write_en && offset == 4*id) weight[id] <= wdata[2:0];
if (commit && write_en && offset == ENABLE + 4*(id/32))
enabled[id] <= wdata[id%32];
if (commit && offset == CLAIM) begin
if (!write_en && winner == id) pending[id] <= 0;
if (write_en && enabled[id] && wdata == id && busy[id] && !pending[id]) busy[id] <= 0;
end
end
if (commit && write_en && offset == THRESHOLD) threshold <= wdata[2:0];
end
end
endmodule
Read included file: ap_clint_timer.sv
// Timer slice of ap_soc's local interrupt block. One hart, one timebase tick
// per clk and a registered interrupt output. Word strobes arrive at commitment.
module ap_clint_timer #(parameter logic [63:0] RESET_COMPARE = '1) (
input logic clk, reset_n, write_cmp_low, write_cmp_high,
input logic [31:0] wdata,
output logic [63:0] mtime, mtimecmp,
output logic mtip
);
always_ff @(posedge clk) begin
if (!reset_n) begin
mtime <= 0;
mtimecmp <= RESET_COMPARE;
mtip <= 0;
end else begin
mtime <= mtime + 1'b1;
if (write_cmp_low) mtimecmp[31:0] <= wdata;
if (write_cmp_high) mtimecmp[63:32] <= wdata;
mtip <= mtime >= mtimecmp;
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Load the product firmware first.
It uses every part at once, so a failure names none of them.
Fix Run small programs in order, each adding one or two parts.
Wrong Judge a step by watching the board.
A program that hangs looks the same as one that is still working.
Fix End each program with a check that reads a result.
Wrong Test an interrupt with one event.
A missing completion lets the first event through and blocks the rest.
Fix Send several events, and compare their count with the interrupts taken.
Remember
- Bring-up is the first run of software on a new chip. It starts small.
- Each bring-up program adds one or two parts and ends with a check that reads a result.
- The first failing step names its suspects: the parts it added.
- A silent interrupt: walk the path from the device to mstatus. The first 0 is the break.
- An interrupt that arrives once: look at the way back, such as the completion.