--- /var/www/www.edgebsd.org/wiki/port-lm32 2014/02/25 10:54:28 1.5
+++ /var/www/www.edgebsd.org/wiki/port-lm32 2014/09/13 18:55:38 1.6
@@ -1,28 +1,128 @@
-<h3>Build instructions</h3>
-<p>How to build EdgeBSD/lm32:</p>
-<ul><li>Fetch the source: <pre>$ git clone http://git.edgebsd.org/EdgeBSD/edgebsd-src.git</pre></li>
-<li>Go to my branch: <pre>$ cd edgebsd-src && git checkout fallen-port-milkymist</pre></li>
-<li>Build the lm32 cross toolchain: <pre>$ ./build.sh -m milkymist -U tools</pre></li>
-<li>Build EdgeBSD kernel: <pre>$ ./build.sh -m milkymist -U kernel=GENERIC</pre></li></ul>
-
-<p>Note, if you are rebuilding after a modification or a <tt>git pull</tt>, this is faster: </p><pre>$ ./build.sh -m milkymist -U -u kernel=GENERIC</pre><p></p>
-
-
-<h3>Test instructions</h3>
-
-<p>Build Qemu for Milkymist SoC with support for lm32-mmu:</p>
-<pre>$ git clone https://github.com/fallen/qemu.git
-$ cd qemu
-$ ./configure --target-list=lm32-softmmu</pre><pre>$ make</pre><pre>Or, if you're on BSD:
-$ gmake</pre>
-
-<p>Run EdgeBSD/lm32 in qemu:</p>
-<pre>$ ./lm32-softmmu/qemu-system-lm32 -M milkymist -cpu lm32-full-mmu -nographic -kernel /path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd</pre>
-
-
-<p>Debug with Qemu and GDB:</p>
-<ul><li>Build EdgeBSD kernel with debug information: <pre>$ DEBUG=-g ./build.sh -m milkymist -U kernel=GENERIC
-$ ./lm32-softmmu/qemu-system-lm32 -M milkymist -cpu lm32-full-mmu -nographic -s -S -kernel /path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd.gdb
-$ gdb -x /path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/.gdbinit /path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd.gdb</pre>
-and then inside gdb: <pre> target remote :1234</pre>
-</li></ul>
\ No newline at end of file
+
+<h1>NetBSD|EdgeBSD/lm32</h1>
+
+<p>
+What it does so far:
+</p><ul><li>
+ Boots the kernel all the way up to mounting rootfs from ramdisk
+</li><li>
+ Loads /sbin/init from the ramdisk and starts executing it in user space
+</li><li>
+ /sbin/init executes entirely, it contains 3 open() and 1 write() syscalls
+</li><ul><li>
+ init opens /dev/console 3 times (stdin, stdout, stderr) and writes "hello, world!" to stdout which shows up in the uart console
+</li></ul><li>
+ Then init "returns to 0x0" and crashes the machine
+</li></ul>
+
+
+<p>
+How to build EdgeBSD/lm32:
+
+</p><ul><li>
+ Fetch the source: <i>git clone http://git.edgebsd.org/EdgeBSD/edgebsd-src.git</i>
+</li><li>
+ Go to my branch: <i>cd edgebsd-src && git checkout fallen-port-milkymist</i>
+</li><li>
+ Fetch the submodule (init_src): <i>git submodule update --init</i>
+</li><li>
+ Build the lm32 cross toolchain: <i>./build.sh -m milkymist -U tools</i>
+</li><li>
+ Build EdgeBSD kernel: <i>./build.sh -m milkymist -U kernel=GENERIC</i>
+</li></ul>
+
+Note, if you are rebuilding after a modification or a git pull, this is faster: <i>./build.sh -m milkymist -U -u kernel=GENERIC</i>
+
+
+
+<p>
+Run EdgeBSD/lm32 in qemu:
+
+</p><ul><li>
+ <i>./lm32-softmmu/qemu-system-lm32 -M milkymist -cpu lm32-full-mmu
+-nographic -kernel
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd</i>
+</li></ul>
+
+
+<p>
+Build Qemu for Milkymist SoC with support for lm32-mmu:
+</p><ul><li>
+ <i>git clone https://github.com/fallen/qemu.git && cd qemu
+&& ./configure --target-list=lm32-softmmu && make</i>
+</li></ul>
+
+
+<p>
+Debug with Qemu and GDB:
+</p><ul><li>
+ Build EdgeBSD kernel with debug information: <i>DEBUG=-g ./build.sh -m milkymist -U kernel=GENERIC</i>
+</li><li>
+ <i>./lm32-softmmu/qemu-system-lm32 -M milkymist -cpu lm32-full-mmu
+-nographic -s -S -kernel
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd.gdb</i>
+</li><li>
+ <i>gdb -x
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/.gdbinit
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/netbsd.gdb</i>
+</li><li>
+ (inside gdb) target remote :1234
+</li></ul>
+
+
+<p>
+Embed a ramdisk (MFS : memory file system) inside the kernel with a simple static init binary:
+</p>
+
+<ul><li>
+ Build EdgeBSD kernel with MFS support: <i>DEBUG=-g ./build.sh -m milkymist -U kernel=GENERIC_MFS</i>
+</li><li>
+ Build init binary: <i>make -C init_src</i>
+ <ul><li>
+ Beware, if you are not under Mac OS X you need to tell the makefile
+where your lm32 crosstoolchain is by prefixing the previous command
+with: TOOLCHAIN_DIR=$PWD/obj/tooldir.NetBSD-7.0-i386/
+ </li></ul>
+</li><li>
+ Install init binary inside the kernel image: <i>debug=1 make -C init_src install</i>
+ <ul><li>
+ you still need the TOOLCHAIN_DIR variable if not under OS X
+ </li><li>
+ you will need to enter your SUDO password
+ </li></ul>
+</li><li>
+ Run the kernel with Qemu and wait for GDB to attach: <i>./lm32-softmmu/qemu-system-lm32
+ -M milkymist -cpu lm32-full-mmu -nographic -kernel
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC_MFS/netbsd.gdb
+ -s -S</i>
+</li><li>
+ Attach GDB: <i>gdb -x
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC/.gdbinit
+/path/to/edgebsd-src/sys/arch/milkymist/compile/obj/GENERIC_MFS/netbsd.gdb</i>
+</li><li>
+ Inside GDB:
+ <ul><li>
+ (gdb) target remote :1234
+ </li><li>
+ 0x10000000 is the virtual address where init binary gets loaded (you can inspect the binary with readelf)<br/>
+ (gdb) break *0x10000000
+ </li><li>
+ (gdb) continue
+ </li><li>
+ 0x47eb4000 is the physical address where init binary gets loaded in RAM<br/>
+ (gdb) x/10i 0x47eb4000
+ </li><li>
+ Then you can single step using "si" and see the registers changing
+values according to the instructions you printed at the previous step
+ </li><li>
+ (gdb) break syscall<br/>
+ (gdb) continue
+ </li><li>
+ So far the init program will do 3 open("/dev/console") and one
+write(0, "hello, world\n", 12), you can break on sys_open and sys_write
+to catch them or just single step from the break to syscall
+ </li></ul>
+</li></ul>
+
+
+