Samsung devices cannot be downgraded to a lower security binary. If your phone runs Binary 4 (U4/S4), your downloaded firmware must be Binary 4 or higher.
If you want, I can generate a concrete Makefile, flash script, or a CMake configuration for a specific MCU/board — tell me the target MCU (e.g., STM32F411, ESP32, ATmega328P) and preferred tools. efrpme easy firmware work