Writing own bootloader as a learning exercise

So as a learning experience, I’m hoping to baremetal program a custom bootloader for the STM32 on the photon. This bootloader will then either load the application stored in flash or read a new firmware OTA and then load that (maybe dependent upon a response to a query to a local server). I realize this involves using STLink, doing a flash erase, and then not really having much to do with the rest of the photon’s factory system. I still have a few questions as I’m just starting out:

  1. Is this feasible/not overly complicated? My main concern for the bootloader is getting the WiFi communication initialized without using any of the photon’s libraries (again, doing this as a learning experience and past using ST supplied HALs and such I’d like to write as much as possible myself… minus the TCP/IP stack). I was doing some looking at using WICED; would that be possible? Would I need to do too much TCP/IP stack stuff? Is it complicated to implement a custom memory map?

  2. I’d also like to better understand the photon’s boot architecture. I know it has a bootloader; I’m not sure what the “System firmware” does compared to the “User firmware” compared to the “OTA firmware.” Are the user and OTA firmware one in the same? What firmware does the bootloader load? The documentation doesn’t seem to go into that great of detail about the whole process. From looking at the source code it seems like it loads the system firmware? Then does the system firmware run whatever user/OTA firmware is present?

Thanks for any and all help!