Subject: NetBSD Mips port, Success story.
To: None <port-pmax@NetBSD.ORG>
From: Per Fogelstrom <pefo@enea.se>
List: port-pmax
Date: 12/10/1994 18:22:05
Hi everybody!

There have been much talk about the pmax port during the last days.
I'm not a pmax owner, have no funds, so i built my own system.
Porting NetBSD to it was quite stright forward so i don't recognize
all the problems you describe. Perhaps many of them arise from using
Ultrix as a porting plattform. :-> Or at least, using Ultrix C compiler
and tools is giving you problems.

Anyway i have a R3000 system running native without major problems.
This is the story how it was done. Maybe it can give you some ideas
or at least entertain you for a couple of minutes.


		HOW NetBSD WAS PORTED TO NEW HARDWARE
		=====================================

Building hardware is fun, but soner or later you come to the point where
you need software to do something meaningful.
So i started to look around. At work we had the BSD4.4 tapes and it included
a pmax port which was a good starting point. However BSD4.4 contain a few
licenced modules. To make this story short, NetBSD solved the issue.
A toolchain was needed to compile the code for my hardware and GNU was the
natural choise. Then i needed a porting plattform. So i had to dig the dungeon.
In my basement i had an old 68020 SYSVR3 un*x system which would do.

Next step was to create a cross development environment on the 68k system.
This was fairly easy, GCC runs on almost any system you might have.

I was now able to compile a NetBSD kernel from the pmax sources. After having
set up the include file hireachy the compile went through smoothly. Of course
i had no possibility to verify that it really worked. But as a starting point
for the rest of the work it could be considered as a milestone.

Then the time had come to start modifying and rewriting drivers for my own
system. I also had to create a bootstrap prom. Downloading and test took a
while because the only way i could download was via the serial port. Well,
after a few iterations (146 according to the version counter) the kernel was
working. At least until it tried mount the root disk.

Now the 'fun' part starts. Because i had no access to a BSD system i couldn't
create a file system on the hard disk. So i had to do it 'native'. The way
to do this was to hack "newfs" to run standalone with the bootprom hard disk
driver. Newfs was also hacked to create inodes for '/dev/console', '/dev/rz0a'
and "/dev/tz0". From this point i had a system which paniced because there
was no init process.

Next step was to create the rest of the system software. The tiresome process
of compiling all neccesary librarys was started. The libs was then installed
in the cross development system. It was now possible to cross compile the rest
of the system and create a distribution file system tree. Now how to download
the file system tree on the NetBSD disk? The file tree was "tared" out on a
streamer tape and i now had a 'system tape'. The problem to solve now was how
to get the tape down on the disk.

To load the tape to the NetBSD disk i needed a tar program that i could run
on the target system. To do this the kernel was hacked. The first hack was to
make the kernel mount the root disk r/w, open '/dev/tz0', copy the tape to a
file in the root directory, syncing the disks and then halt. What was there on
the tape then? Some of you might have guessed; a hacked :-) tar program. This
tar mounted the root disk, opened '/dev/console' and then started with options
'xvf /dev/tz0'. The kernel was hacked again to started this program instead
of init and downloaded. The 'distribution' tar tape was loaded, the hacked
kernel started and....  ta da da da, the tape was loaded to the hard disk.
Next step, reeboot with the downloaded kernel and viola, the system asked
for the shell to run!! I entered 'sh' and the '#' prompt showed up on the
terminal. Hurray!! It works, well almost. A few more things had to be fixed
in locore.s and the terminal driver.

>From this point the rest of the system was crosscompiled and the last thing
crosscompiled was the complete GNU toolchain. Next step was to recreate the
whole system native and the when this was done, the plug was pulled on the
old 68k system.

Of course it requiered a number of tries before the download succeded. But
what was most amazing was that the system programs, sh, init, almost all of
the just worked! My only misstake was that the system i built was big-endian.


To all of you who made it to here, hope you enjoyed the reading.

I would really like to help you guys to get NetBSD for the mips boxes
housebroken. Most of my spare time right now is spent on porting it to
a R4400 board i got recently. The kernel will of course be different but
the rest of the system would pretty much be the same as for the pmax.

One suggestion that i have, based on my own experience, is that someone
creates a pmax/Ultrix GCC environment that people who compiles kernels
can use and put it up for ftp. You can then stop using Ultrix tools.

I will not take up more of your time right now, but if anyone has some
ideas let me know if and how i can be of any help.


Regards

Per