Exemplo n.º 1
0
        public static BootloaderImage Load(string File)
        {
            FileInfo f = new FileInfo(File);
            if(f.Length < 8) throw new Exception("Wrong file.");

            StreamReader r = new StreamReader(File);
            BootloaderImage img = new BootloaderImage();

            img.Length = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            img.CRC16 = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            img.Version = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            byte brd = (byte)r.BaseStream.ReadByte();

            switch(brd)
            {
                case 0: img.Board = Boards.Mini; break;
                case 1: img.Board = Boards.Coco; break;
                case 2: img.Board = Boards.Ultra; break;
                case 3: img.Board = Boards.CocoDuino; break;
                case 4: img.Board = Boards.MiniDuino; break;
            }

            img.Revision = (byte)r.BaseStream.ReadByte();
            img.Content = new byte[img.Length - 8];

            for(int i = 7; i < img.Length; i++)
            {
                img.Content[i - 7] = (byte)r.BaseStream.ReadByte();
            }

            return img;
        }
Exemplo n.º 2
0
        public bool UpdateBootloader(string File)
        {
            Crc16Ccitt CRC = new Crc16Ccitt(InitialCrcValue.Zeros);

            FileInfo     bl   = new FileInfo(File);
            StreamReader Read = new StreamReader(File);

            if (Board == null)
            {
                LoadBoardInfo();
            }

            // load header of the bootloader file
            BootloaderImage img = BootloaderImage.Load(File);

            if (Board.Board != img.Board)
            {
                return(false);
            }
            else if (img.Revision != 0 && img.Revision != Board.BoardRevision)
            {
                return(false);
            }

            int Pages = (int)Math.Ceiling((double)bl.Length / Board.PageSize);

            for (int Page = 0; Page < Pages; Page++)
            {
                for (int Part = 0; Part < Board.PageSize / ChunkSize; Part++)
                {
                    byte[] Content = new byte[ChunkSize];

                    PacketPAGE packet = new PacketPAGE();
                    packet.Part       = (byte)Part;
                    packet.PageNumber = (byte)Page;
                    for (int i = 0; i < ChunkSize; i++)
                    {
                        if (i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize < (img.Length - 8))
                        {
                            Content[i] = img.Content[i + Part * (Board.PageSize / ChunkSize) + Page * Board.PageSize];
                        }
                        else
                        {
                            Content[i] = 0;
                        }
                    }

                    packet.CRC16   = CRC.ComputeChecksum(Content);
                    packet.Payload = Content;

                    packet.Send(Comm);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public static BootloaderImage Load(string File)
        {
            FileInfo f = new FileInfo(File);

            if (f.Length < 8)
            {
                throw new Exception("Wrong file.");
            }

            StreamReader    r   = new StreamReader(File);
            BootloaderImage img = new BootloaderImage();

            img.Length  = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            img.CRC16   = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            img.Version = (ushort)((byte)r.BaseStream.ReadByte() | ((byte)r.BaseStream.ReadByte()) << 8);
            byte brd = (byte)r.BaseStream.ReadByte();

            switch (brd)
            {
            case 0: img.Board = Boards.Mini; break;

            case 1: img.Board = Boards.Coco; break;

            case 2: img.Board = Boards.Ultra; break;

            case 3: img.Board = Boards.CocoDuino; break;

            case 4: img.Board = Boards.MiniDuino; break;
            }

            img.Revision = (byte)r.BaseStream.ReadByte();
            img.Content  = new byte[img.Length - 8];

            for (int i = 7; i < img.Length; i++)
            {
                img.Content[i - 7] = (byte)r.BaseStream.ReadByte();
            }

            return(img);
        }