顯示具有 Embedded - qcm 標籤的文章。 顯示所有文章
顯示具有 Embedded - qcm 標籤的文章。 顯示所有文章

2018年9月2日 星期日

How to clone MDM9207 codeaurora/openembedded


筆記一下How to clone MDM9207 codeaurora/openembedded
brook@vista:~/oe-9x07$ git clone https://gerrit.googlesource.com/git-repo
Cloning into 'git-repo'...
remote: Counting objects: 139, done
remote: Total 4069 (delta 2714), reused 4069 (delta 2714)
Receiving objects: 100% (4069/4069), 1.21 MiB | 0 bytes/s, done.
Resolving deltas: 100% (2714/2714), done.
Checking connectivity... done.
brook@vista:~/oe-9x07$ ln -s git-repo/repo
brook@vista:~/oe-9x07$ ./repo init -u git://codeaurora.org/quic/le/le/manifest.git -b release -m LE.UM.1.0.2-34100-9x07.xml
Get https://gerrit.googlesource.com/git-repo/clone.bundle
Get https://gerrit.googlesource.com/git-repo
Get git://codeaurora.org/quic/le/le/manifest.git
remote: Counting objects: 4009, done.
remote: Compressing objects: 100% (191/191), done.
remote: Total 4009 (delta 84), reused 0 (delta 0)        KiB/s
Receiving objects: 100% (4009/4009), 1.07 MiB | 706.00 KiB/s, done.
Resolving deltas: 100% (2191/2191), done.
From git://codeaurora.org/quic/le/le/manifest
 * [new branch]      IMM.LE.1.0 -> origin/IMM.LE.1.0
 * [new branch]      release    -> origin/release
...
...
Your identity is: Brook Kuo <rene3210 at gmail.com>
If you want to change this, please re-run 'repo init' with --config-name

repo has been initialized in /home/brook/oe-9x07

brook@vista:~/oe-9x07$ ./repo sync
Fetching project platform/vendor/qcom/titanium_32
remote: Counting objects: 5758, done.
remote: Compressing objects: 100% (375/375), done.
remote: Total 5758 (delta 305), reused 380 (delta 177)
Receiving objects: 100% (5758/5758), 1.02 MiB | 868.00 KiB/s, done.
Resolving deltas: 100% (3639/3639), done.
From git://codeaurora.org/platform/vendor/qcom/titanium_32
 * [new branch]      LA.BR.1.3.7_rb1.11 -> caf/LA.BR.1.3.7_rb1.11
...
...
Fetching projects: 100% (58/58), done.
Checking out files: 100% (52804/52804), done. files:  23% (12539/52804)
Checking out files: 100% (622/622), done. out files:  26% (167/622)
Syncing work tree: 100% (58/58), done.



    參考資料
  • https://gerrit.googlesource.com/git-repo/, repo - The Multiple Git Repository Tool
  • https://wiki.codeaurora.org/xwiki/bin/QLBEP/, Open Embedded for MSM




2018年8月25日 星期六

Using gdbserver to debug MDM9xxx


openembedded提供了一個良好的gdb環境,設定步驟如下。
brook@vista:/home/brook/apps_proc/poky/build$ tar zxvf tmp-glibc/deploy/images/mdm9607/machine-image-mdm9607-dbg.tar.gz
./
./var/
./var/lib/
./var/lib/opkg/
./var/lib/opkg/info/
...

brook@vista:/home/brook/apps_proc/poky/build$ mv usr/lib/.debug/* usr/lib/
brook@vista:/home/brook/apps_proc/poky/build$ mv lib/.debug/* lib

brook@vista:/home/brook/apps_proc/poky/build$ ln -s libconfig.so.9.2.0 usr/lib/libconfig.so.9
...

brook@vista:/home/brook/apps_proc/poky/build$ ln -s libpthread-2.22.so lib/libpthread.so.0
brook@vista:/home/brook/apps_proc/poky/build$ ln -s librt-2.22.so lib/librt.so.1
brook@vista:/home/brook/apps_proc/poky/build$ ln -s libm-2.22.so lib/libm.so.6
brook@vista:/home/brook/apps_proc/poky/build$ ln -s libc-2.22.so lib/libc.so.6
brook@vista:/home/brook/apps_proc/poky/build$ ln -s ld-2.22.so lib/ld-linux.so.3
brook@vista:/home/brook/apps_proc/poky/build$ ln -s libdl-2.22.so lib/libdl.so.2
...

brook@vista:/home/brook/apps_proc/poky/build/tmp-glibc/work/armv7a-vfp-neon-oe-linux-gnueabi/myprog/git-r0/build/src$ adb push myprog /usr/bin/myprog

brook@vista:/home/brook/apps_proc/poky/build/tmp-glibc/work/armv7a-vfp-neon-oe-linux-gnueabi/myprog/git-r0/build/src$ adb shell
sh-3.2# gdbserver :2345 /usr/bin/myprog
Process /usr/bin/myprog created; pid = 9035
Listening on port 2345


接著host端就可以開啟GDB來debug了
brook@vista:/home/brook/apps_proc/poky/build/tmp-glibc/work/armv7a-vfp-neon-oe-linux-gnueabi/myprog/git-r0/build/src$ arm-oe-linux-gnueabi-gdb myprog 
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
...
Reading symbols from myprog...done.
(gdb) set sysroot /home/brook/apps_proc/poky/build/
(gdb) target remote 10.0.0.1:2345
Remote debugging using 10.0.0.1:2345
Reading symbols from /home/brook/apps_proc/poky/build//lib/ld-linux.so.3...done.
0xb6fceac0 in ?? ()
(gdb) b main
Breakpoint 1 at 0x7f5595ac: file /home/brook/apps_proc/poky/build/tmp-glibc/work/armv7a-vfp-neon-oe-linux-gnueabi/myprog/git-r0/src/main.c, line 207.
(gdb) c
Continuing.

Breakpoint 1, main (argc=1, argv=0xbefffdf4)
    at /home/brook/apps_proc/poky/build/tmp-glibc/work/armv7a-vfp-neon-oe-linux-gnueabi/myprog/git-r0/src/main.c:207
207     {
(gdb) set sysroot /home/brook/apps_proc/poky/build
warning: .dynamic section for "/home/brook/apps_proc/poky/build/lib/libpthread.so.0" is not at the expected address (wrong library or version mismatch?)
warning: .dynamic section for "/home/brook/apps_proc/poky/build/lib/libm.so.6" is not at the expected address (wrong library or version mismatch?)
warning: .dynamic section for "/home/brook/apps_proc/poky/build/lib/libc.so.6" is not at the expected address (wrong library or version mismatch?)
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Reading symbols from /home/brook/apps_proc/poky/build/usr/lib/libconfig.so.9...done.
Reading symbols from /home/brook/apps_proc/poky/build/lib/libpthread.so.0...done.
Reading symbols from /home/brook/apps_proc/poky/build/lib/librt.so.1...done.
Reading symbols from /home/brook/apps_proc/poky/build/lib/libm.so.6...done.
Reading symbols from /home/brook/apps_proc/poky/build/lib/libc.so.6...done.
Reading symbols from /home/brook/apps_proc/poky/build/lib/libdl.so.2...done.
(gdb) info share
From        To          Syms Read   Shared Object Library
0x7473e7c0  0x7475a328  Yes         /home/brook/apps_proc/poky/build/lib/ld-linux.so.3
0xb6fc42d0  0xb6fca6e0  Yes         /home/brook/apps_proc/poky/build/usr/lib/libconfig.so.9
0xb6ebc210  0xb6ecb4e8  Yes         /home/brook/apps_proc/poky/build/lib/libpthread.so.0
0xb6ea2720  0xb6ea6034  Yes         /home/brook/apps_proc/poky/build/lib/librt.so.1
0xb6e28bf0  0xb6e5ac20  Yes         /home/brook/apps_proc/poky/build/lib/libm.so.6
0xb6ced280  0xb6dee638  Yes         /home/brook/apps_proc/poky/build/lib/libc.so.6
0xb6cc3928  0xb6cc4870  Yes         /home/brook/apps_proc/poky/build/lib/libdl.so.2
確認所有symbol都有找到之後, 就可以開始debug之旅了.




2016年10月1日 星期六

QC的partition table大小設定與實際大小對應關係


這裡記錄一下QC的9x40 partition table configure file(common/build/partition_nand.xml)size與實際的大小怎麼換算。 大概就兩類tag,一個tag是size_blks,以eraseblock為單位。另一個是tag是size_kb,所以實際大小還要轉成eraseblock。 如:
/ # cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00280000 00040000 "sbl"
mtd1: 00280000 00040000 "mibib"
mtd2: 00c00000 00040000 "efs2"
mtd3: 00140000 00040000 "tz"
mtd4: 00100000 00040000 "rpm"
mtd5: 00140000 00040000 "aboot"
...

partition table configure file內容
<partition>
    <name length="16" type="string">0:SBL</name>
    <size_blks length="4">0x8</size_blks>
    <pad_blks length="4">0x2</pad_blks>
    ...
</partition>
...
<partition>
    <name length="16" type="string">0:EFS2</name>
    <size_kb length="4">11264</size_kb>
    <pad_kb length="4">1024</pad_kb>
    ....
</partition>
SBL的設定為0x8+0x2個eraseblock,所以/proc/mtd大小為 (8 + 2) * 256 * 1024 = 0x280000。 EFS2的設定為11264+1024 KB,所以/proc/mtd大小為ceiling(11264 / 256)+ceiling(1024 / 256) = 48個eraseblock,所以/proc/mtd大小為48 * 256 * 1024 = 0xC0000。 eraseblock就是上面的erasesize,0x40000 / 1024 = 256kb。


2015年12月13日 星期日

mkbootimg -- pack boot images utils


mkbootimg是Android project的一部分,用來封裝boot image的,其使用參數如下:
usage: mkbootimg
       --kernel <filename>
       --ramdisk <filename>
       [ --second <2ndbootloader-filename> ]
       [ --cmdline <kernel-commandline> ]
       [ --board <boardname> ]
       [ --base <address> ]
       [ --pagesize <pagesize> ]
       [ --ramdisk_offset <ramdisk_offset> ]
       [ --dt <filename> ]
       [ --tags-addr <address> ]
       -o|--output <filename>


基本上就是將kenrnel、ramdisk、device tree等封裝成一個檔案,讓boot loader能將其載入RAM中,並正確執行。檔案的layout如下(就如bootimg.h中註解所提到的,https://www.codeaurora.org/cgit/quic/femto/platform/system/core/tree/mkbootimg/bootimg.h?h=LNX.LE.5.0.1-57023-9x40)
/*
** +-----------------+ 
** | boot header     | 1 page
** +-----------------+
** | kernel          | n pages  
** +-----------------+
** | ramdisk         | m pages  
** +-----------------+
** | second stage    | o pages
** +-----------------+
** | device tree     | p pages
** +-----------------+
**
** n = (kernel_size + page_size - 1) / page_size
** m = (ramdisk_size + page_size - 1) / page_size
** o = (second_size + page_size - 1) / page_size
** p = (dt_size + page_size - 1) / page_size
**
** 0. all entities are page_size aligned in flash
** 1. kernel and ramdisk are required (size != 0)
** 2. second is optional (second_size == 0 -> no second)
** 3. load each element (kernel, ramdisk, second) at
**    the specified physical address (kernel_addr, etc)
** 4. prepare tags at tag_addr.  kernel_args[] is
**    appended to the kernel commandline in the tags.
** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
** 6. if second_size != 0: jump to second_addr
**    else: jump to kernel_addr
*/

其中boot header會有一些information,讓LK能正確的將各個section load到正確的Address上,boot header定義如下
typedef struct boot_img_hdr boot_img_hdr;

#define BOOT_MAGIC "ANDROID!"
#define BOOT_MAGIC_SIZE 8
#define BOOT_NAME_SIZE 16
#define BOOT_ARGS_SIZE 512

struct boot_img_hdr
{
    unsigned char magic[BOOT_MAGIC_SIZE];

    unsigned kernel_size;  /* size in bytes */
    unsigned kernel_addr;  /* physical load addr */

    unsigned ramdisk_size; /* size in bytes */
    unsigned ramdisk_addr; /* physical load addr */

    unsigned second_size;  /* size in bytes */
    unsigned second_addr;  /* physical load addr */

    unsigned tags_addr;    /* physical addr for kernel tags */
    unsigned page_size;    /* flash page size we assume */
    unsigned dt_size;      /* device tree in bytes */
    unsigned unused;       /* future expansion: should be 0 */
    unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
    
    unsigned char cmdline[BOOT_ARGS_SIZE];

    unsigned id[8]; /* timestamp / checksum / sha1 / etc */
};

第一個欄位magic用以識別這個image是否為有效,後續會帶著kernel、ramdisk、device tree跟second的size大小,以及要load的address。 以下是我的platform的FLASH與其RAM的layout,如下圖

基本上,main function就是將這些檔案pack成一個檔案,並做page alignment,有興趣再去看code吧。

下面這段是我寫的umkbootimg,讀取boot header資訊後印出。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>

#include "bootimg.h"

static void *load_file(const char *fn, unsigned sz)
{
    char *data;
    int fd;

    data = 0;
    fd = open(fn, O_RDONLY);
    if(fd < 0) return 0;

    data = (char*) malloc(sz);
    if(data == 0) goto oops;

    if(read(fd, data, sz) != sz) goto oops;
    close(fd);

    return data;

oops:
    close(fd);
    if(data != 0) free(data);
    return 0;
}

int usage(void)
{
    fprintf(stderr,"usage: umkbootimg <filename>\n");
    return 1;
}


int main(int argc, char **argv)
{
    boot_img_hdr *hdr;

    char *img_name = 0;
    void *img_data = 0;
    unsigned sz;

    if (argc < 2) {
        return usage();
    }

    hdr = (boot_img_hdr *) load_file(argv[1], sizeof(boot_img_hdr));
    hdr->magic[BOOT_MAGIC_SIZE] = 0;
    printf("magic:%s\n", hdr->magic);
    printf("kernel_size:%u/0x%08x\n", hdr->kernel_size, hdr->kernel_size);
    printf("kernel_addr:%u/0x%08x\n", hdr->kernel_addr, hdr->kernel_addr);

    printf("ramdisk_size:%u/0x%08x\n", hdr->ramdisk_size, hdr->ramdisk_size);
    printf("ramdisk_addr:%u/0x%08x\n", hdr->ramdisk_addr, hdr->ramdisk_addr);

    printf("second_size:%u/0x%08x\n", hdr->second_size, hdr->second_size);
    printf("second_addr:%u/0x%08x\n", hdr->second_addr, hdr->second_addr);

    printf("tags_addr:%u/0x%08x\n", hdr->tags_addr, hdr->tags_addr);

    printf("page_size:%u/0x%08x\n", hdr->page_size, hdr->page_size);

    printf("dt_size:%u/0x%08x\n", hdr->dt_size, hdr->dt_size);

    printf("name:%s\n", hdr->name);

    printf("cmdline:%s\n", hdr->cmdline);
    return 0;
}


    參考資料:
  • https://www.codeaurora.org/cgit/quic/femto/platform/system/core/tree/mkbootimg/bootimg.h?h=LNX.LE.5.0.1-57023-9x40




2015年9月29日 星期二

create an initramfs on mdm9x40


利用linux提供的script建立initramfs在先前的文章已經提過,可參考如何利用kvm/qemu練習linux module之new update,基本上就是呼叫gen_initramfs_list.sh建立file system清單,使用gen_init_cpio將清單轉成CPIO格式後,在使用gzip做壓縮。相關指令如下:
W=/home/brook/projects/9x40/apps_proc
RD=/home/brook/projects/initramfs
CPIO=/home/brook/projects/initramfs.cpio
SYSROOT=${W}/oe-core/build/tmp-eglibc/sysroots/
OUTPUT=/home/brook/projects/9x40-initramfs.img
sh ${W}/kernel/scripts/gen_initramfs_list.sh -d ${RD} > /tmp/gen_initramfs_list
${W}/oe-core/build/tmp-eglibc/sysroots/mdm9640/usr/src/kernel/usr/gen_init_cpio /tmp/gen_initramfs_list > ${CPIO}
gzip -c ${CPIO} > ${CPIO}.gz


我是copy recipes/linux-quic/linux-quic_git.bb裡面的do_deploy(),接著修改成另外一個script,來建立image,指令如下:
${SYSROOT}/x86_64-linux/usr/bin/mkbootimg --kernel ${SYSROOT}/mdm9640/boot/zImage-3.10.49 --dt ${SYSROOT}/mdm9640/boot/masterDTB --ramdisk ${CPIO}.gz --cmdline "dynamic_debug.verbose=1 root=/dev/ram rootfstype=ramfs console=ttyHSL0,115200,n8 androidboot.hardware=qcom ehci-hcd.park=3 msm_rtb.filter=0x37" --base 0x81C00000 --tags-addr 0x81900000 --pagesize 2048 --ramdisk_offset 0xd32000 --output ${OUTPUT}

這裡的重點是cmdline要改成"root=/dev/ram rootfstype=ramfs",否則在lk的lk/app/aboot/aboot.c:update_cmdline()會塞一些information給kernel,導致無法由initramfs開機。

相關檔案位置: https://www.codeaurora.org/cgit/quic/le/mdm/manifest/tree/?id=LNX.LE.5.0.1-57014-9x40
LNX.LE.5.0.1-57014-9x40.xml: repo manifest file,

https://www.codeaurora.org/cgit/quic/le/kernel/lk/tree/app/aboot/aboot.c?id=LNX.LE.5.0.1-57014-9x40
lk/app/aboot/aboot.c: unsigned char *update_cmdline(const char * cmdline)

https://www.codeaurora.org/cgit/quic/le/oe/recipes/tree/conf/machine/mdm9640.conf?h=LNX.LE.5.0.1_rb1.7
conf/machine/mdm9640.conf: MACHINE_KERNEL_TAGS_OFFSET = "0x81900000"

https://www.codeaurora.org/cgit/quic/le/oe/recipes/tree/recipes/linux-quic/linux-quic_git.bb?id=LNX.LE.5.0.1-57014-9x40
recipes/linux-quic/linux-quic_git.bb: do_deploy()



熱門文章