Fix some bugs,and add auto flash firmware features