You should set IMG here only if it's not already set.  When it was in board_setup, it would get set before reading most of the user's config file.  Now that you're doing it after the config file is read, you need to be careful not to overwrite the users IMG setting, if any.

if [ -z "${IMG}" ]; then
    IMG=....
fi