[ECOS] Loading linux image through redboot.

Ian Campbell icampbell@arcomcontrols.com
Fri Oct 11 04:25:00 GMT 2002


>         Is it possible to load linux image for x86 system through redboot.If
> it is possible then at which location the setup code and system code must be
> loaded and whether it     
>         requires change in source code ?

I solved this problem by stripping the setup code from the start of the
linux image and booting that directly in protected mode. It's a bit of a
hack, but I was able to make it work.

1) Create raw image without the realmode header. This corresponds to
arch/i386/boot/compressed/bvmlinux.out

	dd if=bzImage of=kernel bs=1024 skip=3

2) Load the file 'kernel' onto the board at 0x100000 using whatever
method you choose.

3) Build the attached .c and .S into RedBoot. Note that these have been
stripped down to the basics removing some device specific stuff. They
are completely untested (not even built), although the non-stripped down
version works for my application. You may need to tweak them. If so you
should read the kernel docs carefully. Especially
Documentation/i386/boot.txt. Also read the the source for the real mode
part, in particular arch/i386/boot/setup.S.

The .c file attempts to setup the same environment as the real mode
header in linux does. The .S part then resets the GDT to match linux and
begins executing the code.

Perhaps someone would like to massage into something suitable for the
generic i386 arch directory, unfortunately I don't have time right at
the minute.

Cheers,
Ian.
-- 
Ian Campbell
Design Engineer

Arcom Control Systems Ltd,
Clifton Road,
Cambridge CB1 7EA
United Kingdom

Tel: +44 (0)1223 403465
E-Mail: icampbell@arcomcontrols.com
Web: http://www.arcomcontrols.com


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linuxexec.c
Type: text/x-c
Size: 2674 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/ecos-discuss/attachments/20021011/5532addc/attachment.bin>
-------------- next part --------------
#define FUNC_START(name)                        \
        .globl name;                            \
name:   

#define __KERNEL_DS	0x18
#define __KERNEL_CS	0x10
	
FUNC_START(do_linux_boot)
	cli					# no interrupts allowed !
	
	movb	$0x80, %al			# disable NMI for bootup
	outb	%al, $0x70			# sequence

	movw	$0xfffc, %dx			# Disable MMCR Shadow.
	movl	$0, %eax
	outl	%eax, %dx

	# Copy GDT to RAM at 0x90400
	movl	$(linux_gdt_end - linux_gdt), %ecx # Length
	shrl	$2, %ecx               # Bytes -> Longs
	leal	linux_gdt, %eax	   # Source
	movl	%eax, %esi
	movl	$(0x90400), %edi  # Dest
1:	
	lodsl	
	stosl
	loop	1b

	# Create a GDT descriptior at 0 and load it
	movl	$0x90000, %esi
	movw	$(linux_gdt_end - linux_gdt),%ax
        dec     %ax
	movw	%ax,0
	movl	$0x90400,%eax
	movl	%eax,2
	lgdt	0

	# Reload segment registers
	mov	$(__KERNEL_DS), %eax
	movl 	%eax, %ds
	movl 	%eax, %es
	movl 	%eax, %fs
	movl 	%eax, %gs

	# Start kernel
	ljmp	$(__KERNEL_CS), $0x100000
	ret

	.ALIGN 4, 0xCC

# Descriptor tables
linux_gdt:
	.word	0, 0, 0, 0			# dummy
	.word	0, 0, 0, 0			# unused

	.word	0xFFFF				# 4Gb - (0x100000*0x1000 = 4Gb)
	.word	0				# base address = 0
	.word	0x9A00				# code read/exec
	.word	0x00CF				# granularity = 4096, 386
						#  (+5th nibble of limit)

	.word	0xFFFF				# 4Gb - (0x100000*0x1000 = 4Gb)
	.word	0				# base address = 0
	.word	0x9200				# data read/write
	.word	0x00CF				# granularity = 4096, 386
						#  (+5th nibble of limit)
linux_gdt_end:

-------------- next part --------------
-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


More information about the Ecos-discuss mailing list