MokoidBoard 是基於 DMA-6410L (S3C6410) 的一款開發板,目前使用在仕橙3G教室的大部份訓練課程裡,目前已經將 Android 2.1 (Eclair) 移植至 MokoidBoard 上。開發板使用者或是課程學員,同樣請使用 [Mokoid] product tree 即可編譯。
升級 Android 2.1 步驟如下
以下步驟提供給 MokoidBoard 使用者參考。依此步驟即可將您的 MokoidBoard 升級 Android 2.1。

圖一:Android 2.1

圖二:Home Screen
1. 準備 Android 1.6 原始碼
請備妥 MokoidBoard CD,將 Android 1.6 (Donut) 取原始碼取出,並解壓縮。
2. 取得 Mokoid 分支
將 Mokoid 分支取出,擺放到 vendor/ 目錄下:
$ svn co http://mokoid.googlecode.com/svn/trunk/ mokoidAndroid 以 product tree 方式維護分支與編譯程式碼,請確保 mokoid 分支存在於 vendor/ 目錄下。
3. 取得 DMA-6410L 的 LED Stub
Mokoid 上的 LED Stub 為骨架,依開發板硬體,須填入 system call 程式碼。文後附上一個給 DMA-6410L 的 LED Stub 原始碼。
4. 保留 BatteryService 實作
請注意,由於 Android 2.1 的 BatteryService native 實作上做了變更。因此,我們先將 1.6 版的 BatteryService natvie 實作備份下來:
$ cp frameworks/base/services/jni/com_android_server_BatteryService.cpp /tmp
待更新至 2.1 版後,再將 1.6 的實作放回 source tree。Android 2.1 在 BatteryService native 端,主要的變動是修改了 sysfs 的讀取方式。
4. 更新至 Android 2.1 版
依照 [Android 網站] 上的說明,安裝 repo。接著使用 repo 直接取回 Android 2.1 的程式碼即可:
$ cd <path-to-your-android-source>/
$ repo sync
將 com_android_server_BatteryService.cpp 放回 source tree:
$ cp /tmp/com_android_server_BatteryService.cpp frameworks/base/services/jni/com_android_server_BatteryService.cpp5. 編譯 Mokoid Product Tree
編譯 Android image:
$ make PRODUCT-dma6410xp-eng6. 打包 ramdisk.img
將編譯完成的 ramdisk.img 包裝成 u-boot 格式:
$ mkimage -A arm -O linux -T ramdisk -C none -a 0x50800000 -n "ramdisk" -d ramdisk.img ramdisk-uboot.img將 system.img 與 ramdisk-uboot.img 拷貝到 tftp 根目錄下,並設定好開發板的 tftp 環境。
7. 更新至 Android 2.1
最後將 system.img 與 ramdisk-uboot.img 燒錄至 MokoidBoard 即可:
U-Boot 1.1.6 (Jan 21 2010 - 08:58:14) for SMDK6410
CPU: S3C6410@666MHz
Fclk = 666MHz, Hclk = 166MHz, Pclk = 83MHz, Serial = CLKUART (ASYNC Mo
Board: SMDK6410
DRAM: 128 MB
Flash: 0 kB
NAND: 128 MB
In: serial
Out: serial
Err: serial
Initialise LCD with values
Hit any key to stop autoboot: 0
SMDK6410 # run system
dm9000 i/o: 0x30000300, id: 0x90000a46
MAC: 00:40:5c:26:0a:5b
could not establish link
TFTP from server 10.0.1.24; our IP address is 10.0.1.25
Filename 'system.img'.
Load address: 0x50008000
Loading: T ####################################
...
done
Bytes transferred = 59174016 (386ec80 hex)
NAND erase: device 0 offset 0xa00000, size 0x4300000
Erasing at 0x4ce0000 -- 100% complete.
OK
NAND write: device 0 offset 0xa00000, size 0x386ec80
Writing data at 0x40b8800 -- 100% complete.
59174016 bytes written: OK
SMDK6410 # run ramdisk_uboot
dm9000 i/o: 0x30000300, id: 0x90000a46
MAC: 00:40:5c:26:0a:5b
could not establish link
TFTP from server 10.0.1.24; our IP address is 10.0.1.25
Filename 'ramdisk-uboot.img'.
Load address: 0x50008000
Loading: ################################
done
Bytes transferred = 158894 (26cae hex)
NAND erase: device 0 offset 0x900000, size 0x100000
Erasing at 0x9e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x900000, size 0x100000
1048576 bytes written: OK

圖三:更新完成、啟動 MokoidBoard

圖四:執行 LedTest 範例、LED 燈初始化狀況為全滅

圖五:點亮 LED 1
DMA-6410L 的 LED Stub 原始碼
以下是 led.c 的原始碼,支援 DMA-6410L 的 LED 控制:
/*
* Copyright (C) 2009 Mokoid Open Source Project
* Copyright (C) 2009 Moko365 Inc
*
* Author: Jollen Chen <jollen@jollen.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "MokoidLedStub"
#include <hardware/hardware.h>
#include <fcntl.h>
#include <errno.h>
#include <cutils/log.h>
#include <cutils/atomic.h>
#include <mokoid/led.h>
/**
* Definition of kernel-space driver.
*/
#define LED_DEVICE "/dev/led"
#define LED_C608 1
#define LED_C609 2
static int led_device_close(struct hw_device_t* device)
{
struct led_control_device_t* ctx = (struct led_control_device_t*)device;
if (ctx) {
close(ctx->fd);
free(ctx);
}
return 0;
}
static int led_on(struct led_control_device_t *dev, int32_t led)
{
int fd;
LOGI("LED Stub: set %d on.", led);
fd = dev->fd;
switch (led) {
case LED_C608:
ioctl(fd, 1, &led);
break;
case LED_C609:
ioctl(fd, 1, &led);
break;
default:
return -1;
}
return 0;
}
static int led_off(struct led_control_device_t *dev, int32_t led)
{
int fd;
LOGI("LED Stub: set %d off.", led);
fd = dev->fd;
switch (led) {
case LED_C608:
ioctl(fd, 2, &led);
break;
case LED_C609:
ioctl(fd, 2, &led);
break;
default:
return -1;
}
return 0;
}
static int led_device_open(const struct hw_module_t* module, const char* name,
struct hw_device_t** device)
{
struct led_control_device_t *dev;
dev = (struct led_control_device_t *)malloc(sizeof(*dev));
memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = module;
dev->common.close = led_device_close;
dev->set_on = led_on;
dev->set_off = led_off;
*device = &dev->common;
/*
* Initialize Led hardware here.
*/
dev->fd = open(LED_DEVICE, O_RDONLY);
if (dev->fd < 0)
dev->fd = 2; /* Error Handler */
led_off(dev, LED_C608);
led_off(dev, LED_C609);
success:
return 0;
}
static struct hw_module_methods_t led_module_methods = {
open: led_device_open
};
const struct led_module_t HAL_MODULE_INFO_SYM = {
common: {
tag: HARDWARE_MODULE_TAG,
version_major: 1,
version_minor: 0,
id: LED_HARDWARE_MODULE_ID,
name: "Sample LED Stub",
author: "The Mokoid Open Source Project",
methods: &led_module_methods,
}
/* supporting APIs go here. */
};
新版的 led.h 設計:
/*
* Copyright (C) 2009 Mokoid Open Source Project
* Copyright (C) 2009 Moko365 Inc
*
* Author: Jollen Chen <jollen@jollen.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <hardware/hardware.h>
#include <fcntl.h>
#include <errno.h>
#include <cutils/log.h>
#include <cutils/atomic.h>
/***************************************************************************/
struct led_module_t {
struct hw_module_t common;
};
struct led_control_device_t {
struct hw_device_t common;
/* attributes */
int fd;
/* supporting control APIs go here */
int (*set_on)(struct led_control_device_t *dev, int32_t led);
int (*set_off)(struct led_control_device_t *dev, int32_t led);
};
/***************************************************************************/
struct led_control_context_t {
struct led_control_device_t device;
};
#define LED_HARDWARE_MODULE_ID "led"
下載原始碼
Jollen's Blog 使用 Github issues 與讀者交流討論。請點擊上方的文章專屬 issue,或 open a new issue
您可透過電子郵件 jollen@jollen.org,或是 Linkedin 與我連絡。更歡迎使用微信,請搜尋 WeChat ID:jollentw