メッセージ欄

2014年11月の日記

一覧で表示する

NetBSD/evbarm on Radxa Rock USB編 その2
2014/11/10(月) 28:16 NetBSD はてブ情報 はてブに登録 はてブ数

なんか、動くようになってました。

変えたところは、USBメモリを刺すポートを隣にしたのと、以下ぐらい? たぶん関係なさそう。
--- a/arm/rockchip/rockchip_dwctwo.c
+++ b/arm/rockchip/rockchip_dwctwo.c
@@ -83,7 +83,7 @@ static struct dwc2_core_params rkdwc2_params = {
        .ts_dline                       = 0,    /* 0 - No (default) */
        .reload_ctl                     = 0,    /* 0 - No (default for core < 2.92a) */
        .ahbcfg                         = 0x7,  /* INCR16 */
-       .uframe_sched                   = 1,    /* True to enable microframe scheduler */
+       .uframe_sched                   = -1,   /* True to enable microframe scheduler */
 };
すごい不安定だから、まったく同じカーネルでも起動したりpanicしたり。

USBメモリをroot deviceとして、USB無線LANアダプタでネットワークも使えています。とはいえ、すごい遅いんですけど。

手持ちのUSB有線LANアダプタが二つあったのですが、認識されるけどパケットが出ていかない、認識する途中でポートから切り離される、など残念な感じでした。
Loaded initial symtab at 0x8079e878, strtab at 0x807d4668, # entries 13772
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 7.99.1 (RADXA) #204: Mon Nov 10 18:14:38 UTC 2014
        root@aug:/usr/obj/sys/arch/evbarm/compile/RADXA
total memory = 1024 MB
avail memory = 1009 MB
sysctl_createv: sysctl_create(machine_arch) returned 17
kern.module.path=/stand/evbarm/7.99.1/modules
mainbus0 (root)
cpu0 at mainbus0 core 0: 1600 MHz Cortex-A9 r4p0 (Cortex V7A core)
cpu0: DC enabled IC enabled WB disabled EABT branch prediction enabled
cpu0: 32KB/32B 4-way L1 VIPT Instruction cache
cpu0: 32KB/32B 4-way write-back-locking-C L1 PIPT Data cache
cpu0: 64KB/32B 8-way write-through L2 PIPT Unified cache
vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN propagation, denormals
armperiph0 at mainbus0: mapping registers at 0x1013c000 size 12288 memh feb3c000
arml2cc0 at armperiph0: ARM PL310 r3p2 L2 Cache Controller (disabled)
arml2cc0: cache enabled
armgic0 at armperiph0: Generic Interrupt Controller, 160 sources (149 valid)
armgic0: 32 Priorities, 128 SPIs, 5 PPIs, 16 SGIs
a9tmr0 at armperiph0: A9 Global 64-bit Timer (800 MHz)
a9tmr0: interrupting on irq 27
a9wdt0 at armperiph0: A9 Watchdog Timer, default period is 12 seconds
obio0 at mainbus0: On-board I/O
grf iomux: old 00005554, new ffff5555, renew 00005555
grf iomux: old 00000000, new ffff0004, renew 00000004
grf iomux: old 00001000, new ffff1400, renew 00001400
gpio: 0x2000a000 0x00000100 -> 0x00000108
gpio: 0x2000a004 0x00000104 -> 0x0000010c
com0 at obio0: addr 0x20064000-0x200643ff intr 68  mult 4
: ns16550a, working fifo
com0: console
dwctwo0 at obio0: addr 0x10180000-0x101bffff intr 48  mult 1
: USB controller
dwctwo1 at obio0: addr 0x101c0000-0x101fffff intr 49  mult 1
: USB controller
usb0 at dwctwo0: USB revision 2.0
usb1 at dwctwo1: USB revision 2.0
uhub0 at usb0: vendor 0x0000 DWC2 root hub, class 9/0, rev 2.00/1.00, addr 1
uhub1 at usb1: vendor 0x0000 DWC2 root hub, class 9/0, rev 2.00/1.00, addr 1
uhub2 at uhub1 port 1: Genesys Logic USB2.0 Hub, class 9/0, rev 2.00/85.36, addr 2
uhub2: single transaction translator
ugen0 at uhub2 port 1
ugen0: Realtek 802.11n WLAN Adapter, rev 2.00/2.00, addr 3
urtwn0 at uhub2 port 3
urtwn0: GW-USValue-EZ GW-USValue-EZ, rev 2.00/2.00, addr 4
urtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R, address XX:XX:XX:XX:XX:XX
urtwn0: 1 rx pipe, 2 tx pipes
urtwn0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
urtwn0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
umass0 at uhub2 port 4 configuration 1 interface 0
umass0: SMI Corporation USB DISK, rev 2.00/11.00, addr 5
scsibus0 at umass0: 2 targets, 1 lun per target
sd0 at scsibus0 target 0 lun 0: <S31B0807, USB DISK, 1100> disk removable
sd0: 1983 MB, 3936 cyl, 16 head, 63 sec, 512 bytes/sect x 4061184 sectors
boot device: <unknown>
root device: sd0a
dump device (default sd0b):
file system (default generic): ffs
root on sd0a dumps on sd0b
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
warning: no /dev/console
init path (default /sbin/init):
init: copying out path `/sbin/init' 11
/etc/rc.conf is not configured.  Multiuser boot aborted.
Enter pathname of shell or RETURN for /bin/sh:
Terminal type is vt100.
We recommend that you create a non-root account and use su(1) for root access.
# uname -a
NetBSD  7.99.1 NetBSD 7.99.1 (RADXA) #204: Mon Nov 10 18:14:38 UTC 2014  root@aug:/usr/obj/sys/arch/evbarm/compile/RADXA evbarm
# mount
root_device on / type ffs (read-only, local)
tmpfs on /dev type tmpfs (union, local)
# mount /dev/sd0a /
/dev/sd0a: file system not clean (fs_clean=0x8); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
# ls
.cshrc    bin       lib       mnt       sbin      usr
.profile  dev       libdata   rescue    stand     var
altroot   etc       libexec   root      tmp
# ifconfig
urtwn0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
        ssid ""
        powersave off
        address: XX:XX:XX:XX:XX:XX
        media: IEEE802.11 autoselect
        status: no network
lo0: flags=8048<LOOPBACK,RUNNING,MULTICAST> mtu 33192
# dhclient urtwn0
# urtwn0: link state UP (was UNKNOWN)


# ifconfig
urtwn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        ssid XXXXXXXX
        powersave off
        bssid XX:XX:XX:XX:XX:XX chan 6
        address: XX:XX:XX:XX:XX:XX
        media: IEEE802.11 autoselect (OFDM54 mode 11g)
        status: active
        inet 192.168.43.193 netmask 0xffffff00 broadcast 192.168.43.255
lo0: flags=8048<LOOPBACK,RUNNING,MULTICAST> mtu 33192
# ping ki.nu
PING ki.nu (218.44.234.234): 64 data bytes
64 bytes from 218.44.234.234: icmp_seq=0 ttl=239 time=301.274847 ms
64 bytes from 218.44.234.234: icmp_seq=1 ttl=239 time=245.764923 ms
64 bytes from 218.44.234.234: icmp_seq=2 ttl=239 time=219.746549 ms
64 bytes from 218.44.234.234: icmp_seq=3 ttl=239 time=122.356646 ms
^C
----ki.nu PING Statistics----
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 122.356646/222.285741/301.274847/74.794880 ms
# 

NetBSD/evbarm on Radxa Rock USB編
2014/11/09(日) 24:29 NetBSD はてブ情報 はてブに登録 はてブ数

デバイスが認識される程度に動いたよ!

root hubから先に進まず悩んでいたのですが、ふかうみさんに4port usb hubの電源を入れないとダメというヒントが大きかったですー。

オンボードの無線LANチップがugenで見えています。
sd0として見えているのは2GBのUSBメモリです。NetBSD/evbarmのbase.tgz, etc.tgz, modules.tgzが展開されているのですが、root deviceとしてマウントしようとするも、あえなくpanicしております。
Loaded initial symtab at 0x8077e7e8, strtab at 0x807b32a8, # entries 13465
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 7.99.1 (RADXA) #194: Sun Nov  9 14:38:23 UTC 2014
        root@aug:/usr/obj/sys/arch/evbarm/compile/RADXA
total memory = 1024 MB
avail memory = 1009 MB
sysctl_createv: sysctl_create(machine_arch) returned 17
kern.module.path=/stand/evbarm/7.99.1/modules
mainbus0 (root)
cpu0 at mainbus0 core 0: 1600 MHz Cortex-A9 r4p0 (Cortex V7A core)
cpu0: DC enabled IC enabled WB disabled EABT branch prediction enabled
cpu0: 32KB/32B 4-way L1 VIPT Instruction cache
cpu0: 32KB/32B 4-way write-back-locking-C L1 PIPT Data cache
cpu0: 64KB/32B 8-way write-through L2 PIPT Unified cache
vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN propagation, denormals
armperiph0 at mainbus0: mapping registers at 0x1013c000 size 12288 memh feb3c000
arml2cc0 at armperiph0: ARM PL310 r3p2 L2 Cache Controller (disabled)
arml2cc0: cache enabled
armgic0 at armperiph0: Generic Interrupt Controller, 160 sources (149 valid)
armgic0: 32 Priorities, 128 SPIs, 5 PPIs, 16 SGIs
a9tmr0 at armperiph0: A9 Global 64-bit Timer (800 MHz)
a9tmr0: interrupting on irq 27
a9wdt0 at armperiph0: A9 Watchdog Timer, default period is 12 seconds
obio0 at mainbus0: On-board I/O
grf iomux: old 00005554, new ffff5555, renew 00005555
grf iomux: old 00000000, new ffff0004, renew 00000004
grf iomux: old 00001000, new ffff1400, renew 00001400
gpio: 0x2000a000 0x00000100 -> 0x00000108
gpio: 0x2000a004 0x00000104 -> 0x0000010c
com0 at obio0: addr 0x20064000-0x200643ff intr 68  mult 4
: ns16550a, working fifo
com0: console
dwctwo0 at obio0: addr 0x10180000-0x101bffff intr 48  mult 1
: USB controller
dwctwo1 at obio0: addr 0x101c0000-0x101fffff intr 49  mult 1
: USB controller
usb0 at dwctwo0: USB revision 2.0
usb1 at dwctwo1: USB revision 2.0
uhub0 at usb0: vendor 0x0000 DWC2 root hub, class 9/0, rev 2.00/1.00, addr 1
uhub1 at usb1: vendor 0x0000 DWC2 root hub, class 9/0, rev 2.00/1.00, addr 1
uhub2 at uhub1 port 1: Genesys Logic USB2.0 Hub, class 9/0, rev 2.00/85.36, addr 2
uhub2: single transaction translator
ugen0 at uhub2 port 1
ugen0: Realtek 802.11n WLAN Adapter, rev 2.00/2.00, addr 3
umass0 at uhub2 port 3 configuration 1 interface 0
umass0: SMI Corporation USB DISK, rev 2.00/11.00, addr 4
scsibus0 at umass0: 2 targets, 1 lun per target
sd0 at scsibus0 target 0 lun 0: <S31B0807, USB DISK, 1100> disk removable
sd0: 1983 MB, 3936 cyl, 16 head, 63 sec, 512 bytes/sect x 4061184 sectors
boot device: <unknown>
root device: sd0a
dump device (default sd0b):
file system (default generic):
root on sd0a dumps on sd0b
mountroot: trying ffs...
root file system type: ffs
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
Undefined instruction 0xdeadbeef in kernel at 0x80dfacb0 (LR 0x805db50c SP 0xbfd
c9c18)
Stopped in pid 1.1 (init) at    80dfacb0:       cdple   p14, 10, c11, c13, c15, 7

0xbfdc9ccc: netbsd:ufs_lookup+0x10
0xbfdc9d04: netbsd:VOP_LOOKUP+0xa0
0xbfdc9d54: netbsd:lookup_once+0x19c
0xbfdc9e24: netbsd:namei_tryemulroot+0x524
0xbfdc9e5c: netbsd:namei+0x34
0xbfdc9ebc: netbsd:nameiat_simple_kernel+0x64
0xbfdc9fac: netbsd:start_init+0x94
db>

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 『Have you seen this one: https://www.reddit.com/r/freebsd/comment...』 (2016/01/20 7:14)

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