//=====================================================================
//TITLE:
// 重定位编译文件
//AUTHOR:
// norains
//DATE:
// Wednesday 29-September-2010
//Environment:
// KEIL MDK 4.0
// .NET Micro Framework
//=====================================================================
如果想将.Net Micro Framework移植到新的硬件平台,免不了要对里面的文件进行一番修改。比如最初的启动文件FirstEntry.s,也许你就要在上面删删减减。那么,遇到这种情况,是不是直接在原文件中修改呢?我想,这应该是最为简单的,也最不容易出错的方法。但如果真的这么做了,那么问题就随之而来了。因为在FirstEntry.s修改的地方,是针对特定平台的,但该文件却是公共的。也就是说,你修改了之后,可能这个文件就不再适合别的Solution了。也许你会说,这没关系,别的Solution我一辈子都不会用到。就假设这说法成立吧,但如果你要将辛勤劳动的成功和别人分享,那你是不是也要求对方将这公共文件也更改呢?万一对方要使用多个Solution呢?所以,我们不应该直接在原文件上进行修正,而要另辟蹊径。
以重定位FirstEntry.s文件为例子。包含该文件的工程位于./DeviceCode/cores/dotNetMF.proj,而这个工程恰好又被NativeSample.proj所依赖。因为移植都是从NativeSample入手,所以我们就在这个文件上进行捣鼓。
首先,将原来的./DeviceCode/cores/dotNetMF.proj文件拷贝到./[SOLUTION]/DeviceCode/CORES/ARM文件夹中。在这里,[SOLUTION]指的是我们目标SOLUTION的路径。
接着,更改NativeSample.proj。之前对于./DeviceCode/cores/dotNetMF.proj的路径依赖是这么写的:
<RequiredProjects Include="$(SPOCLIENT)/DeviceCode/cores/arm/dotNetMF.proj" />
现在我们改为:
<RequiredProjects Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/cores/arm/dotNetMF.proj" />
好了,那么现在连接的就是我们的./[SOLUTION]/DeviceCode/CORES/ARM文件了。不过,如果你这时候调用MSBUILD编译的话,肯定会出错。因为原来./DeviceCode/cores/dotNetMF.proj定义的编译文件,都是用相对路径的,现在dotNetMF.proj位置移动了,强制编译肯定要出错。为了修正这个问题,需要将相对路径更改为绝对路径。当然,这绝对路径也不是定死的,因为$(SPOCLIENT)宏定义表示的是.Net Micro Framework的根目录,这对于和朋友分享Solution非常重要。另外一点需要注意的是,除了FirstEntry.s以外,别的都不用重定位,也就还是用原来的文件。
完整的修改后的./DeviceCode/cores/dotNetMF.proj文件如下:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyName>TinyHal</AssemblyName>
<ProjectGuid>{8b626ac4-c8ce-48d9-a7db-0d59f0874983}</ProjectGuid>
<Size>
</Size>
<Description>Core HAL library</Description>
<Level>HAL</Level>
<LibraryFile>TinyHal.$(LIB_EXT)</LibraryFile>
<ProjectPath>$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/cores/arm/dotNetMF.proj</ProjectPath>
<ManifestFile>TinyHal.$(LIB_EXT).manifest</ManifestFile>
<Groups>System</Groups>
<LibraryCategory>
<MFComponent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="TinyHal_HAL" Guid="{37C37BC0-3CA6-4C1C-A26F-4761A7BA3C05}" ProjectPath="" Conditional="" xmlns="">
<VersionDependency xmlns="http://schemas.microsoft.com/netmf/InventoryFormat.xsd">
<Major>4</Major>
<Minor>0</Minor>
<Revision>0</Revision>
<Build>0</Build>
<Extra />
<Date>2009-04-30</Date>
</VersionDependency>
<ComponentType xmlns="http://schemas.microsoft.com/netmf/InventoryFormat.xsd">LibraryCategory</ComponentType>
</MFComponent>
</LibraryCategory>
<Documentation>
</Documentation>
<PlatformIndependent>False</PlatformIndependent>
<CustomFilter>
</CustomFilter>
<Required>False</Required>
<IgnoreDefaultLibPath>False</IgnoreDefaultLibPath>
<IsStub>False</IsStub>
<Directory>Solutions/STM32F103ZE_RedCow/DeviceCode/cores/arm</Directory>
<PlatformIndependentBuild>false</PlatformIndependentBuild>
<Version>4.0.0.0</Version>
</PropertyGroup>
<Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Settings" />
<Import Project="$(SPOCLIENT)/Framework/Features/PreStackInit_HAL.libcatproj" />
<PropertyGroup>
<OutputType Condition="'$(PLATFORM_FAMILY)'=='arm'">Library</OutputType>
</PropertyGroup>
<ItemGroup Condition="'$(INSTRUCTION_SET)'=='arm' or '$(INSTRUCTION_SET)'=='thumb' ">
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/cpwait.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/FirstEntry.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/IDelayLoop.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/Sampling_Profiler_RAM.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/VectorsHandlers.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/arm/$(AS_SUBDIR)/VectorsTrampolines.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/Diagnostics/FIQAssembly/$(AS_SUBDIR)/FiqSubhandler_MC9328.s"/>
</ItemGroup>
<ItemGroup Condition="'$(INSTRUCTION_SET)'=='thumb2'">
<Compile Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/FirstEntry.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/IDelayLoop.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/Sampling_Profiler_RAM.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/VectorsHandlers.s" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/VectorsTrampolines.s" />
</ItemGroup>
<ItemGroup>
<HFiles Include="$(SPOCLIENT)/DeviceCode/Initialization/MasterConfig.h" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/Diagnostics/Aborts.cpp" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/Diagnostics/FIQ_Profiler.cpp" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/Diagnostics/RamTest.cpp" />
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/Diagnostics/RamTest.h" />
<LIB_FIRSTENTRY_OBJ Include="$(OBJ_DIR)/FirstEntry.$(OBJ_EXT)" />
</ItemGroup>
<ItemGroup>
<ExtraProjects Include="$(SPOCLIENT)/DeviceCode/cores/arm/dotNetMF_loader.proj" Condition="'$(PLATFORM_FAMILY)'=='arm'" />
</ItemGroup>
<Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Targets" />
</Project>
从修改后的文件看出,不用重定位的文件都以$(SPOCLIENT)/DeviceCode为路径前缀,如:
<Compile Include="$(SPOCLIENT)/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/IDelayLoop.s" />
只有需要重定位的FirstEntry.s文件的路径前缀不同,如:
<Compile Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/cores/arm/AssemblyCode/thumb2/$(AS_SUBDIR)/FirstEntry.s" />
这个语句的意思是,需要编译的FirstEntry.s文件是位于我们的./Solution/[SOLUTION]/cores/ARM目录之下的,而不是的原文件。
在这里唯一需要注意的是,STM32F103ZE_RedCow是我所建立的Solution的文件夹名,如果你的Solution和我的不同,只需要直接修改即可。