示例#1
0
        private static retType AISObjectFileLoad( AISGen devAISGen, ObjectFile file )
        {
            UInt32 loadedSectionCount = 0;

              // Check if object file already loaded
              if (FindObjectFile(devAISGen,file.FileName) != null)
              {
            return retType.FAIL;
              }

              // If this is a new file, let's add it to our list
              devAISGen.objectFiles.Add(file);

              if (!devAISGen.devEndian.ToString().Equals(file.Endianness))
              {
            Console.WriteLine("Endianness mismatch. Device is {0} endian, Object file is {1} endian",
            devAISGen.devEndian.ToString(),
            file.Endianness);
            return retType.FAIL;
              }

              // Make sure the .TIBoot section is first (if it exists)
              ObjectSection firstSection = file.LoadableSections[0];
              for (Int32 i = 1; i < file.LoadableSectionCount; i++)
              {
            if ((file.LoadableSections[i].name).Equals(".TIBoot"))
            {
              file.LoadableSections[0] = file.LoadableSections[i];
              file.LoadableSections[i] = firstSection;
              break;
            }
              }

              // Enable CRC if needed
              devAISGen.InsertAISEnableCRC();

              // Do all SECTION_LOAD commands
              for (Int32 i = 0; i < file.LoadableSectionCount; i++)
              {
            if (AISSectionLoad(devAISGen, file, file.LoadableSections[i]) != retType.SUCCESS)
            {
              return retType.FAIL;
            }

            // Check for need to do TIBoot initialization
            if (loadedSectionCount == 0)
            {
              devAISGen.InsertAISJump("_TIBootSetup");
            }

            loadedSectionCount++;
              }
              // End of SECTION_LOAD commands

              // Now that we are done with file contents, we can close it
              file.Close();

              return retType.SUCCESS;
        }
        /// <summary>
        /// AIS COFF file Load command generation (loads all sections)
        /// </summary>
        /// <param name="cf">The COFFfile object that the section comes from.</param>
        /// <param name="devAISGen">The specific device AIS generator object.</param>
        /// <returns>retType enumerator indicating success or failure.</returns>
        private static retType AISSecureObjectFileLoad( AISGen devAISGen, ObjectFile file )
        {
            UInt32 loadedSectionCount = 0;

              // Check if object file already loaded
              if (FindObjectFile(devAISGen,file.FileName) != null)
              {
            return retType.FAIL;
              }

              // Ii this is a new file, let's add it to our list
              devAISGen.objectFiles.Add(file);

              // Make sure we have an endianness match be
              // FIXME - Is this a good idea, what about binary files?
              if (!devAISGen.devEndian.ToString().Equals(file.Endianness))
              {
            Console.WriteLine("Endianness mismatch. Device is {0} endian, Object file is {1} endian",
            devAISGen.devEndian.ToString(),
            file.Endianness);
            return retType.FAIL;
              }

              // Make sure the .TIBoot section is first (if it exists)
              ObjectSection firstSection = file.LoadableSections[0];
              for (int i = 1; i < file.LoadableSectionCount; i++)
              {
            if ((file.LoadableSections[i].name).Equals(".TIBoot"))
            {
              file.LoadableSections[0] = file.LoadableSections[i];
              file.LoadableSections[i] = firstSection;
              break;
            }
              }

              // Do all SECTION_LOAD commands
              for (Int32 i = 0; i < file.LoadableSectionCount; i++)
              {
            Boolean encryptSection = false;

            // Determine section encryption status
            if (devAISGen.sectionsToEncrypt != null)
            {
              if ( (devAISGen.sectionsToEncrypt.Length == 1) && devAISGen.sectionsToEncrypt[0].Equals("ALL"))
              {
            encryptSection = true;
            Console.WriteLine("Encrypting section {0}, since ALL was specified for encryptSections in ini file.",file.LoadableSections[i].name);
              }
              else
              {
            if ( Array.IndexOf(devAISGen.sectionsToEncrypt,file.LoadableSections[i].name) >= 0 )
            {
              encryptSection = true;
              Console.WriteLine("Encrypting section {0}, since it was explicitly specified in encryptSections in ini file.",file.LoadableSections[i].name);
            }
              }
            }

            // Perform secure section load
            if (AISSecureSectionLoad(devAISGen, file, file.LoadableSections[i], encryptSection) != retType.SUCCESS)
            {
              return retType.FAIL;
            }

            // Check for need to do TIBoot initialization
            if ( (loadedSectionCount == 0) && ((file.LoadableSections[i].name).Equals(".TIBoot")) )
            {
              devAISGen.InsertAISJump("_TIBootSetup");
              InsertAISSecureSignature(devAISGen);
            }

            loadedSectionCount++;
              }
              // End of SECTION_LOAD commands

              // Now that we are done with file contents, we can close it
              file.Close();

              return retType.SUCCESS;
        }