Updated firmware upgrade code to be more general.