2014/10/28(火)glibcのビルド

逆アセンブルしてもソースコード中の関数をみても一致しない。
なぜだろうか・・・、ということで少し探ってみた時のメモ。
解決に至っていないので、そのものズバリが欲しい人は回れ右でお願いいたします・・・。
情報提供、誤り指摘はありがたく頂戴させていただきます。

ビルドされたログを見る

ct-ngにビルドしてもらった時のログから、1ファイルのコマンドラインを引っ張ってみる。
[ALL  ] 
( echo '#define SYSCALL_NAME close';
	echo '#define SYSCALL_NARGS 1';
	echo '#define SYSCALL_SYMBOL __libc_close';
	echo '#define SYSCALL_CANCELLABLE 1';
	echo '#include <syscall-template.S>';
	echo 'weak_alias (__libc_close, __close)';
	echo 'libc_hidden_weak (__close)';
	echo 'weak_alias (__libc_close, close)';
	echo 'libc_hidden_weak (close)';
	) \
 | arm-linaro-linux-gnueabi-gcc -c 
 -I../include 
-I/PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/build/build-libc-final/io 
-I/PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/build/build-libc-final 
-I../ports/sysdeps/arm/elf 
-I../ports/sysdeps/unix/sysv/linux/arm/eabi/nptl 
-I../ports/sysdeps/unix/sysv/linux/arm/eabi 
-I../ports/sysdeps/unix/sysv/linux/arm/nptl 
-I../ports/sysdeps/unix/sysv/linux/arm 
-I../nptl/sysdeps/unix/sysv/linux 
-I../nptl/sysdeps/pthread 
-I../sysdeps/pthread 
-I../ports/sysdeps/unix/sysv/linux 
-I../sysdeps/unix/sysv/linux 
-I../sysdeps/gnu 
-I../sysdeps/unix/common 
-I../sysdeps/unix/mman 
-I../sysdeps/unix/inet 
-I../nptl/sysdeps/unix/sysv 
-I../ports/sysdeps/unix/sysv 
-I../sysdeps/unix/sysv 
-I../ports/sysdeps/unix/arm 
-I../nptl/sysdeps/unix 
-I../ports/sysdeps/unix 
-I../sysdeps/unix 
-I../sysdeps/posix 
-I../ports/sysdeps/arm/eabi 
-I../ports/sysdeps/arm/nptl 
-I../ports/sysdeps/arm 
-I../sysdeps/wordsize-32 
-I../sysdeps/ieee754/flt-32 
-I../sysdeps/ieee754/dbl-64 
-I../sysdeps/ieee754 
-I../sysdeps/generic/elf 
-I../sysdeps/generic 
-I../nptl 
-I../ports  
-I.. 
-I../libio 
-I. -nostdinc
 -isystem /PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/buildtools/lib/gcc/arm-linaro-linux-gnueabi/4.7.4/include
 -isystem /PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/buildtools/lib/gcc/arm-linaro-linux-gnueabi/4.7.4/include-fixed
 -isystem /opt/export/V980_cam/repo/_master_m8m/hosttool/arm-linaro-linux-gnueabi/arm-linaro-linux-gnueabi/sysroot/usr/include
 -D_LIBC_REENTRANT
 -include ../include/libc-symbols.h
 -DASSEMBLER
   -Wa,--noexecstack  
 -o /PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/build/build-libc-final/io/close.o
 -x assembler-with-cpp -
 -MD
 -MP
 -MF /PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/build/build-libc-final/io/close.o.dt
 -MT
 /PATH/TO/MYDIR/_build/arm-linaro-linux-gnueabi/build/build-libc-final/io/close.o
ソースコードだけ見ててもアカンやつや...
というかむしろソースコードないぞおい.
echoコマンドで現存するシステムコールはソースコードを生成してコンパイルしちゃうのかなぁ.
えぐいなぁ...

glibcじゃなくなるけど, eglibcの場合は 以下のソースをincludeして コードが生成されちゃう模様.
src/eglibc-2_13/sysdeps/unix/syscall-template.S
src/eglibc-2_13/ports/sysdeps/unix/sysv/linux/arm/nptl/sysdep-cancel.h
※nptl/cancel可能を前提として.

2014/10/08(水)memory test

メモリテストプログラム

いわゆるPCのmemtestがそう。
PCとは異なるアーキテクチャでも、特に組込み危機でも必要となるでしょう。
この記事は、メモ代わりに記載するだけで本体に価値はありません・・・。
(オフラインで資料を作る際に参考にさせていただいた時のメモ)

メモリテストの目的や達成目標を明確にすることで、必要十分なものを選択しましょう。
(過去の踏襲…とか、非論理的なシゴトは決してしないように、なぁ。)

参考

メモリテストに関するよい記事

http://www.barrgroup.com/Embedded-Systems/How-To/Memory-Test-Suite-C

掲示板には20年の職人が来ている

http://stackoverflow.com/questions/3729544/free-implementation-of-march-memory-testing-algorithm
>Memory testing with cache
>Permalink Submitted by krishnakoyalmannam on Thu, 2011-05-19 02:00.
When you are testing external DDR2 memory on a multicore system,
 with a shared Level 2 Cache,
 each core could be assigned a dedicated section of memory to test and all the cores memory tests in parallel.
This causes the L2 cache to result in more cache miss than cache hit,
 thereby resulting in increased DRAM bus transactions,
 which could be very useful during HW Board BringUp.
And yes, the ground bounce and cross-talk tests do check for signal integrity problems. There is also MARCH-B and MARCH-C memory testing algorithms that sweep memory with random patterns in one direction and sweep in the reverse direction, so, a cache flush would be required before starting the reverse sweep. And finally, an XOR test to uncover memory cell faults, would make the suite of memory tests quite comprehensive providing greater coverage.

マーチアルゴリズム:LSIテスト用だなぁ

http://www.ece.uc.edu/~wjone/
http://www.ece.uc.edu/~wjone/Memory.pdf

2014/10/08(水)procfsの辿り方

kernel coding:

http://www.linuxplanet.org/blogs/?cat=4558
http://tuxthink.blogspot.jp/2013/10/creating-read-write-proc-entry-in.html

proc_create("name", 0, NULL, &proc_fops);

Ex. fs/proc/cmdline.c
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

static int cmdline_proc_show(struct seq_file *m, void *v)
{
        seq_printf(m, "%s\n", saved_command_line);
        return 0;
}

static int cmdline_proc_open(struct inode *inode, struct file *file)
{
        return single_open(file, cmdline_proc_show, NULL);
}

static const struct file_operations cmdline_proc_fops = {
        .open           = cmdline_proc_open,
        .read           = seq_read,
        .llseek         = seq_lseek,
        .release        = single_release,
};

static int __init proc_cmdline_init(void)
{
        proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
        return 0;
}
module_init(proc_cmdline_init);
非常に判りよい例.. ;)

2014/10/01(水)git

パッチファイルを作りたい

他所のリポジトリにコードを持って行く時や, 差分ファイル提供を要求される場合に
相手もgitを使っている場合に同期を取りやすい方法:
mkdir /path/to/files
git format-patch  -o /path/to/files  <revision-format> 
適用する場合には shellのファイル展開を期待するなら:
git am -p<n> < /path/to/files/*
こっちのほうがいいかも.
for f in `ls -l /path/to/files/*`
do
  git am -p<n> < $f
done
★参照URL
https://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/

linux kernel debug(小技)

2014/07/25linux::debugimport

kernel debug

driver毎のデバッグ出力

pr_debug()は"DEBUG"が定義されているときしか出力されない。
全域で表示させると、UBIなどの大量に吐き出してしまうモノがいるので厄介。
ファイルごとであれば、includeまえに
#define DEBUG (1)
とか、宣言を追加しても良いし、Makefileを編集しても良い。

ブロック単位?であれば、"FILE: driver/of/Makefile"に以下の一行を追加する。
ccflags-y := -DDEBUG
Flattened device tree関連のデバッグ出力が付与されて気持ちよく動作が見える。

参考資料

Documentation/kbuild/makefiles.txt
*1

*1 : このへんとか.. http://lxr.free-electrons.com/source/Documentation/kbuild/makefiles.txt