Update scripts

Rework the makefiles again.

Add a script that sets all the environment variables, and adds some useful functions.

Fix a bug in flash_kernel.sh