No differentiation is needed.
The bootloader ALWAYS gets control first. It waits a short time to see if any code upload is going to take place. During this time, the bootloader uses the serial interface.
Once the bootloader is done, it hands over control (meaning: jumps to) your program. Your program can now take control of the serial interface. There is no "binary sequence that will trigger the code upload functions in the arduino firmware."
Two caveats:
-
The sequence "!!!" (three exclamation marks without the double quotes and without anything intervening) in the uploaded code means something special to the bootloader, so do NOT have this sequence in your program.
-
If your code jumps to the bootloader, or if a reset occurs, the bootloader will of course get control again