Configuration, Boot Order and Partial Reconfiguration

Most fabric forgets its design when the power goes off. Who writes it back, and when, decides which half is ready first. Part of the fabric can even change while the rest runs, if it is fenced off first.

You Will Be Able To

  • Compare three boot orders of an FPGA SoC, and work out when each half is ready.
  • Explain partial reconfiguration: one region rewritten while the static logic runs.
  • Say what a decoupler must do while a region changes, and why a plain gate is not enough.
Lesson
S10.19
Time
30 min
Runs on
Your browser
Check
5 questions

A camera board swaps the image filter in its fabric while video keeps flowing. One swap in fifty, the processor freezes.

The old filter is fine, and so is the new one. What froze the processor?

Before You Start

You need FPGA SoCs: ap_fpga, the fabric, the bitstream and the fabric window.

You need The Multi-Stage Secure Boot Chain: a boot ROM, then a loader that checks the next image.

You need Power at Chip Level: clamps hold the outputs of a domain steady while it is off.

It helps to have read The Power-Up Sequence.

Five questions this page answers
Question
1Who writes the bitstream into the fabric, and which half is ready first?
2What is partial reconfiguration, and what keeps running during it?
3Why must a region be fenced off while it changes?
4Why is a plain gate on the region's wires not enough?
5With a bitstream of 100 words, what does the lab print for the hard-first order?

The Idea: An Empty Fabric, and a Region That Changes

Most fabric keeps its design in SRAM cells. When the power goes off, the design is gone. At every power-up the fabric is empty, and somebody must write the bitstream again.

That somebody sets the boot order. If the loader of the hard half writes it, the processor runs first. If a small block of its own loads it from flash, the fabric is ready first. Some fabric keeps its design without power, and is ready almost at once.

The second idea is bolder. The fabric need not change all at once. One region can be rewritten while the rest keeps running. This is partial reconfiguration. A camera board can change its filter between two frames, and never stop the video.

While a region changes, its wires carry noise. So it must be fenced off, much as clamps fence off a power domain that is off. The fence has one more job: it must not cut a request in half.

New Words

New words on this page
WordMeaning
Configuration portThe port through which a bitstream is written into the fabric. In the lab it takes one word in each tick.
Configuration blockA small fixed block that loads the bitstream from flash by itself, before any processor runs.
Kept designA fabric whose cells hold their design without power, so nothing is loaded at power-up.
Static logicThe part of the fabric that stays the same, and keeps running, while a region is rewritten.
Partial bitstreamThe bitstream of one region only.
DecouplerA block between a region and the static logic that fences the region off while it changes.
Open requestA request that has been sent and not yet answered.
DrainLetting the open requests finish before the fence closes.

One Picture: One Region, Swapped

One Region, Swapped While the Rest RunsStep through the picture. The static logic keeps working the whole time. Only the region changes, behind its fence.
  • Processor
  • Control / FSM
  • Peripheral
  • Bus
  • Memory
One Region, Swapped While the Rest RunsStep through the picture. The static logic keeps working the whole time. Only the region changes, behind its fence. component Hard half ap_soc: theprocessor and itsloader component Configurationport takes a bitstream oneword at a time component Static logic stays the same: thewindow, the video path component Decoupler the fence betweenstatic logic andregion component Region today a sharpeningfilter, soon a blur component Partial bitstream the design of theregion only requestsrequestsrequestsstream, interruptdecouplewordsnew design
  1. component Hard halfap_soc: the processor and its loader
    • requests → Static logic
    • decouple → Decoupler
  2. component Static logicstays the same: the window, the video path
    • requests → Decoupler
  3. component Decouplerthe fence between static logic and region
    • requests → Region
  4. component Regiontoday a sharpening filter, soon a blur
    • stream, interrupt → Decoupler
  5. component Partial bitstreamthe design of the region only
    • words → Configuration port
  6. component Configuration porttakes a bitstream one word at a time
    • new design → Region
  1. Running

    Requests reach the region through the decoupler. Its stream and its interrupt come back the same way.

  2. Fence first

    Software asks the decoupler to isolate the region. From now on nothing the region does reaches the static logic.

  3. Rewrite the region

    The loader writes the partial bitstream through the configuration port. Meanwhile the wires of the region are noise.

  4. The rest goes on

    The static logic never stops. Video keeps flowing past the region, and the window still answers.

  5. Open the fence

    The new design has started. Software lets go of decouple, and the region joins again.

Read the diagram as text
  • Hard half: ap_soc: the processor and its loader
  • Configuration port: takes a bitstream one word at a time
  • Static logic: stays the same: the window, the video path
  • Decoupler: the fence between static logic and region
  • Region: today a sharpening filter, soon a blur
  • Partial bitstream: the design of the region only
  • Hard half → Static logic: requests
  • Static logic → Decoupler: requests
  • Decoupler → Region: requests
  • Region → Decoupler: stream, interrupt
  • Hard half → Decoupler: decouple
  • Partial bitstream → Configuration port: words
  • Configuration port → Region: new design

A region of ap_fpga, the exercise chip of S10.14. The filter names are an example. Real tools name these parts in their own words.

The Smallest Example, Worked by Hand

No simulator yet. In ap_fpga the boot ROM runs for 5 ticks, and then the loader needs 20 to check its next image. The bitstream has 64 words, one a tick. The fabric needs 3 ticks to wake its logic. The two halves may talk once both are ready.

Three boot orders, by hand
OrderLoader doneFabric liveHalves may talk
Kept design: nothing to load5 + 20 = 25325
Fabric first: a configuration block loads it; the hard half waits in reset67 + 5 + 20 = 9264 + 3 = 6792
Hard half first: the loader writes it5 + 20 = 2525 + 64 + 3 = 9292

Two orders end at the same tick, 92, but for opposite reasons. In fabric first, the fabric works from tick 67 while the processor is still in reset. In hard half first, the processor runs from tick 25 while the fabric is still empty.

Now the swap. The region of the lab sends a stream word every 4 ticks and an interrupt every 8. While it is rewritten, for 16 ticks, its three output wires carry noise. Each one is 1 about half the time. Without a fence, about 8 false events on each wire reach the static logic.

The Rules

  1. Rule 1: Fabric in SRAM cells is empty after power-up.

    Something must write its bitstream at every power-up.

  2. Rule 2: Whoever writes the bitstream sets the boot order.

    The loader: the hard half first. A configuration block: the fabric first. A kept design: the fabric is ready almost at once.

  3. Rule 3: The halves may talk only when both are ready.

    The bridge opens at the later of the two times.

  4. Rule 4: A region can change while the static logic runs.

    Only its own partial bitstream is written. Its wires carry noise until the new design has started.

  5. Rule 5: Fence the region before the swap, and open the fence after its new design has started.

    Nothing the region does in between may reach the static logic.

  6. Rule 6: A fence must not cut an open request in half.

    Let the open request drain first. Then answer for the region, so that no request waits for ever.

Sources for These Rules

Fabric configured from SRAM loses its design without power and is loaded at power-up, from a computer or a memory chip. Some parts keep it on chip instead. Source: Harris and Harris, Digital Design and Computer Architecture, ARM edition, section 5.6.2.

Clamps at the boundary of a domain that is off: see Power at Chip Level and its sources.

Rules 2 to 6 are common practice for FPGA SoCs, stated on ap_fpga. The vendor guides to boot and to partial reconfiguration are not in our reference library. The tick counts are exercise values.

Now Run It

The lab at the end of this page has two parts. The first adds up the three boot orders. The second is a circuit: one region, swapped three times behind a plain decoupler that gates four wires.

Printed by the lab on Icarus. The swap rows come from the circuit; the boot rows are sums of ticks.
order=kept-design  loader_done=25 fabric_live=3 bridge_open=25
order=fabric-first loader_done=92 fabric_live=67 bridge_open=92
order=hard-first   loader_done=25 fabric_live=92 bridge_open=92
swap without decoupling: stray valid=8 irq=8 answers=7
swap with decoupling:    stray valid=0 irq=0 answers=0
read open when decoupling starts: answered=0 after 20 ticks

Rules 2 and 3 in the first three rows, exactly as in the hand table.

Rule 4 in the fourth row. With no fence, the static logic sees 8 false stream words and 8 false interrupts in 16 ticks. It also sees 7 answers to no request.

Rule 5 in the fifth row. The decoupler closes one tick before the swap and opens one tick after. Nothing gets through.

Rule 6 in the last row. A read of the region is open when the plain decoupler closes. The gate hides the answer, and the static side waits. After 20 ticks the lab gives up. A processor would not.

This lab leaves things out. It writes no real bitstream, and its region is a few counters. The plain decoupler has no drain and no answer of its own: building those is problem S10.19.1.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
The loader writes the bitstream (hard half first)A configuration block (fabric first)The boot chain can check the bitstream with its own keys, and software can choose it. The fabric is empty until late.
A configuration block loads the fabricThe loader does itThe fabric can work before any software, for example to sequence supplies. The processor waits in reset.
Rewrite one regionRewrite the whole fabricThe rest keeps running, and the partial bitstream is short. The region needs a fence and fixed borders.
A decoupler that drains, then answersA plain gateNo request is cut in half, and a stray access fails at once. The decoupler needs states and a status bit.

The Trap: The Read That Never Came Back

This is the camera board from the top of the page. Its driver set decouple, then wrote the new filter. The decoupler was a plain gate.

Most of the time no request was open, and the swap was clean. One time in fifty, the processor had just read a register of the filter. The gate closed between the request and the answer. The processor waited for an answer that the gate now hid.

The fix is rule 6. Let the open request finish, then close the fence. Afterwards answer any new request with an error at once. Software also needs a status bit that says the fence is really closed.

The second trap is opening the fence too early. The new design has just been written, but has not left reset. Its first output is noise, and it reaches the static logic.

The third trap is a pin. In the hard-first order, a fabric pin that switches a supply is not driven until tick 92. Decide its level with a resistor on the board.

At Scale

ap_fpga1 region, 64 words
A large FPGA SoCseveral regions, large bitstreams

This section names what real families do. The vendor guides are not in our reference library: each fact is labelled "not checked".

  1. Three boot orders in real families

    AMD Zynq parts boot the processor system first, which then loads the fabric. Intel (Altera) parts have a manager block that configures, with either half first. PolarFire SoC fabric keeps its design without power. All not checked.

  2. Names for the same idea

    AMD calls partial reconfiguration Dynamic Function eXchange, and its tools offer a decoupler block. Intel uses the name partial reconfiguration. Not checked.

  3. A bitstream is an image

    It can be encrypted and signed like any boot image, and checked by the same chain. Then an old or altered fabric design is refused too.

  4. Verifying a swap

    A bench for a swap drives noise on the wires of the region, as the lab does. It then checks that nothing reaches the static logic, and that no request hangs.

The next lesson, Two Case Studies From Public Documents, reads a real FPGA SoC and a real RISC-V chip. It maps each block to a lesson of this module.

Try It

Run the lab. Check the first three rows against the hand table.

Set BIT_WORDS to 200. Which order now opens the bridge last, and by how much?

Set SWAP_TICKS to 4, then to 40. Which counts of stray events change, and which stay at 0?

Names Printed by the Lab
NameMeaning
orderWho writes the bitstream: nobody (kept-design), a configuration block (fabric-first) or the loader (hard-first).
loader_doneThe tick at which the loader of the hard half has finished.
fabric_liveThe tick at which the fabric logic has left reset with its design.
bridge_openThe tick from which the two halves may talk: the later of the two above.
stray valid, irq, answersEvents that reached the static logic during the swap: stream words, interrupts, and answers to no request.
answeredWhether a read that was open when decoupling began ever got its answer.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: order=kept-design loader_done=25 fabric_live=3 bridge_open=25 order=fabric-first loader_done=92 fabric_live=67 bridge_open=92 order=hard-first loader_done=25 fabric_live=92 bridge_open=92 swap without decoupling: stray valid=8 irq=8 answers=7 swap with decoupling: stray valid=0 irq=0 answers=0 read open when decoupling starts: answered=0 after 20 ticks

Check Yourself

Predict the outputIn this run the bitstream has 100 words, and the run stops after the boot orders. What is the last line? Its form is: order=hard-first loader_done=.. fabric_live=... bridge_open=...
// Part 1: three boot orders of ap_fpga, as sums of ticks (test code, no circuit).
// Part 2: one region of the fabric swapped while the rest runs, behind a plain decoupler (a circuit).
// The plain decoupler only gates. It has no drain, no error answer and no status.
module plain_decoupler (input logic decouple,
                        input logic s_req, output logic r_req,          // static side asks the region
                        input logic r_ack, output logic s_ack,          // the region answers
                        input logic r_valid, r_irq, output logic s_valid, s_irq);
  assign r_req = s_req & ~decouple;
  assign s_ack = r_ack & ~decouple;
  assign s_valid = r_valid & ~decouple;
  assign s_irq = r_irq & ~decouple;
endmodule

// The region: a valid pulse every 4 ticks, an interrupt every 8, and an answer 2 ticks after a request.
// While it is being rewritten its outputs are noise.
module region (input logic clk, swapping, req, output logic ack, valid, irq);
  int t = 0, seed = 7, wait_n = 0;
  logic a, v, i;
  always @(posedge clk) begin
    t <= t + 1;
    wait_n <= req ? wait_n + 1 : 0;
  end
  always @* begin
    a = req && wait_n == 2;  v = (t % 4) == 3;  i = (t % 8) == 7;
  end
  always @(negedge clk) if (swapping) begin {ack, valid, irq} = $random(seed); end else begin ack = a; valid = v; irq = i; end
endmodule

module tb;
  // ---- Part 1: boot orders. A tick is one word through the configuration port.
  localparam int ROM_TICKS = 5;           // the boot ROM of the hard half, until the loader runs
  localparam int LOADER_TICKS = 20;       // the loader reads and checks the next image
  localparam int BIT_WORDS = 100;          // words of the fabric design (the bitstream), one a tick
  localparam int START_TICKS = 3;         // the fabric wakes its logic and leaves reset
  int live, loader_done;
  initial begin
    // The fabric keeps its design in cells that hold it without power: nothing to load.
    live = START_TICKS;  loader_done = ROM_TICKS + LOADER_TICKS;
    $display("order=kept-design  loader_done=%0d fabric_live=%0d bridge_open=%0d", loader_done, live, live > loader_done ? live : loader_done);
    // Fabric first: a configuration block loads the bitstream from flash; the hard half waits in reset.
    live = BIT_WORDS + START_TICKS;  loader_done = live + ROM_TICKS + LOADER_TICKS;
    $display("order=fabric-first loader_done=%0d fabric_live=%0d bridge_open=%0d", loader_done, live, live > loader_done ? live : loader_done);
    // Hard half first: the loader writes the bitstream into the fabric.
    loader_done = ROM_TICKS + LOADER_TICKS;  live = loader_done + BIT_WORDS + START_TICKS;
    $display("order=hard-first   loader_done=%0d fabric_live=%0d bridge_open=%0d", loader_done, live, live > loader_done ? live : loader_done);
    $finish;                              // this run stops after the boot orders
  end

  // ---- Part 2: a swap of SWAP_TICKS ticks, three times.
  localparam int SWAP_TICKS = 16;
  bit clk;  always #5 clk = ~clk;
  logic swapping = 0, decouple = 0, s_req = 0;
  wire r_req, r_ack, r_valid, r_irq, s_ack, s_valid, s_irq;
  region u_region (.clk(clk), .swapping(swapping), .req(r_req), .ack(r_ack), .valid(r_valid), .irq(r_irq));
  plain_decoupler u_dec (.decouple(decouple), .s_req(s_req), .r_req(r_req), .r_ack(r_ack), .s_ack(s_ack),
                         .r_valid(r_valid), .r_irq(r_irq), .s_valid(s_valid), .s_irq(s_irq));
  int stray_valid, stray_irq, stray_ack, open_ticks;
  task automatic swap(input bit guard);
    stray_valid = 0;  stray_irq = 0;  stray_ack = 0;
    @(posedge clk);  decouple = guard;
    @(posedge clk);  swapping = 1;
    repeat (SWAP_TICKS) begin @(posedge clk); #1; stray_valid += s_valid; stray_irq += s_irq; stray_ack += (s_ack && !s_req); end
    swapping = 0;
    @(posedge clk);  decouple = 0;
  endtask
  initial begin
    #1000;
    swap(0);  $display("swap without decoupling: stray valid=%0d irq=%0d answers=%0d", stray_valid, stray_irq, stray_ack);
    swap(1);  $display("swap with decoupling:    stray valid=%0d irq=%0d answers=%0d", stray_valid, stray_irq, stray_ack);
    // A read of the region is open when the decoupler closes. Give up after 20 ticks.
    @(posedge clk);  s_req = 1;  open_ticks = 0;
    @(posedge clk);  decouple = 1;  #1;
    while (!s_ack && open_ticks < 20) begin @(posedge clk); #1; open_ticks++; end
    $display("read open when decoupling starts: answered=%0d after %0d ticks", s_ack, open_ticks);
    $finish;
  end
endmodule
ConceptWhich boot order lets the fabric work before any software runs?
ConceptWhat keeps running while a region is rewritten?
ConceptWhy does a plain gate freeze the processor in the trap?
ConceptWhy open the fence only after the new design has started?

Common Mistakes

Wrong Expect the fabric to hold its design after power-up.

Fabric in SRAM cells is empty at every power-up.

Fix Decide who writes the bitstream, and when.

Wrong Gate the region's wires the moment software asks.

An open request is cut in half, and its owner waits for ever.

Fix Drain the open request, then isolate and answer for the region.

Wrong Open the fence as soon as the bitstream is written.

The new design has not left reset, and its first outputs are noise.

Fix Open the fence after the new design has started.

Remember

  • Fabric in SRAM cells is empty at power-up; whoever writes the bitstream sets the boot order.
  • The halves may talk only when both are ready.
  • Partial reconfiguration rewrites one region while the static logic runs.
  • Fence the region during the swap, and drain any open request before the fence closes.

Practice

Report a problem with this page