byte[] ReadOtp()
        {
            var       devices = DfuContext.Current.GetDevices();
            DfuDevice device  = devices[0];

            var configuration = new byte[32];

            device.Download(configuration, 0x1FFF7800, 2);
            return(configuration);
        }
        // Initialize the internal structures.
        public void InitializeConfigData()
        {
            uint hal_config_block_size  = 0;
            uint hal_config_static_size = 0;
            int  index = 0;

            unsafe
            {
                hal_config_block_size  = (uint)sizeof(HAL_CONFIG_BLOCK);
                hal_config_static_size = (uint)sizeof(HAL_CONFIGURATION_SECTOR) - hal_config_block_size;
            }

            // read in the configuration data if the config sector was found
            if ((uint)configAddress != uint.MaxValue)
            {
                int hal_static_cfg_size = 0;
                unsafe
                {
                    hal_static_cfg_size = sizeof(HAL_CONFIGURATION_SECTOR);
                }

                var       devices = DfuContext.Current.GetDevices();
                DfuDevice device  = devices[0];

                m_all_cfg_data = new byte[hal_static_cfg_size];

                device.Download(m_all_cfg_data, configAddress);

                m_StaticConfig = (HAL_CONFIGURATION_SECTOR)UnmarshalData(m_all_cfg_data, typeof(HAL_CONFIGURATION_SECTOR));

                // uninitialized config sector, lets try to fix it
                if (m_StaticConfig.ConfigurationLength == 0xFFFFFFFF)
                {
                    m_StaticConfig.ConfigurationLength = (uint)hal_static_cfg_size;
                    m_StaticConfig.Version.Major       = 3;
                    m_StaticConfig.Version.Minor       = 0;
                    m_StaticConfig.Version.Extra       = 0;
                    m_StaticConfig.Version.TinyBooter  = 4;
                }

                // move to the dynamic configuration section
                index = (int)m_StaticConfig.ConfigurationLength;

                m_lastCfgIndex = index;

                while (true)
                {
                    byte[] data = new byte[hal_config_block_size];

                    // read the next configuration block
                    device.Download(data, configAddress + index);

                    HAL_CONFIG_BLOCK cfg_header = (HAL_CONFIG_BLOCK)UnmarshalData(data, typeof(HAL_CONFIG_BLOCK));

                    // out of memory or last record
                    if (cfg_header.Size > configSize)
                    {
                        // last record or bogus entry
                        m_lastCfgIndex = index;

                        // save the configuration data for later use
                        m_all_cfg_data = new byte[m_lastCfgIndex];

                        int    idx = 0;
                        byte[] tmp = null;

                        while (idx < index)
                        {
                            int size = 512;

                            if ((index - idx) < size)
                            {
                                size = index - idx;
                            }
                            tmp = new byte[size];

                            device.Download(tmp, configAddress + idx);
                            Array.Copy(tmp, 0, m_all_cfg_data, idx, tmp.Length);

                            idx += size;
                        }
                        break;                         // no more configs
                    }

                    // move to the next configuration block
                    if (cfg_header.Size + hal_config_block_size + index > configSize)
                    {
                        // end of config sector
                        break;
                    }

                    m_cfgHash[cfg_header.DriverNameString] = new ConfigIndexData(index, (int)(cfg_header.Size + hal_config_block_size));

                    index += (int)(cfg_header.Size + hal_config_block_size);

                    while (0 != (index % 4))
                    {
                        index++;
                    }
                }
            }
            m_init = true;
        }