Beispiel #1
0
        private static retType AISSectionLoad( AISGen devAISGen, ObjectFile file, ObjectSection section)
        {
            Byte[] secData = file.secRead(section);
              Byte[] srcCRCData = new Byte[section.size + 8];

              Debug.DebugMSG("AISSectionLoad for section " + section.name + " from file " + file.FileName + ".");

              // If we are doing section-by-section CRC, then zero out the CRC value
              if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC)
              {
            devAISGen.devCRC.ResetCRC();
              }

              // Add section load to the output
              devAISGen.InsertAISSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData);

              // Copy bytes to CRC byte array for future CRC calculation
              if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
              {
            if (devAISGen.devEndian != devAISGen.devAISEndian)
            {
              Endian.swapEndian(BitConverter.GetBytes(section.loadAddr)).CopyTo(srcCRCData, 0);
              Endian.swapEndian(BitConverter.GetBytes(section.size)).CopyTo(srcCRCData, 4);
            }
            else
            {
              BitConverter.GetBytes(section.loadAddr).CopyTo(srcCRCData, 0);
              BitConverter.GetBytes(section.size).CopyTo(srcCRCData, 4);
            }

              }

              // Now write contents to CRC array
              for (UInt32 k = 0; k < section.size; k+=4)
              {
            // Copy bytes to array for future CRC calculation
            if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
            {
              Byte[] temp = new Byte[4];
              Array.Copy(secData,k,temp,0,4);
              if (devAISGen.devEndian != devAISGen.devAISEndian)
              {
            Endian.swapEndian(temp).CopyTo(srcCRCData, (8 + k));
              }
              else
              {
            temp.CopyTo(srcCRCData, (8 + k));
              }
            }
              }

              // Add this section's memory range, checking for overlap
              AddMemoryRange(devAISGen, (UInt32) section.loadAddr, (UInt32) (section.loadAddr+section.size-1));

              // Perform CRC calculation of the section's contents
              if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
              {
            devAISGen.devCRC.CalculateCRC(srcCRCData);
            if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC)
            {
              // Write CRC request command, value, and jump value to temp AIS file
              devAISGen.InsertAISRequestCRC(((Int32)(-1) * (Int32)(section.size + 12 + 12)));
            }
              }

              return retType.SUCCESS;
        }
        /// <summary>
        /// AIS Section Load command generation
        /// </summary>
        /// <param name="cf">The COFFfile object that the section comes from.</param>
        /// <param name="secHeader">The Hashtable object of the section header to load.</param>
        /// <param name="devAISGen">The specific device AIS generator object.</param>
        /// <returns>retType enumerator indicating success or failure.</returns>
        private static retType AISSecureSectionLoad( AISGen devAISGen, ObjectFile file, ObjectSection section, Boolean encryptSection)
        {
            Byte[] secData = file.secRead(section);

              // Write Section_Load AIS command, load address, and size
              if (encryptSection)
              {
            Byte[] encData = null;

            // Encrypt data using CTS algorithm
            try
            {
              encData = AesManagedUtil.AesCTSEncrypt(secData,devAISGen.customerEncryptionKey,devAISGen.CEKInitialValue);
            }
            catch(Exception e)
            {
              Console.WriteLine("Exception during encryption operation: {0}",e.Message);
              return retType.FAIL;
            }

            if (encData != null)
            {
              devAISGen.InsertAISEncSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData, encData);
            }
            else
            {
              Console.WriteLine("Section encryption failed.");
              return retType.FAIL;
            }
              }
              else
              {
            devAISGen.InsertAISSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData);
              }

              // Add this section's memory range, checking for overlap
              AddMemoryRange(devAISGen, (UInt32) section.loadAddr, (UInt32) (section.loadAddr+section.size-1));

              return retType.SUCCESS;
        }