Intel Edisonでシリアル文字出力
2014/11/03(月) 22:03 NetBSD はてブ情報 はてブに登録 はてブ数

さて、EdisonでもNetBSDやりたいねと。

まずは、シリアルから一文字出して気分を盛り上げたいところです。

u-bootのコマンドプロンプトから行った、シリアルコンソールのアドレス0xff010180に0x40を書き込んで@を出しましょう。

sys/arch/i386/i386/locore.Sにベタな感じで書いてみました。
--- sys/arch/i386/i386/locore.S.orig    2014-10-29 03:49:31.000000000 +0000
+++ sys/arch/i386/i386/locore.S 2014-11-03 11:37:11.000000000 +0000
@@ -304,6 +304,10 @@
        jmp     2f
 #endif

+       /* serial console put '@' */
+       movl    $0xff010180, %eax
+       movb    $0x40, (%eax)
+
 1:
        /*
         * At this point, we know that a NetBSD-specific boot loader
./build.sh -m i386 kernel=EDISONなんて感じでkernelを作って
# /usr/obj/tooldir.NetBSD-7.99.1-amd64/i486--netbsdelf/bin/objcopy -I elf32-i386 -O binary /usr/obj/sys/arch/i386/compile/EDISON/netbsd /tmp/netbsd.bin
って感じでbinary形式のkenrelを作ります。

EdisonをLinuxで起動し、scpを使ってnetbsd.binを転送後、/にコピーして再起動。
Poky (Yocto Project Reference Distro) 1.6 edison ttyMFD2

edison login: root
root@edison:~# scp tokuda@192.168.0.106:/tmp/netbsd.bin .
netbsd.bin                                    100%   14MB 614.6KB/s   00:23
root@edison:~# cp netbsd.bin /
root@edison:~# md5sum /netbsd.bin ./netbsd.bin
5d8163b95315ca2944d5a3be89ccefb7  /netbsd.bin
5d8163b95315ca2944d5a3be89ccefb7  ./netbsd.bin
root@edison:~# sync
root@edison:~# reboot
さきほど書き込んだ/netbsd.binはmmcblk0p8なのでu-boot的にはmmc 0:8って感じになるようで、次のような手順でブートしました。
U-Boot 2014.04 (Sep 08 2014 - 14:09:10)

       Watchdog enabled
DRAM:  980.6 MiB
MMC:   tangier_sdhci: 0
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
boot >
boot > ext4load mmc 0:8 100000 netbsd.bin
14473916 bytes read in 12736 ms (1.1 MiB/s)
boot > go 100000
## Starting application at 0x00100000 ...
@
おー、ちゃんと@が表示されましたねー。

実は、u-bootのときに気付いたのですが、0xff010180に0x40を書き込む際に、以前はmm.lを使って書き込んでいたのですが、それだとうまくいきません。

mm.bを使わなければなりませんでした。

u-bootでmd.l 0xff010180してみるとこんな感じです。
boot > md.l 0xff010180 4
ff010180: 03c10200 00110003 00000000 00000000    ................
レジスタの最初のほうに0x03c102が入っています。
なので、32bit単位で書き込むとおかしな表示になってしまいます。
boot > mm.l 0xff010180
ff010180: 03c10200 ? 40
&1,8M
      ア
       0l
で、うーんと思って試しに0x03c102を変更せず、下位8bitだけを変更してうまくいったわけです。
boot > mm.l 0xff010180
ff010180: 03c10200 ? 03c10240
@ff010184: 00110003 ? .
boot >
もしかすると、このシリアルコンソールってcomドライバではないってことですかね。

だとしたら、シリアルコンソールドライバをcomでラクできないってことに...

1: Andy 2016年01月20日(水) 午前7時14分

Have you seen this one: https://www.reddit.com/r/freebsd/comments/3xktgm/freebsd_on_intel_edison_has_anyone_tried_doing/


名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/0850/tb/

Intel Edison買いました
2014/11/03(月) 21:31 NetBSD はてブ情報 はてブに登録 はてブ数

Intel Edison買いました。

最新のファームにアップデート。
root@edison:~# uname -a
Linux edison 3.10.17-poky-edison+ #1 SMP PREEMPT Mon Sep 8 14:09:55 CEST 2014 i686 GNU/Linux
内蔵MMCはこんな感じでマウントされてる。
root@edison:~# mount|grep mmcblk
/dev/mmcblk0p8 on / type ext4 (rw,nodev,noatime,discard,noauto_da_alloc,data=ordered)
/dev/mmcblk0p5 on /factory type ext4 (ro,nosuid,nodev,noatime,discard,noauto_da_alloc)
/dev/mmcblk0p10 on /home type ext4 (rw,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered)
mmcblk0p7はマウントされていないが、ここからブートしているようだ。
root@edison:~# mount -t msdos /dev/mmcblk0p7 /mnt
root@edison:~# mount | grep msdos
/dev/mmcblk0p7 on /mnt type msdos (rw,relatime,fmask=0022,dmask=0022,codepage=437,errors=remount-ro)
root@edison:~# ls /mnt
ldlinux.c32   ldlinux.sys   syslinux.cfg  vmlinuz
root@edison:~# df /mnt
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mmcblk0p7            5638      5182       456  92% /mnt
rootパーティションは10MB程度の空きがあるようだ。kernelを置くぐらいならできそうだ。
root@edison:/mnt# df -m /
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/root                  464       454         0 100% /
Windowsからドライブとして見える領域がLinuxから簡単に参照できるのだろうか。

ブートローダはu-boot。起動時に素早くキー入力を行うとu-bootプロンプトが表示され、コマンド入力を受け付ける。
-Boot 2014.04 (Sep 08 2014 - 14:09:10)

       Watchdog enabled
DRAM:  980.6 MiB
MMC:   tangier_sdhci: 0
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
boot > help
?       - alias for 'help'
askenv  - get environment variables from stdin
base    - print or set address offset
bdinfo  - print Board Info structure
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootelf - Boot from an ELF image in memory
bootm   - boot application image from memory
bootvx  - Boot vxWorks from an ELF image
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
dcache  - enable or disable data cache
dfu     - Device Firmware Upgrade
echo    - echo args to console
editenv - edit environment variable
env     - environment handling commands
exit    - exit script
ext4load- load binary file from a Ext4 filesystem
ext4ls  - list files in a directory (default /)
ext4write- create a file in the root directory
false   - do nothing, unsuccessfully
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
fatwrite- write file into a dos filesystem
gettime - get timer val elapsed,

go      - start application at address 'addr'
gpt     - GUID Partition Table
grepenv - search environment variables
hash    - compute message digest
help    - print command description/usage
icache  - enable or disable instruction cache
in      - read data from an IO port
ini     - parse an ini file in memory and merge the specified section into the env
interrupts- enable or disable interrupts
irqinfo - print information about IRQs
itest   - return true/false on integer compare
load    - load binary file from a filesystem
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loadx   - load binary file over serial line (xmodem mode)
loady   - load binary file over serial line (ymodem mode)
loop    - infinite loop on address range
ls      - list files in a directory (default /)
md      - memory display
meminfo - display memory information
mm      - memory modify (auto-incrementing address)
mmc     - MMC sub system
mmcinfo - display MMC info
mw      - memory write (fill)
nm      - memory modify (constant address)
out     - write datum to IO port
part    - disk partition related commands
pci     - list and access PCI Configuration Space
printenv- print environment variables
read    - Load binary data from a partition
reginfo - print register information
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv  - set environment variables
setexpr - set environment variable as the result of eval expression
sha1sum - compute SHA1 message digest
showvar - print local hushshell variables
sleep   - delay execution for some time
source  - run script from memory
test    - minimal test like /bin/sh
timer   - access the system timer
true    - do nothing, successfully
version - print monitor, compiler and linker version
zboot   - Boot bzImage
シリアルコンソールはLinuxのdmesgからttyMFD2でアドレスは0xff010180、IRQは54の模様。
root@edison:~# dmesg | grep ttyMFD2
[    0.000000] Kernel command line: root=PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4 rootfstype=ext4 console=ttyMFD2 earlyprintk=ttyMFD2,keep loglevel=4 systemd.unit=multi-user.target hardware_id=00 g_multi.iSerialNumber=c6305d42cdcc9203bf0c6a2901a70a5a
[    0.727379] 0000:00:04.3: ttyMFD2 at MMIO 0xff010180 (irq = 54) is a hsu_debug_port_p
[    0.734998] console [ttyMFD2] enabled
[    2.368030] systemd[1]: Expecting device dev-ttyMFD2.device...
u-bootからシリアルコンソールとおぼしきアドレスに直接書き込んでみる。40を書き込んでいるが、これはアットマークのASCIIコード。
boot > mm.b 0xff010180
ff010180: 00 ? 40
@ff010181: 02 ? .
ちゃんとアットマークが表示された。

u-bootがどのようにvmlinuzを実行しているのか、u-bootからprintを実行して重要そうなところを記録しておく。
boot_target_cmd=run do_flash_os;run do_probe_dfu;run do_compute_target;run mmc-bootargs;run load_kernel;zboot ${loadaddr}
load_kernel=fatload mmc 0:7 ${loadaddr} vmlinuz
loadaddr=0x100000
MMCのパーティション7から0x100000にvmlinuzをロードし、zboot 0x100000しているようだ。

zbootはbzImage形式のファイルを処理するもののようだ。bzImage形式は、http://wiki.bit-hive.com/linuxkernelmemo/pg/bzImageに書いてある情報を参考にすると、カーネルのbinaryイメージの前にbootsect.o, setup.oというのがくっついている形式らしい。

startup_32が0x100000にあるのかと思ったが、/proc/kallsymsを見ると0xc1200000にあるようだ。
root@edison:/proc# head kallsyms
c1200000 T startup_32
c1200000 T _text
c12000b8 T start_cpu0
c12000c8 T _stext
c12000d0 T do_one_initcall
c1200230 t match_dev_by_uuid
c1200260 T name_to_dev_t
c12005d0 t init_linuxrc
c1200670 t set_ti_thread_flag
c1200680 T start_thread

名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/0849/tb/