依据Starboard现实对Cobalt的移植

参考网站:https://cobalt.foo/starboard/porting.html#prerequisites

名词解释
Starboard:Cobalt定义的porting层和OS抽象层。这里仅包括移植平台的特性部分。

本文意在指导cobalt的移植,即能匹配移植平台的特性,又不影响cobalt后续升级改变。

正文
1. Enumerate and name your platform configurations
给要移植的平台取个名字,后面的配置项都需要用这个来命令。推荐格式

<family-name>-<binary-variant>

例如一家叫优必选的公司,UBT,要移植到mips的芯片上,
如果是大端则可以叫 ubt-mipseb, 如果是小端则可以叫 ubt-mipsel。
当然如果有必要可以继续扩展下去,比如小端模式,绘图工具选择DirectFB,则可以叫ubt-mipsel-dfb, 如果选择OpenGL ES,则可以叫 ubt-mipsel-gles

2. Add Source Tree Directories for your Starboard Port
取好名字之后,就需要在source code中新建对应的文件夹

src/third_party/starboard/<family-name>/
src/third_party/starboard/<family-name>/shared/

一个公司下的所有芯片都放到family-name这个文件下,其中有可以重复使用的文件放到shared目录下,特性文件放到binary-variant文件夹下。

src/third_party/starboard/<family-name>/<binary-variant>/

继续沿用上文说到的例子,则建立如下文件夹

  src/third_party/starboard/ubt/shared/
  src/third_party/starboard/ubt/mipseb/
  src/third_party/starboard/ubt/mipsel/
  src/third_party/starboard/ubt/mipsel/dfb/
  src/third_party/starboard/ubt/mipsel/gles/

3. Add required binary-variant files
在第2步创建出来的每一个特性文件夹中,都需要包含以下文件。

  • atomic_public.h
  • configuration_public.h
  • gyp_configuration.gypi
  • gyp_configuration.py
  • starboard_platform.gyp
  • thread_types_public.h

推荐从 src/third_party/stub/ 复制一份到新建的特性 binary-variant 目录下,这里都是干净的接口,可以依据移植平台的特性,自己写对应的实现。

cp -R src/starboard/stub
      src/third_party/starboard/<family-name>/<binary-variant>

复制了这些文件之后,即使代码里面没有实现,但应该就可以编译通过了。

还有另一种方式,就是将 the Desktop Linux or Raspberry Pi ports 整个复制过来,然后在去掉移植平台上不需要的部分。

3a. Additional files in the stub implementation
还有一个文件,虽然不是移植必需要依赖的,但是如果要新增接口的话,就需要用到它们。

  • application_stub.c
  • application_stub.h
  • main.cc

设计一个标准的类,需要遵循以下原则。

  • Integrate a generic message loop function with a system message pump that can deliver either input or application lifecycle events like suspend/resume.
  • Provide a place for graceful platform-specific initialization and teardown.
  • Provide a universally accessible place
    to store global platform-specific state, such as managed UI windows.

因此这些文件提供了一个标准框架,来实现标准事件的发送,接收流程。虽然这些文件里面没有真正的实现,也不是移植必需的,但是一般移植的时候都需要复制application_stub.cc,application_stub.h 过来,在实现一些新增的接口。

4. Make required file modifications
要移植代码,必须对在步骤3中复制的文件进行以下修改:

  • atomic_public.h - 确保此文件指向适当的共享或自定义实现。
  • configuration_public.h- 根据您的平台调整所有配置值。
  • gyp_configuration.py

步骤

  • 修改该CreatePlatformConfig()函数以返回您在步骤1中定义的平台配置。下面的示例显示了Stub implementation and the Desktop Linux port:

Stub:

def CreatePlatformConfig():
  try:
    return PlatformConfig('stub')
  except RuntimeError as e:
    logging.critical(e)
    return None

Desktop Linux

def CreatePlatformConfig():
  try:
    return gyp_configuration.PlatformConfig('linux-x64x11')
  except RuntimeError as e:
    logging.critical(e)
    return None
  • 在GetVariables函数中,如果工具链使用clang ,请确保将clang变量设置为1:
    variables = super(PlatformConfig, self).GetVariables(configuration)
    variables.update({‘clang’: 1,})
    return variables

  • 在该GetEnvironmentVariables函数中,将这些字典值设置为适用于您平台的工具链类似物。请注意,“目标平台”是指端口所针对的平台(例如Android TV,Raspberry Pi),“主机平台”是运行交叉编译器到目标的工作站平台(例如桌面Linux,桌面Windows)。

  • gyp_configuration.gypi
    更新一下 default_configuration property 值 和 configurations property 值,修改这两个栏位 <”platform-configuration> - <build-type“>

     <”platform-configuration> 是在第一步上定义的值
     <"build-type> 是以下值之一:
     
      - debug 
      - devel 
      - qa 
      - gold
     
     配置文件中的以下代码段显示了这些属性在Stub实现中的显示方式。
     
         'target_defaults': {
           'default_configuration': 'stub_debug',
           'configurations': {
             'stub_debug': {
               'inherit_from': ['debug_base'],
             },
             'stub_devel': {
               'inherit_from': ['devel_base'],
             },
             'stub_qa': {
               'inherit_from': ['qa_base'],
             },
             'stub_gold': {
               'inherit_from': ['gold_base'],
             },
           }, # end of configurations
           ...
         }
    

    更新variables的属性:

    • target_arch - 标识架构。支持的值是arm,mips,ppc,x64,和x86。
    • target_os - 设置为linux移植平台是否基于Linux。如果不是,则删除此变量。
    • gl_type - 如果您使用的是系统EGL,则设置为 system_gles2,如果正在使用系统EGL + GLES3实现,请 设置为system_gles3。都不是的话就设置成 none。
    • in_app_dial - 启用(或禁用)在Cobalt内运行的DIAL服务器。(此服务器仅在Cobalt运行时运行。)DIAL协议使第二屏设备(如平板电脑和手机)能够在第一屏设备(如电视,机顶盒或者蓝牙设备)上显示。

    更新toolchain command-line flags and libraries
    更新 target_defaults.defines。 这里是一些全局变量,需要查看以下是否要更新。

  • thread_types_public.h - 此文件放自定义实现。

5. Port modules to work on your platform

由于模块之间的依赖关系,您会发现更容易让一些模块在其他模块之前通过NPLB测试。我们建议按以下顺序移植模块以考虑此类依赖关系

  • Configuration
  • main(),
  • Application, and Event Pump - This is the call into SbEventHandle.
  • Memory
  • Byte Swap
  • Time
  • String/Character/Double
  • Log
  • File
  • Directory
  • System
  • Atomic
  • Thread & Thread Types
  • Mutex
  • Condition
  • Variable
  • Once
  • Socket
  • SocketWaiter
  • Window
  • Input
  • Blitter (if applicable)
  • Audio Sink
  • Media & Player
  • DRM
  • TimeZone
  • User Storage
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值