Email me: jollen # jollen.org

more: Jollen 的 Embedded Linux 教育訓練

« April 2010 | (回到Blog入口) | June 2010 »

May 2010 歸檔

May 11, 2010

更新 MokoidBoard (DMA-6410L) 至 Android 2.1 (Eclair)

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/ mokoid
Android 以 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.cpp
5. 編譯 Mokoid Product Tree

編譯 Android image:

$ make PRODUCT-dma6410xp-eng
6. 打包 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"

下載原始碼

May 21, 2010

Jollen 的 Android 系統管理雜記, #4: C 如何取得 property

上一則日記提到 Android property 的設定。在 Android 作業系統裡,取得 property 是很重要的工作。不管是 Android 框架層(使用 Java 語言),或是 Native 層(使用 C/C++ 語言),都可以看到讀取 property 的程式碼。

以下是一段簡單的範例程式,用以說明如何用 C 來讀取 Android 系統的 property:

/* * Copyright (C) 2010 The Mokoid Open Source Project * * 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 "LED Stub" #include <stdlib.h> #include <string.h> #include <unistd.h> #include <assert.h> #include <jni.h> #include <mokoid/led.h> #include <cutils/properties.h> #define HAL_DEFAULT_VARIANT "default" static const char *variant_keys[] = { "ro.hardware", /* This goes first so that it can pick up a different file on the emulator. */ "ro.product.board", "ro.board.platform", "ro.arch" }; #define HAL_VARIANT_KEYS_COUNT (sizeof(variant_keys)/sizeof(variant_keys[0])) int main() { int i; int status; char prop[PATH_MAX]; status = -EINVAL; for (i = 0; (status != 0) && (i < HAL_VARIANT_KEYS_COUNT); i++) { if (property_get(variant_keys[i], prop, NULL) == 0) { continue; } printf("Your property is: %s = %s\n", variant_keys[i], prop); } return 0; }

上述範例,是由 libhardware 的程式碼修改而成。HAL (即 libhardware) 會讀取以下四個 property:

  • ro.hardware
  • ro.product.board
  • ro.board.platform
  • ro.arch

習慣上,我們會以 "ro.product.board" 做為 HAL 模組的 "product name",ro.product.board 決定 HAL 模組的命名方式。例如,當 ro.product.board 為 "mokoid" 時,我們就必須將 HAL 模組命名為 *.mokoid.so,並存放於 system/lib/hw 目錄下。

關於 May 2010

此頁面包含了在May 2010發表於Jollen's Blog的所有日記,它們從老到新列出。

前一個存檔 April 2010

後一個存檔 June 2010

更多信息可在 主索引 頁和 歸檔 頁看到。

Top | 授權條款 | Jollen's Forum: Blog 評論、討論與搜尋
Copyright(c) 2006 www.jollen.org