Where does the code pertaing to fastboot mode reside? Is it in the primary-bootloader (on the mb), or the secondary-bootloader(on the emmc)?

My motive behid the question is to understand what other codes are executed before system can get into fastboot mode

(Recently, I've been tinkering with a lot of different android devices and have tried to read up whatever comes up upon web-searches regarding "fastboot", "bootloaders", "primary bootloader", "secondary bootloaders". But this is one question I can't find any definitive answer about.)
Fastboot mode is in the bootloader and usually resides in a /dev/block, none of this is open sourced.