I guess the best way woul dbe to regulate that.
If you want to sell any software (including firmware) you have to deposit the sources and encryption keys into some state-owned repository.
If you decided to stop maintaining the code it would be released into public domain after some reasonable grace period (e.g. 5 years).
That would solve many issues including excess e-waste.