APC8750にNetBSD/evbarmを移植するための記録 10/23
2014/02/14(金) 22:06 NetBSD はてブ情報 はてブに登録 はてブ数

ちょっと10日ほど冷却期間をおいて再開です。

currentのVMをつくって、そこで再開した。6.99.24であります。
ソースを更新したからって、先に進むなどという幸運はなく。

/sbin/initが
pid1072pid0wait for single-user shell failed: m; restartingpid1073pid0wait for single-user shell failed: m; restartingproc: table is full - increase kern.maxproc or NPROC
pid-1
などと言って果てていた件。

init.cを読んでみるとforkのところが怪しい。

forkのあと、pid==0ならという条件文をpid !=0と、変えてみるとpid0, pid2が動いていることがわかる。しかし、pid==0だとするとpid2だけしか動いていないように見える。

動いている場合も、下記のaccessより先にはいかない。

    678 	if ((pid = fork()) == 0) {
    679 		/*
    680 		 * Start the single user session.
    681 		 */
    682 		if (access(_PATH_CONSTTY, F_OK) == 0)
    683 			setctty(_PATH_CONSTTY);
    684 		else
    685 			setctty(_PATH_CONSOLE);
つまりsetcttyで引っかかっている(無限ループか無限待ちなど)ということ。

んで、setcttyを見てみると、関数の中で
    620 static void
    621 setctty(const char *name)
    622 {
    623 	int fd;
    624 
    625 	(void)revoke(name);
    626 	(void)nanosleep(&dtrtime, NULL);	/* leave DTR low for a bit */
    627 	if ((fd = open(name, O_RDWR)) == -1) {
    628 		stall("can't open %s: %m", name);
    629 		_exit(1);
    630 	}
    631 	if (login_tty(fd) == -1) {
    632 		stall("can't get %s for controlling terminal: %m", name);
    633 		_exit(2);
    634 	}
    635 }
むむ、nanosleepというのを使っているな。

なんか、そういえば、sleepを使うと止まってしまう事象に見舞われたはず。
いやちがう、wmt_com.cのattachでdelayを呼ぶと止まるのだった。
というか、delayとsleepは似たようなものだろうから、きっと呼ぶと止まるのだろう(いい加減だ)。

pid!=0のままsetcttyにコメントを入れて止まる場所を探してみる。
icu: establish_irq: is->is_irq=0x20
icu: establish_irq: is->is_irq=0x30
rn_init: radix functions require max_keylen be set
boot device: <unknown>
root on md0a dumps on md0b
mountroot: trying nfs...
mountroot: trying msdos...
mountroot: trying ffs...
root file system type: ffs
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
init: copying out flags `-s' 3
init: copying out path `/sbin/init' 11
init: pid = 2
init: access ret = 0
init: setctty consttyinit: revoke(name)
init: nanosleep()
init: pid = 0 start busy loop...
やっぱりだ。pid = 2の場合nanosleepまで実行して止まっている。一方、pid = 0はダミーで仕込んだビジーループを全力で回している。

臭いものにはフタということで、nanosleepを#if 0 - #endifで呼ばないようにしてみた。
icu: establish_irq: is->is_irq=0x30
rn_init: radix functions require max_keylen be set
boot device: <unknown>
root on md0a dumps on md0b
mountroot: trying nfs...
mountroot: trying msdos...
mountroot: trying ffs...
root file system type: ffs
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
init: copying out flags `-s' 3
init: copying out path `/sbin/init' 11
init: pid = 2
init: access ret = 0
init: setctty consttyinit: revoke(name)
init: nanosleep()
init: open()
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
erase ^?, werase ^W, kill ^U, intr ^C
wmtcom: ioctl
init: pid = 0 start busy loop...
おぉ、なんか先に進んでいるっぽい。wmtcomのioctlが呼ばれまくっている。中身が実装されていないのでデバック出力している。

が、pid = 2が先に進まない。ビジーループがだめなのかな。

よく考えたら、ビジーループだけにpid0が全力でCPUをつかんで離さないのではないかな? これをsleepなどにかえて、次のプロセスに処理を渡すようにしてやればいいんじゃ?

とりあえず、wmt_tmr.cのdelayにdelayが呼ばれたらデバッグプリントするように仕込むことにした。

なんか知らんが、pid==0の条件に戻して、ビジーループの中でsleepを入れたらsysinstが動いたぞ? これって、/bin/sh経由でうごいているはず。
wmtcom0 at obio0 addr 0xd8200000-0xd820ffff intr 32 : WMT UART
wmtcom:wmtcom_attach_subr 1-1
wmtcom0: console cn_tab->cn_dev=00007000
icu: establish_irq: is->is_irq=0x20
icu: establish_irq: is->is_irq=0x30
rn_init: radix functions require max_keylen be set
boot device: <unknown>
root on md0a dumps on md0b
mountroot: trying nfs...
mountroot: trying msdos...
mountroot: trying ffs...
root file system type: ffs
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
init: copying out flags `-s' 3
init: copying out path `/sbin/init' 11
init: pid = 2 start busy loop...
init: pid = 0
init: access ret = 0
init: setctty consttyinit: revoke(name)
init: nanosleep()
init: open()
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
erase ^?, werase ^W, kill ^U, intr ^C
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl

wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl
wmtcom: ioctl

wmtcom: ioctl




















































 NetBSD/evbarm 6.99.24

 This menu-driven tool is designed to help you install NetBSD to a hard disk,
 or upgrade an existing NetBSD system, with a minimum of work.
 In the following menus type the reference letter (a, b, c, ...) to select an
 item, or type CTRL+N/CTRL+P to select the next/previous item.
 The arrow keys and Page-up/Page-down may also work.
 Activate the current selection from the menu by typing the enter key.



                lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
                xwmtcom: ioctlion messages in English         x
                x b: Messages d'installation en fran軋is      x
                x c: Installation auf Deutsch                 x
                x d: Komunikaty instalacyjne w jezyku polskim x
                x e: Mensajes de instalacion en castellano    x
                mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
シリアルの入力を作れば、もしかするかもしれんぞ。

というか、ramdisk.fsの.profileでsysinstを呼ばないようにしたら、shellが上がってきそうな気がする。

distrib/evbarm/instkernel/ramdisk/dot.profileにls, df, sysctl -aなどと書いたらioctlのログを大量に吐きつつも、ちゃんと実行できるようになった。
わはは!

シリアルドライバの入力を作りたい気分が高まってきた。
冷却期間おいてよかった。

ps見られるとおもしろそうだと思って、ramdisk/listにpsを足してみたがエラーになる。
#      link  obj/ramdiskbin
/usr/src/obj/tooldir.NetBSD-6.99.24-amd64/bin/arm--netbsdelf-gcc    --sysroot=/usr/src/obj/destdir.evbarm   -static  -o ramdiskbin  ramdiskbin.o  -Wl,-rpath-link,/usr/src/obj/destdir.evbarm/lib  -L=/lib cat.cro chmod.cro cp.cro dd.cro df.cro ed.cro ln.cro ls.cro mkdir.cro mv.cro pax.cro ps.cro pwd.cro rm.cro rmdir.cro sh.cro stty.cro sync.cro chown.cro disklabel.cro drvctl.cro fdisk.cro fsck.cro fsck_msdos.cro fsck_ffs.cro gpt.cro ifconfig.cro init.cro mknod.cro mount.cro mount_cd9660.cro mount_ext2fs.cro mount_ffs.cro mount_kernfs.cro mount_msdos.cro mount_nfs.cro mount_tmpfs.cro newfs.cro newfs_ext2fs.cro ping.cro reboot.cro restore.cro route.cro shutdown.cro slattach.cro sysctl.cro swapctl.cro umount.cro ftp.cro tip.cro gzip.cro less.cro sed.cro tset.cro chroot.cro sysinst.cro progress.cro dhcpcd.cro  libhack.o -ledit -lutil -lcurses -lterminfo -lrmt -lcrypt -ll -lm -lz -lprop
ps.cro: In function `donlist$$from$$ps':
:(.text+0x734): undefined reference to `kvm_nlist'
:(.text+0x764): undefined reference to `kvm_read'
:(.text+0x778): undefined reference to `kvm_geterr'
:(.text+0x7a8): undefined reference to `kvm_read'
:(.text+0x7b8): undefined reference to `kvm_geterr'
:(.text+0x7ec): undefined reference to `kvm_read'
:(.text+0x7fc): undefined reference to `kvm_geterr'
:(.text+0x830): undefined reference to `kvm_read'
:(.text+0x840): undefined reference to `kvm_geterr'
ps.cro: In function `command$$from$$ps':
:(.text+0xdd8): undefined reference to `kvm_getenvv2'
:(.text+0xe44): undefined reference to `kvm_getargv2'
ps.cro: In function `_crunched_ps_stub':
:(.text+0x3620): undefined reference to `kvm_openfiles'
:(.text+0x364c): undefined reference to `kvm_openfiles'
:(.text+0x371c): undefined reference to `kvm_getproc2'
:(.text+0x3734): undefined reference to `kvm_geterr'
:(.text+0x37c0): undefined reference to `kvm_getlwps'
:(.text+0x3914): undefined reference to `kvm_getlwps'
collect2: ld returned 1 exit status
psがうごくと楽しそうなんだけどな。ちょっとそれは後にしよう。

勢いでシリアルコンソールのRX部分を実装してみました。

ISR, IERをとりちがえてしまったのとcomintrの中のRXの中でISRを読んでいる部分、最初はループ外で読んでいる奴を使いまわせばよい&ISRを読んでしまうとクリアされてしまうステータスがあるので読んじゃダメなんじゃ? と思っていたが実はそれは間違いで、ISRを呼ばないとループをちゃんと回せない(次の文字に進まない)ことがわかっぱー。

もろもろデバッグプリントを消したり、wmtcomのioctlを無言にしたりして、起動時をそれっぽく出せるようにしてみました。

はい! 来ました!
WMT # set serverip 192.168.0.10; tftpboot 8000; go 8000
EEP-less strapping = TRUE
*** Warning: no boot file name; using 'C0A80002.img'
TFTP from server 192.168.0.10; our IP address is 192.168.0.2
Filename 'C0A80002.img'.
Load address: 0x8000
Loading: #################################################################
         ###########################################T ######################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ################################T #################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ####################T #############################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################################################T ############
         #################################################################
         ##################
done
Bytes transferred = 6747520 (66f580 hex)
## Starting application at 0x00008000 ...
00008328
NetBSD
00000000 00000000 0088a74b 00000412
00000000 00000412 00000008 00000412
c0000000 00000000 0088a74b 0000041e
00003000 0000041e 00000008 0000041e
fe000000 d8000000 010fffff 00000412
00003f80 d8000412 00000010 00000412
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
NS
NetBSD/evbarm (APC) booting ...
initarm: Configuring system ...
arm32_bootmem_init: memstart=0, memsize=0x20000000, kernelstart=0x8000
arm32_bootmem_init: kernelend=0x68b000
arm32_bootmem_init: adding 129397 free pages: [0x68b000..0x1fffffff] (VA 0xc068b000)
arm32_bootmem_init: adding 8 free pages: [0..0x7fff] (VA 0xc0000000)
arm32_kernel_vm_init: 2 L2 pages are needed to map 0x6b6000 kernel bytes
arm32_kernel_vm_init: allocating page tables for vectoradd_pages: adding pv 0xc0677cac (pa 0x68b000, va 0xc068b000, 1 pages) at tail
 kerneladd_pages: appending pv 0xc06826ec (0x68c000..0x68ffff) to 0x68b000..0x68bfff
add_pages: appending pv 0xc0677f30 (0x690000..0x690fff) to 0x68b000..0x68ffff
add_pages: appending pv 0xc0677f44 (0x691000..0x691fff) to 0x68b000..0x690fff
 vmadd_pages: appending pv 0xc0677f58 (0x692000..0x692fff) to 0x68b000..0x691fff
add_pages: appending pv 0xc0677f6c (0x693000..0x693fff) to 0x68b000..0x692fff
add_pages: appending pv 0xc0677f80 (0x694000..0x694fff) to 0x68b000..0x693fff
add_pages: appending pv 0xc0677f94 (0x695000..0x695fff) to 0x68b000..0x694fff
add_pages: appending pv 0xc0677fa8 (0x696000..0x696fff) to 0x68b000..0x695fff
add_pages: appending pv 0xc0677fbc (0x697000..0x697fff) to 0x68b000..0x696fff
add_pages: appending pv 0xc0677fd0 (0x698000..0x698fff) to 0x68b000..0x697fff
add_pages: appending pv 0xc0677fe4 (0x699000..0x699fff) to 0x68b000..0x698fff
arm32_kernel_vm_init: allocating stacks
add_pages: appending pv 0xc0678230 (0x69a000..0x69afff) to 0x68b000..0x699fff
add_pages: appending pv 0xc0678244 (0x69b000..0x69bfff) to 0x68b000..0x69afff
add_pages: appending pv 0xc0678258 (0x69c000..0x69cfff) to 0x68b000..0x69bfff
add_pages: appending pv 0xc067826c (0x69d000..0x69dfff) to 0x68b000..0x69cfff
add_pages: appending pv 0xc0678280 (0x69e000..0x69ffff) to 0x68b000..0x69dfff
add_pages: appending pv 0xc067821c (0x6a0000..0x6a1fff) to 0x68b000..0x69ffff
add_pages: appending pv 0xc0677d24 (0x6a2000..0x6a5fff) to 0x68b000..0x6a1fff
Creating L1 page table at 0x0068c000
arm32_kernel_vm_init: adding L2 pt (VA 0xc068b000, PA 0x68b000) for VA 0xffff0000
 (vectors)arm32_kernel_vm_init: adding L2 pt (VA 0xc0690000, PA 0x690000) for VA 0xc0000000 (kernel)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0691000, PA 0x691000) for VA 0xc0400000 (kernel)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0692000, PA 0x692000) for VA 0xc1000000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0693000, PA 0x693000) for VA 0xc1400000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0694000, PA 0x694000) for VA 0xc1800000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0695000, PA 0x695000) for VA 0xc1c00000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0696000, PA 0x696000) for VA 0xc2000000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0697000, PA 0x697000) for VA 0xc2400000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0698000, PA 0x698000) for VA 0xc2800000 (vm)
arm32_kernel_vm_init: adding L2 pt (VA 0xc0699000, PA 0x699000) for VA 0xc2c00000 (vm)
Mapping kernel
arm32_kernel_vm_init: adding chunk for kernel text 0x8000..0x1cffff (VA 0xc0008000)
add_pages: adding pv 0xc0677c98 (pa 0x8000, va 0xc0008000, 456 pages) before pa 0x68b000
arm32_kernel_vm_init: adding chunk for kernel data/bss 0x1d0000..0x68afff (VA 0xc01d0000)
add_pages: appending pv 0xc0677cfc (0x1d0000..0x68afff) to 0x8000..0x1cffff
add_pages: merging pv 0xc0677cac (0x68b000..0x6a5fff) to 0x8000..0x68afff
Listing Chunks
arm32_kernel_vm_init: pv 0xc0677c98: chunk VA 0xc0008000..0xc06a5fff (PA 0x8000, prot 3, cache 1)

Mapping Chunks
arm32_kernel_vm_init: mapping last chunk VA 0xc0008000..0xc06a5fff (PA 0x8000, prot 3, cache 1)
pmap_map_chunk: pa=0x8000 va=0xc0008000 size=0x69e000 resid=0x69e000 prot=0x3 cache=1
PPPPPPPPLLLLLLLLLLLLLLLSSSSSLLLLLLLLLLPPPPPP
devmap: d8000000 -> d8ffffff @ fe000000
pmap_map_chunk: pa=0xd8000000 va=0xfe000000 size=0x1000000 resid=0x1000000 prot=0x3 cache=0
SSSSSSSSSSSSSSSS
                             Physical              Virtual        Num
                       Starting    Ending    Starting    Ending   Pages
               SDRAM: 0x00000000 0x1fffffff 0xc0000000 0xdfffffff 131072
        text section: 0x00008000 0x001cffff 0xc0008000 0xc01cffff 456
        data section: 0x001d0000 0x00677580 0xc01d0000 0xc0677580 1192
         bss section: 0x00677580 0x0068a74c 0xc0677580 0xc068a74c 20
   L1 page directory: 0x0068c000 0x0068ffff 0xc068c000 0xc068ffff 4
   ABT stack (CPU 0): 0x0069a000 0x0069afff 0xc069a000 0xc069afff 1
   FIQ stack (CPU 0): 0x0069b000 0x0069bfff 0xc069b000 0xc069bfff 1
   IRQ stack (CPU 0): 0x0069c000 0x0069cfff 0xc069c000 0xc069cfff 1
   UND stack (CPU 0): 0x0069d000 0x0069dfff 0xc069d000 0xc069dfff 1
  IDLE stack (CPU 0): 0x0069e000 0x0069ffff 0xc069e000 0xc069ffff 2
           SVC stack: 0x006a0000 0x006a1fff 0xc06a0000 0xc06a1fff 2
      Message Buffer: 0x006a2000 0x006a5fff 0xc06a2000 0xc06a5fff 4
   Exception Vectors: 0x006a6000 0x006a6fff 0xffff0000 0xffff0fff 1
         Free Memory: 0x006a7000 0x1fffffff                       129369
         Free Memory: 0x00000000 0x00007fff                       8
switching to new L1 page table @0x68c000...TTBR0=0x68c000 OK
done.
nfreeblocks = 2, free_pages = 129377 (0x1f961)
bootstrap done.
vectors 0xffff0000
init subsystems: stacks vectors undefined page pmap_physload pmap [ Kernel symbol table missing! ]
done.
Loaded initial symtab at 0xc01d4360, strtab at 0xc01f42a0, # entries 8165
pmap_postinit: Allocated 35 static L1 descriptor tables
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
    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 6.99.24 (APC) #5: Thu Oct 24 17:27:18 UTC 2013
        root@oct.localdomain:/usr/obj/sys/arch/evbarm/compile/APC
total memory = 512 MB
avail memory = 495 MB
sysctl_createv: sysctl_create(machine_arch) returned 17
mainbus0 (root)
cpu0 at mainbus0 core 0: ARM1176JZ-S r0p7 (ARM11J V6ZK core)
cpu0: DC enabled IC enabled WB enabled LABT
cpu0: 16KB/32B 4-way L1 Instruction cache
cpu0: 16KB/32B 4-way write-back-locking-C L1 Data cache
vfp0 at cpu0: VFP11
obio0 at mainbus0
wmicu0 at obio0 addr 0xd8140000-0xd814ffff
wmtmr0 at obio0 addr 0xd8100000-0xd810ffff intr 48 : WMT System Timer
wmtcom0 at obio0 addr 0xd8200000-0xd820ffff intr 32 : WMT UART
rn_init: radix functions require max_keylen be set
boot device: <unknown>
root on md0a dumps on md0b
mountroot: trying nfs...
mountroot: trying msdos...
mountroot: trying ffs...
root file system type: ffs
WARNING: no TOD clock present
WARNING: using filesystem time
WARNING: CHECK AND RESET THE DATE!
init: copying out flags `-s' 3
init: copying out path `/sbin/init' 11
erase ^?, werase ^W, kill ^U, intr ^C

# ls /
.profile        kern            sbin            sysinstmsgs.fr  usr
bin             libexec         sysinst         sysinstmsgs.pl  var
dev             mnt             sysinstmsgs.de  targetroot
etc             mnt2            sysinstmsgs.es  tmp
# ls /usr/sbin
chroot
# ls /usr/bin
cu        gunzip    gzip      more      sed       tip
ftp       gzcat     less      progress  tar       tset
# ls /bin
cat   chmod dd    ed    ls    mv    pwd   rmdir stty
chgrp cp    df    ln    mkdir pax   rm    sh    sync
# echo hello > /foo.txt
# cat /foo.txt
hello
#
いろいろ手抜きしてますが、ちゃんと、入力してその反応を得ることができています。OSが動いてるっぽいように見えるレベルまで来ました。

ここまで来られるとは思ってもいなかったので、すなおにうれしい。

名前:  非公開コメント   

  • TB-URL  http://www.tokuda.net/diary/adiary.cgi/0841/tb/