Imagine a scenario: I supply you with a blank Arduino Uno, perhaps just running the blink sketch to placate you. I have oodles of resources, but excluding the incorporation of a fake ATmega328P chip.
- Can I pre-program it (bootloader?) so that it will run certain of my instructions and not all of yours when you come to load your own sketches? For example, but not restricted to, overloading calls to
The bootloader is the code run the moment the Arduino is booted, waits for activity on the Rx (a new sketch is uploaded), and upon timeout tells the MCU to execute the first instruction of the uploaded code.
Unless the sketch calls code that's in the bootloader (as in: runs instructions stored in those specific addresses in the flash memory) that code will never run again. Mind: I'm now talking about machine instructions, not the C++ code. Normally your sketch will never call the code in the bootloader's part of the flash memory, i.e. the first 2 kB or so of it. I expect that somewhere under the hood the compiler is instructed to use the address of the first byte following the bootloader as lowest byte to be used in the compiled code, as that this is also the point from where the code is actually stored on the Arduino's flash memory.
The only way I think you could modify the behaviour of a regular analogRead() call or other standard Arduino functions is by changing that in the IDE so that code is inserted at compile time.
If your pre-installed bootloader is larger than the space the compiler reserves for it, this may cause your bootloader to stop working after the first sketch upload, as part of the bootloader is overwritten. Or if your large bootloader is set to store the new upload at an address that's different from where the compiler expects the code to go, that will result in the code not working at all and showing unpredictable behaviour, probably crashing real soon.
In case I'd receive a device that I have my doubts about, it'd indeed be a simple case of plugging in an ISP programmer and programming that way. With or without bootloader. Guaranteed no more other code present; and if fuses were set to prevent that from happening I'd see error messages, reset those fuses, or everything failing just bin the part and get a new one. Arduinos are almost cheap enough to be disposable.