Exemplo n.º 1
0
        public void upload(Firmware fw)
        {
            this.port.ReadTimeout = 1000; // 1 sec

            //Make sure we are doing the right thing
            if (self.board_type != fw.board_id)
            {
                if (!(self.board_type == 33 && fw.board_id == 9))
                {
                    throw new Exception("Firmware not suitable for this board fw:" + fw.board_id + " - board:" +
                                        self.board_type);
                }
            }

            if (self.fw_maxsize < fw.image_size && self.fw_maxsize != 0)
            {
                throw new Exception("Firmware image is too large for this board");
            }

            if (self.extf_maxsize < fw.extf_image_size && self.extf_maxsize != 0)
            {
                throw new Exception("extf image is too large for this board");
            }

            if (fw.image_size > 0)
            {
                print("erase...");
                self.__erase();

                print("program...");
                self.__program(fw);

                print("verify...");
                if (self.bl_rev == 2)
                {
                    self.__verify_v2(fw);
                }
                else
                {
                    self.__verify_v3(fw);
                }
            }
            if (fw.extf_image_size > 0)
            {
                print("erase extf...");
                self.__erase_extf(fw);
                print("program extf...");
                self.__program_extf(fw);
                print("verify extf...");
                self.__verify_extf(fw);
            }

            print("done, rebooting.");
            self.__reboot();
            try
            {
                self.port.Close();
            }
            catch { }
        }