Circuit to assign hardware addresses
The simplest way to create a generic "board select" signal is to create a distributed shift register, as shown below. This is similar to what you do when you use a 74xx595 as an I/O expander, and also similar to how JTAG works.



The microcontroller can select any one (or even more than one) daughter board by shifting the appropriate pattern of ones and zeros into the flip-flops.

Each daughtercard also has an open-collector transistor that pulls down on an ACK line whenever it is selected. This allows the microcontroller to count how many daughtercards are present, by shifting a single one into the first card, and then counting how many clocks it takes for the ACK line to go high.

Note that the ACK line may not be necessary if you have some other means of determining that a board is selected, such as seeing whether it responds to a SPI bus cycle.

Note also that if you need an active-low board select signal, just use the not-Q output of the flip-flop.

This scheme does not need any sort of loopback on the last daughtercard.