Ejemplo n.º 1
0
        public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
        {
            bool flag = false;

            if (p_device_type == 2)
            {
                m_devicetype    = DEVICETYPE.LIN;
                m_upper_fw_addr = 0x4000;
            }
            else
            {
                m_devicetype    = DEVICETYPE.PKSA;
                m_upper_fw_addr = 0x8000;
            }
            m_array_size = m_upper_fw_addr - 0x2000;
            if (!parse_hex_file_put_in_array(p_file_name))
            {
                p_error_code = 1;
                p_error_str  = "Error - Could not read hex file - download aborted";
                return(flag);
            }
            if (!Force_PKS_Into_Prog_Mode_Cmd())
            {
                p_error_code = 2;
                p_error_str  = "Error - Could not enter programming mode prior to updating firmware - download aborted";
                return(flag);
            }
            bool flag2 = false;

            byte[] buffer = new byte[14];
            if (!Clear_BL_Flash())
            {
                flag2        = true;
                p_error_str  = "Error - clearing flash prior to writing firmware";
                p_error_code = 3;
            }
            else if (!Write_BL_Flash(ref m_flash_data_array))
            {
                p_error_str  = "Error - writing flash";
                flag2        = true;
                p_error_code = 4;
            }
            else if (!Bootloader.Write_BL_Config_Bytes(ref m_config_bytes_array, ref m_config_bool_array))
            {
                flag2        = true;
                p_error_str  = "Error - writing config bytes";
                p_error_code = 5;
            }
            else
            {
                copy_current_fw_array_into_prior_array();
                if (!Read_BL_Flash(0x2000, m_upper_fw_addr - 0x2000, ref m_flash_data_array))
                {
                    flag2        = true;
                    p_error_str  = "Error - reading flash.";
                    p_error_code = 6;
                }
                else
                {
                    for (int i = 0; i < m_array_size; i++)
                    {
                        if (m_flash_data_array[i] != m_prior_flash_data_array[i])
                        {
                            p_error_str  = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, m_flash_data_array[i], m_prior_flash_data_array[i]);
                            flag2        = true;
                            p_error_code = 8;
                            break;
                        }
                    }
                    if (Bootloader.Read_BL_Config_Data(ref buffer))
                    {
                        for (int j = 0; j < buffer.Length; j++)
                        {
                            if (m_config_bool_array[j] && (buffer[j] != m_config_bytes_array[j]))
                            {
                                p_error_str  = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, buffer[j], m_config_bytes_array[j]);
                                flag2        = true;
                                p_error_code = 9;
                                break;
                            }
                        }
                    }
                    else
                    {
                        flag2        = true;
                        p_error_str  = "Error - reading config bytes";
                        p_error_code = 7;
                    }
                }
            }
            if (!flag2)
            {
                if (m_devicetype == DEVICETYPE.LIN)
                {
                    p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
                }
                else
                {
                    p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
                }
                p_error_code = 0;
                flag         = true;
            }
            if (Bootloader.Issue_BL_Reset())
            {
                restart_the_device();
                return(flag);
            }
            p_error_code = 10;
            p_error_str  = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
            return(false);
        }
Ejemplo n.º 2
0
        public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
        {
            bool result = false;

            if (p_device_type == 2)
            {
                Firmware.m_devicetype    = Firmware.DEVICETYPE.LIN;
                Firmware.m_upper_fw_addr = 16384;
            }
            else
            {
                Firmware.m_devicetype    = Firmware.DEVICETYPE.PKSA;
                Firmware.m_upper_fw_addr = 32768;
            }
            Firmware.m_array_size = Firmware.m_upper_fw_addr - 8192;
            if (Firmware.parse_hex_file_put_in_array(p_file_name))
            {
                if (Firmware.Force_PKS_Into_Prog_Mode_Cmd())
                {
                    bool   flag  = false;
                    byte[] array = new byte[14];
                    if (Firmware.Clear_BL_Flash())
                    {
                        if (!Firmware.Write_BL_Flash(ref Firmware.m_flash_data_array))
                        {
                            p_error_str  = "Error - writing flash";
                            flag         = true;
                            p_error_code = 4;
                        }
                        else if (!Bootloader.Write_BL_Config_Bytes(ref Firmware.m_config_bytes_array, ref Firmware.m_config_bool_array))
                        {
                            flag         = true;
                            p_error_str  = "Error - writing config bytes";
                            p_error_code = 5;
                        }
                        else
                        {
                            Firmware.copy_current_fw_array_into_prior_array();
                            if (Firmware.Read_BL_Flash(8192, Firmware.m_upper_fw_addr - 8192, ref Firmware.m_flash_data_array))
                            {
                                for (int i = 0; i < Firmware.m_array_size; i++)
                                {
                                    if (Firmware.m_flash_data_array[i] != Firmware.m_prior_flash_data_array[i])
                                    {
                                        p_error_str  = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, Firmware.m_flash_data_array[i], Firmware.m_prior_flash_data_array[i]);
                                        flag         = true;
                                        p_error_code = 8;
                                        break;
                                    }
                                }
                                if (Bootloader.Read_BL_Config_Data(ref array))
                                {
                                    for (int j = 0; j < array.Length; j++)
                                    {
                                        if (Firmware.m_config_bool_array[j] && array[j] != Firmware.m_config_bytes_array[j])
                                        {
                                            p_error_str  = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, array[j], Firmware.m_config_bytes_array[j]);
                                            flag         = true;
                                            p_error_code = 9;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    flag         = true;
                                    p_error_str  = "Error - reading config bytes";
                                    p_error_code = 7;
                                }
                            }
                            else
                            {
                                flag         = true;
                                p_error_str  = "Error - reading flash.";
                                p_error_code = 6;
                            }
                        }
                    }
                    else
                    {
                        flag         = true;
                        p_error_str  = "Error - clearing flash prior to writing firmware";
                        p_error_code = 3;
                    }
                    if (!flag)
                    {
                        if (Firmware.m_devicetype == Firmware.DEVICETYPE.LIN)
                        {
                            p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
                        }
                        else
                        {
                            p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
                        }
                        p_error_code = 0;
                        result       = true;
                    }
                    if (Bootloader.Issue_BL_Reset())
                    {
                        Firmware.restart_the_device();
                    }
                    else
                    {
                        p_error_code = 10;
                        p_error_str  = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
                        result       = false;
                    }
                }
                else
                {
                    p_error_code = 2;
                    p_error_str  = "Error - Could not enter programming mode prior to updating firmware - download aborted";
                }
            }
            else
            {
                p_error_code = 1;
                p_error_str  = "Error - Could not read hex file - download aborted";
            }
            return(result);
        }