Zbr's days.
May
Sun Mon Tue Wed Thu Fri Sat
   
28    
2007
Months
May

About TODO Blog RSS Old blog Projects Gallery Notes

Mon, 28 May 2007

Sector reading code.


Ok, I've written a code which resides in MBR and reads a sector into the RAM and jumps there, but it only works if I read the same zero sector - I get recursive call of the same .start routine, which prints "Starting from MBR" to the serial console, but if I change source address, system freezes. Likely this is because of wrong sector->LBA translation (I need second or third sector, but I must provide an LBA address), at least if I blindly use 2 for the third sector, it reads something different than third sector. SuperH LILO source I have use some tricky asm to convert from one system to another, which I do not yet understand, and it also uses some strange constants (likely hardcoded address of the second stage loader), so it is not very useful source of information.
Thinking...

/devel/sh :: Link / Comments (0)


I know kung-fu or how to write your own bootlaoder.


I never did that before, so it is completely new task for me.
My testing system is SuperH board, which already has initial bootloader, which jumps into MBR of the compact flash for execution. I found LILO port for SuperH CPU, but it does not work (and all documentation is in japanese, and google can not translate that page), which required very old LILO versions, since recent ones (22 and higher) just write x86 boot sector into MBR no matter what you ask it to do (i.e. what boot.b is being used). So obvious step from my point of view is to write own bootloader.
"How is it supposed to work?" - I asked myself and found an answer - it will be pretty small stuff without several stages like in LILO or GRUB, my bootloader will just read fixed size Linux kernel image from fixed offset into memory and jump into it, it is quite simple task since the whole initialization and helper code is already written and stored on the NAND flash in IPL (Initial Program Loader).
My code, which starts from MBR and prints greeting message into serial port for that board is very simple (not including initialization of the base registers):

	mova	message, r0
	mov	r0, r4
	mov	#17, r5
	mov	#0, r0
	trapa	#0x3f
SuperH asm is a bit fun sometimes compared to x86 and ppc (small) bits I know.
It is so simple because of IPL-SH code running from the NAND flash (Initial Program Loader), which handles exceptions (trapa traps an execption). Read sector calls (very similar to x86 BIOS ones) are handled exacltly the same way in LILO port.
I will start with reading and running simple code from Compact Flash, and then will move tothe real kernel.

Because of this hacks I have not moved to climbing area today, which is quite a bit of crap, but I could not resist...

/devel/sh :: Link / Comments (0)


OpenBSD c2k7 hackathon. Day two.


BBQ day or playing "shake and suck" as Grange describes - this is a game where each player (can be infinite number) gets a bottle of some crappy beer and starts to shake it trying to suck at least something. There is no winner, but everyone becomes filled with beer and very happy.
BBQ was cooked (as expected) by Bob Beck (This time without "Will cook for sex" motto on the apron).

One can check second day photos.

/devel/other :: Link / Comments (0)


My first boot on SuperH CPU.


Serial console output:

SH IPL+g version 0.9, Copyright (C) 2000 Free Software Foundation, Inc.

This software comes with ABSOLUTELY NO WARRANTY; for details type `w'.
This is free software, and you are welcome to redistribute it under
certain conditions; type `l' for details.

2002/09/09 Making.  2004/09/08 I-O DATA NSU Update.
266:133:33 on base clock 22.22MHz and SDRAM 4 burst. CF boot.

PCIC initialization done.
MASTER:48bit LBA mode non support
Disk drive detected: LEXAR ATA FLASH V1.00 11014102039199095066 
LBA: 001EBF10
DiskSize: 1031675904Byte
PIO MODE1
Set Transfer Mode result: 50 
> b
Set Transfer Mode result: 50 
Initialize Device Parameters result: 50 
IDLE result: 50 
I'm booting from MBR!
Check the last line.
Actually it is not a Linux kernel, it is not LILO, it just a code from first stage of the LILO loader slightly hacked and moved into MBR sector of the Compact flash. Initial loader (everything above the last line) is something from NAND flash soldered to the board and likely flashed on the factory.
I'm currently studing why LILO does not work (actually it does not even write MBR record, so I needed to flash it by hand using dd) and how it is supposed to work (bootloaders were always some kind of a magic for me).

/devel/sh :: Link / Comments (0)


Do you know that Einstein was offered to become an Israeli president in 1952?

/other :: Link / Comments (0)


More OpenBSD c2k7 hackathon photos.


Here.

/devel/other :: Link / Comments (0)