Compare commits
12
Commits
v1.0.0-rc1
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53e9fb50d2 | ||
|
|
26f882bf64 | ||
|
|
00a780e38f | ||
|
|
1548189ffa | ||
|
|
e501e6e19e | ||
|
|
1056a1c2d5 | ||
|
|
9a89f0d17d | ||
|
|
ddcf2d5f08 | ||
|
|
d3b9c3f3d0 | ||
|
|
f3467ad169 | ||
|
|
e6f08b0aa7 | ||
|
|
329c7b78e3 |
+1
-2
@@ -54,7 +54,6 @@ BFD_DIR := $(BINUTILS_DIR)
|
|||||||
SRCDIRS :=
|
SRCDIRS :=
|
||||||
SRCDIRS += libgcc
|
SRCDIRS += libgcc
|
||||||
SRCDIRS += core
|
SRCDIRS += core
|
||||||
SRCDIRS += proto
|
|
||||||
SRCDIRS += net net/tcp net/udp net/infiniband net/80211
|
SRCDIRS += net net/tcp net/udp net/infiniband net/80211
|
||||||
SRCDIRS += image
|
SRCDIRS += image
|
||||||
SRCDIRS += drivers/bus
|
SRCDIRS += drivers/bus
|
||||||
@@ -131,7 +130,7 @@ install :
|
|||||||
VERSION_MAJOR = 1
|
VERSION_MAJOR = 1
|
||||||
VERSION_MINOR = 0
|
VERSION_MINOR = 0
|
||||||
VERSION_PATCH = 0
|
VERSION_PATCH = 0
|
||||||
EXTRAVERSION = -rc1
|
EXTRAVERSION =
|
||||||
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
||||||
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
|
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
|
||||||
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
|
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
|
||||||
|
|||||||
@@ -16,18 +16,11 @@ MEDIA += xrom
|
|||||||
MEDIA += pxe
|
MEDIA += pxe
|
||||||
MEDIA += kpxe
|
MEDIA += kpxe
|
||||||
MEDIA += kkpxe
|
MEDIA += kkpxe
|
||||||
MEDIA += elf
|
|
||||||
MEDIA += elfd
|
|
||||||
MEDIA += lmelf
|
|
||||||
MEDIA += lmelfd
|
|
||||||
MEDIA += lkrn
|
MEDIA += lkrn
|
||||||
MEDIA += bImage
|
|
||||||
MEDIA += dsk
|
MEDIA += dsk
|
||||||
MEDIA += nbi
|
MEDIA += nbi
|
||||||
MEDIA += hd
|
MEDIA += hd
|
||||||
MEDIA += raw
|
MEDIA += raw
|
||||||
MEDIA += com
|
|
||||||
MEDIA += exe
|
|
||||||
|
|
||||||
# Padding rules
|
# Padding rules
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,611 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2000, Entity Cyber, Inc.
|
|
||||||
|
|
||||||
Authors: Gary Byers (gb@thinguin.org)
|
|
||||||
Marty Connor (mdc@thinguin.org)
|
|
||||||
Eric Biederman (ebiederman@lnxi.com)
|
|
||||||
|
|
||||||
This code also derives a lot from arch/i386/boot/setup.S in
|
|
||||||
the linux kernel.
|
|
||||||
|
|
||||||
This software may be used and distributed according to the terms
|
|
||||||
of the GNU Public License (GPL), incorporated herein by reference.
|
|
||||||
|
|
||||||
Description:
|
|
||||||
|
|
||||||
This is just a little bit of code and data that can get prepended
|
|
||||||
to an Etherboot ROM image in order to allow LILO to load the
|
|
||||||
result as if it were a Linux kernel image.
|
|
||||||
|
|
||||||
A real Linux kernel image consists of a one-sector boot loader
|
|
||||||
(to load the image from a floppy disk), followed a few sectors
|
|
||||||
of setup code, followed by the kernel code itself. There's
|
|
||||||
a table in the first sector (starting at offset 497) that indicates
|
|
||||||
how many sectors of setup code follow the first sector and which
|
|
||||||
contains some other parameters that aren't interesting in this
|
|
||||||
case.
|
|
||||||
|
|
||||||
When LILO loads the sectors that comprise a kernel image, it doesn't
|
|
||||||
execute the code in the first sector (since that code would try to
|
|
||||||
load the image from a floppy disk.) The code in the first sector
|
|
||||||
below doesn't expect to get executed (and prints an error message
|
|
||||||
if it ever -is- executed.) LILO's only interested in knowing the
|
|
||||||
number of setup sectors advertised in the table (at offset 497 in
|
|
||||||
the first sector.)
|
|
||||||
|
|
||||||
Etherboot doesn't require much in the way of setup code.
|
|
||||||
Historically, the Linux kernel required at least 4 sectors of
|
|
||||||
setup code. Current versions of LILO look at the byte at
|
|
||||||
offset 497 in the first sector to indicate how many sectors
|
|
||||||
of setup code are contained in the image.
|
|
||||||
|
|
||||||
The setup code that is present here does a lot of things
|
|
||||||
exactly the way the linux kernel does them instead of in
|
|
||||||
ways more typical of etherboot. Generally this is so
|
|
||||||
the code can be strongly compatible with the linux kernel.
|
|
||||||
In addition the general etherboot technique of enabling the a20
|
|
||||||
after we switch into protected mode does not work if etherboot
|
|
||||||
is being loaded at 1MB.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.equ CR0_PE,1
|
|
||||||
|
|
||||||
#ifdef GAS291
|
|
||||||
#define DATA32 data32;
|
|
||||||
#define ADDR32 addr32;
|
|
||||||
#define LJMPI(x) ljmp x
|
|
||||||
#else
|
|
||||||
#define DATA32 data32
|
|
||||||
#define ADDR32 addr32
|
|
||||||
/* newer GAS295 require #define LJMPI(x) ljmp *x */
|
|
||||||
#define LJMPI(x) ljmp x
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Simple and small GDT entries for booting only */
|
|
||||||
#define GDT_ENTRY_BOOT_CS 2
|
|
||||||
#define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1)
|
|
||||||
#define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8)
|
|
||||||
#define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8)
|
|
||||||
|
|
||||||
|
|
||||||
#define SETUPSECS 4 /* Minimal nr of setup-sectors */
|
|
||||||
#define PREFIXSIZE ((SETUPSECS+1)*512)
|
|
||||||
#define PREFIXPGH (PREFIXSIZE / 16 )
|
|
||||||
#define BOOTSEG 0x07C0 /* original address of boot-sector */
|
|
||||||
#define INITSEG 0x9000 /* we move boot here - out of the way */
|
|
||||||
#define SETUPSEG 0x9020 /* setup starts here */
|
|
||||||
#define SYSSEG 0x1000 /* system loaded at 0x10000 (65536). */
|
|
||||||
|
|
||||||
#define DELTA_INITSEG (SETUPSEG - INITSEG) /* 0x0020 */
|
|
||||||
|
|
||||||
/* Signature words to ensure LILO loaded us right */
|
|
||||||
#define SIG1 0xAA55
|
|
||||||
#define SIG2 0x5A5A
|
|
||||||
|
|
||||||
.text
|
|
||||||
.code16
|
|
||||||
.arch i386
|
|
||||||
.org 0
|
|
||||||
.section ".prefix", "ax", @progbits
|
|
||||||
_prefix:
|
|
||||||
|
|
||||||
/*
|
|
||||||
This is a minimal boot sector. If anyone tries to execute it (e.g., if
|
|
||||||
a .lkrn file is dd'ed to a floppy), print an error message.
|
|
||||||
*/
|
|
||||||
|
|
||||||
bootsector:
|
|
||||||
jmp $BOOTSEG, $go - _prefix /* reload cs:ip to match relocation addr */
|
|
||||||
go:
|
|
||||||
movw $0x2000, %di /* 0x2000 is arbitrary value >= length
|
|
||||||
of bootsect + room for stack */
|
|
||||||
|
|
||||||
movw $BOOTSEG, %ax
|
|
||||||
movw %ax,%ds
|
|
||||||
movw %ax,%es
|
|
||||||
|
|
||||||
cli
|
|
||||||
movw %ax, %ss /* put stack at BOOTSEG:0x2000. */
|
|
||||||
movw %di,%sp
|
|
||||||
sti
|
|
||||||
|
|
||||||
movw $why_end-why, %cx
|
|
||||||
movw $why - _prefix, %si
|
|
||||||
|
|
||||||
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
|
|
||||||
movb $0x0e, %ah /* write char, tty mode */
|
|
||||||
prloop:
|
|
||||||
lodsb
|
|
||||||
int $0x10
|
|
||||||
loop prloop
|
|
||||||
freeze: jmp freeze
|
|
||||||
|
|
||||||
why: .ascii "This image cannot be loaded from a floppy disk.\r\n"
|
|
||||||
why_end:
|
|
||||||
|
|
||||||
|
|
||||||
.org 497
|
|
||||||
setup_sects:
|
|
||||||
.byte SETUPSECS
|
|
||||||
root_flags:
|
|
||||||
.word 0
|
|
||||||
syssize:
|
|
||||||
.word _verbatim_size_pgh - PREFIXPGH
|
|
||||||
swap_dev:
|
|
||||||
.word 0
|
|
||||||
ram_size:
|
|
||||||
.word 0
|
|
||||||
vid_mode:
|
|
||||||
.word 0
|
|
||||||
root_dev:
|
|
||||||
.word 0
|
|
||||||
boot_flag:
|
|
||||||
.word 0xAA55
|
|
||||||
|
|
||||||
/*
|
|
||||||
We're now at the beginning of the second sector of the image -
|
|
||||||
where the setup code goes.
|
|
||||||
|
|
||||||
We don't need to do too much setup for Etherboot.
|
|
||||||
|
|
||||||
This code gets loaded at SETUPSEG:0. It wants to start
|
|
||||||
executing the Etherboot image that's loaded at SYSSEG:0 and
|
|
||||||
whose entry point is SYSSEG:0.
|
|
||||||
*/
|
|
||||||
setup_code:
|
|
||||||
jmp trampoline
|
|
||||||
# This is the setup header, and it must start at %cs:2 (old 0x9020:2)
|
|
||||||
|
|
||||||
.ascii "HdrS" # header signature
|
|
||||||
.word 0x0203 # header version number (>= 0x0105)
|
|
||||||
# or else old loadlin-1.5 will fail)
|
|
||||||
realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
|
|
||||||
start_sys_seg: .word SYSSEG # low load segment (obsolete)
|
|
||||||
.word kernel_version - setup_code
|
|
||||||
# pointing to kernel version string
|
|
||||||
# above section of header is compatible
|
|
||||||
# with loadlin-1.5 (header v1.5). Don't
|
|
||||||
# change it.
|
|
||||||
|
|
||||||
type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
|
|
||||||
# Bootlin, SYSLX, bootsect...)
|
|
||||||
# See Documentation/i386/boot.txt for
|
|
||||||
# assigned ids
|
|
||||||
|
|
||||||
# flags, unused bits must be zero (RFU) bit within loadflags
|
|
||||||
loadflags:
|
|
||||||
LOADED_HIGH = 1 # If set, the kernel is loaded high
|
|
||||||
CAN_USE_HEAP = 0x80 # If set, the loader also has set
|
|
||||||
# heap_end_ptr to tell how much
|
|
||||||
# space behind setup.S can be used for
|
|
||||||
# heap purposes.
|
|
||||||
# Only the loader knows what is free
|
|
||||||
.byte LOADED_HIGH
|
|
||||||
|
|
||||||
setup_move_size: .word 0x8000 # size to move, when setup is not
|
|
||||||
# loaded at 0x90000. We will move setup
|
|
||||||
# to 0x90000 then just before jumping
|
|
||||||
# into the kernel. However, only the
|
|
||||||
# loader knows how much data behind
|
|
||||||
# us also needs to be loaded.
|
|
||||||
|
|
||||||
code32_start: # here loaders can put a different
|
|
||||||
# start address for 32-bit code.
|
|
||||||
.long 0x100000 # 0x100000 = default for big kernel
|
|
||||||
|
|
||||||
ramdisk_image: .long 0 # address of loaded ramdisk image
|
|
||||||
# Here the loader puts the 32-bit
|
|
||||||
# address where it loaded the image.
|
|
||||||
# This only will be read by the kernel.
|
|
||||||
|
|
||||||
ramdisk_size: .long 0 # its size in bytes
|
|
||||||
|
|
||||||
bootsect_kludge:
|
|
||||||
.long 0 # obsolete
|
|
||||||
|
|
||||||
heap_end_ptr: .word 0 # (Header version 0x0201 or later)
|
|
||||||
# space from here (exclusive) down to
|
|
||||||
# end of setup code can be used by setup
|
|
||||||
# for local heap purposes.
|
|
||||||
|
|
||||||
pad1: .word 0
|
|
||||||
cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
|
|
||||||
# If nonzero, a 32-bit pointer
|
|
||||||
# to the kernel command line.
|
|
||||||
# The command line should be
|
|
||||||
# located between the start of
|
|
||||||
# setup and the end of low
|
|
||||||
# memory (0xa0000), or it may
|
|
||||||
# get overwritten before it
|
|
||||||
# gets read. If this field is
|
|
||||||
# used, there is no longer
|
|
||||||
# anything magical about the
|
|
||||||
# 0x90000 segment; the setup
|
|
||||||
# can be located anywhere in
|
|
||||||
# low memory 0x10000 or higher.
|
|
||||||
|
|
||||||
ramdisk_max: .long 0 # (Header version 0x0203 or later)
|
|
||||||
# The highest safe address for
|
|
||||||
# the contents of an initrd
|
|
||||||
|
|
||||||
trampoline: call start_of_setup
|
|
||||||
trampoline_end:
|
|
||||||
.space 1024
|
|
||||||
# End of setup header #####################################################
|
|
||||||
|
|
||||||
start_of_setup:
|
|
||||||
# Set %ds = %cs, we know that SETUPSEG = %cs at this point
|
|
||||||
movw %cs, %ax # aka SETUPSEG
|
|
||||||
movw %ax, %ds
|
|
||||||
# Check signature at end of setup
|
|
||||||
cmpw $SIG1, (setup_sig1 - setup_code)
|
|
||||||
jne bad_sig
|
|
||||||
|
|
||||||
cmpw $SIG2, (setup_sig2 - setup_code)
|
|
||||||
jne bad_sig
|
|
||||||
|
|
||||||
jmp good_sig1
|
|
||||||
|
|
||||||
# Routine to print asciiz string at ds:si
|
|
||||||
prtstr:
|
|
||||||
lodsb
|
|
||||||
andb %al, %al
|
|
||||||
jz fin
|
|
||||||
|
|
||||||
call prtchr
|
|
||||||
jmp prtstr
|
|
||||||
|
|
||||||
fin: ret
|
|
||||||
|
|
||||||
# Part of above routine, this one just prints ascii al
|
|
||||||
prtchr: pushw %ax
|
|
||||||
pushw %cx
|
|
||||||
movw $7,%bx
|
|
||||||
movw $0x01, %cx
|
|
||||||
movb $0x0e, %ah
|
|
||||||
int $0x10
|
|
||||||
popw %cx
|
|
||||||
popw %ax
|
|
||||||
ret
|
|
||||||
|
|
||||||
no_sig_mess: .string "No setup signature found ..."
|
|
||||||
|
|
||||||
good_sig1:
|
|
||||||
jmp good_sig
|
|
||||||
|
|
||||||
# We now have to find the rest of the setup code/data
|
|
||||||
bad_sig:
|
|
||||||
movw %cs, %ax # SETUPSEG
|
|
||||||
subw $DELTA_INITSEG, %ax # INITSEG
|
|
||||||
movw %ax, %ds
|
|
||||||
xorb %bh, %bh
|
|
||||||
movb (497), %bl # get setup sect from bootsect
|
|
||||||
subw $4, %bx # LILO loads 4 sectors of setup
|
|
||||||
shlw $8, %bx # convert to words (1sect=2^8 words)
|
|
||||||
movw %bx, %cx
|
|
||||||
shrw $3, %bx # convert to segment
|
|
||||||
addw $SYSSEG, %bx
|
|
||||||
movw %bx, %cs:(start_sys_seg - setup_code)
|
|
||||||
# Move rest of setup code/data to here
|
|
||||||
movw $2048, %di # four sectors loaded by LILO
|
|
||||||
subw %si, %si
|
|
||||||
pushw %cs
|
|
||||||
popw %es
|
|
||||||
movw $SYSSEG, %ax
|
|
||||||
movw %ax, %ds
|
|
||||||
rep
|
|
||||||
movsw
|
|
||||||
movw %cs, %ax # aka SETUPSEG
|
|
||||||
movw %ax, %ds
|
|
||||||
cmpw $SIG1, (setup_sig1 - setup_code)
|
|
||||||
jne no_sig
|
|
||||||
|
|
||||||
cmpw $SIG2, (setup_sig2 - setup_code)
|
|
||||||
jne no_sig
|
|
||||||
|
|
||||||
jmp good_sig
|
|
||||||
|
|
||||||
no_sig:
|
|
||||||
lea (no_sig_mess - setup_code), %si
|
|
||||||
call prtstr
|
|
||||||
|
|
||||||
no_sig_loop:
|
|
||||||
hlt
|
|
||||||
jmp no_sig_loop
|
|
||||||
|
|
||||||
good_sig:
|
|
||||||
cmpw $0, %cs:(realmode_swtch - setup_code)
|
|
||||||
jz rmodeswtch_normal
|
|
||||||
|
|
||||||
lcall *%cs:(realmode_swtch - setup_code)
|
|
||||||
jmp rmodeswtch_end
|
|
||||||
|
|
||||||
rmodeswtch_normal:
|
|
||||||
pushw %cs
|
|
||||||
call default_switch
|
|
||||||
|
|
||||||
rmodeswtch_end:
|
|
||||||
# we get the code32 start address and modify the below 'jmpi'
|
|
||||||
# (loader may have changed it)
|
|
||||||
movl %cs:(code32_start - setup_code), %eax
|
|
||||||
movl %eax, %cs:(code32 - setup_code)
|
|
||||||
|
|
||||||
# then we load the segment descriptors
|
|
||||||
movw %cs, %ax # aka SETUPSEG
|
|
||||||
movw %ax, %ds
|
|
||||||
|
|
||||||
#
|
|
||||||
# Enable A20. This is at the very best an annoying procedure.
|
|
||||||
# A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.
|
|
||||||
#
|
|
||||||
|
|
||||||
A20_TEST_LOOPS = 32 # Iterations per wait
|
|
||||||
A20_ENABLE_LOOPS = 255 # Total loops to try
|
|
||||||
|
|
||||||
a20_try_loop:
|
|
||||||
|
|
||||||
# First, see if we are on a system with no A20 gate.
|
|
||||||
a20_none:
|
|
||||||
call a20_test
|
|
||||||
jnz a20_done
|
|
||||||
|
|
||||||
# Next, try the BIOS (INT 0x15, AX=0x2401)
|
|
||||||
a20_bios:
|
|
||||||
movw $0x2401, %ax
|
|
||||||
pushfl # Be paranoid about flags
|
|
||||||
int $0x15
|
|
||||||
popfl
|
|
||||||
|
|
||||||
call a20_test
|
|
||||||
jnz a20_done
|
|
||||||
|
|
||||||
# Try enabling A20 through the keyboard controller
|
|
||||||
a20_kbc:
|
|
||||||
call empty_8042
|
|
||||||
|
|
||||||
call a20_test # Just in case the BIOS worked
|
|
||||||
jnz a20_done # but had a delayed reaction.
|
|
||||||
|
|
||||||
movb $0xD1, %al # command write
|
|
||||||
outb %al, $0x64
|
|
||||||
call empty_8042
|
|
||||||
|
|
||||||
movb $0xDF, %al # A20 on
|
|
||||||
outb %al, $0x60
|
|
||||||
call empty_8042
|
|
||||||
|
|
||||||
# Wait until a20 really *is* enabled; it can take a fair amount of
|
|
||||||
# time on certain systems; Toshiba Tecras are known to have this
|
|
||||||
# problem.
|
|
||||||
a20_kbc_wait:
|
|
||||||
xorw %cx, %cx
|
|
||||||
a20_kbc_wait_loop:
|
|
||||||
call a20_test
|
|
||||||
jnz a20_done
|
|
||||||
loop a20_kbc_wait_loop
|
|
||||||
|
|
||||||
# Final attempt: use "configuration port A"
|
|
||||||
a20_fast:
|
|
||||||
inb $0x92, %al # Configuration Port A
|
|
||||||
orb $0x02, %al # "fast A20" version
|
|
||||||
andb $0xFE, %al # don't accidentally reset
|
|
||||||
outb %al, $0x92
|
|
||||||
|
|
||||||
# Wait for configuration port A to take effect
|
|
||||||
a20_fast_wait:
|
|
||||||
xorw %cx, %cx
|
|
||||||
a20_fast_wait_loop:
|
|
||||||
call a20_test
|
|
||||||
jnz a20_done
|
|
||||||
loop a20_fast_wait_loop
|
|
||||||
|
|
||||||
# A20 is still not responding. Try frobbing it again.
|
|
||||||
#
|
|
||||||
decb (a20_tries - setup_code)
|
|
||||||
jnz a20_try_loop
|
|
||||||
|
|
||||||
movw $(a20_err_msg - setup_code), %si
|
|
||||||
call prtstr
|
|
||||||
|
|
||||||
a20_die:
|
|
||||||
hlt
|
|
||||||
jmp a20_die
|
|
||||||
|
|
||||||
a20_tries:
|
|
||||||
.byte A20_ENABLE_LOOPS
|
|
||||||
|
|
||||||
a20_err_msg:
|
|
||||||
.ascii "linux: fatal error: A20 gate not responding!"
|
|
||||||
.byte 13, 10, 0
|
|
||||||
|
|
||||||
# If we get here, all is good
|
|
||||||
a20_done:
|
|
||||||
# Leave the idt alone
|
|
||||||
|
|
||||||
# set up gdt
|
|
||||||
xorl %eax, %eax # Compute gdt_base
|
|
||||||
movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
|
|
||||||
shll $4, %eax
|
|
||||||
addl $(bImage_gdt - setup_code), %eax
|
|
||||||
movl %eax, (bImage_gdt_48+2 - setup_code)
|
|
||||||
DATA32 lgdt %ds:(bImage_gdt_48 - setup_code) # load gdt with whatever is
|
|
||||||
# appropriate
|
|
||||||
|
|
||||||
# Switch to protected mode
|
|
||||||
movl %cr0, %eax
|
|
||||||
orb $CR0_PE, %al
|
|
||||||
movl %eax, %cr0
|
|
||||||
|
|
||||||
DATA32 ljmp *%ds:(code32 - setup_code)
|
|
||||||
code32:
|
|
||||||
.long 0x100000
|
|
||||||
.word __BOOT_CS, 0
|
|
||||||
|
|
||||||
# Here's a bunch of information about your current kernel..
|
|
||||||
kernel_version: .ascii "Etherboot "
|
|
||||||
.ascii VERSION
|
|
||||||
.byte 0
|
|
||||||
|
|
||||||
# This is the default real mode switch routine.
|
|
||||||
# to be called just before protected mode transition
|
|
||||||
default_switch:
|
|
||||||
cli # no interrupts allowed !
|
|
||||||
movb $0x80, %al # disable NMI for bootup
|
|
||||||
# sequence
|
|
||||||
outb %al, $0x70
|
|
||||||
lret
|
|
||||||
|
|
||||||
# This routine tests whether or not A20 is enabled. If so, it
|
|
||||||
# exits with zf = 0.
|
|
||||||
#
|
|
||||||
# The memory address used, 0x200, is the int $0x80 vector, which
|
|
||||||
# should be safe.
|
|
||||||
|
|
||||||
A20_TEST_ADDR = 4*0x80
|
|
||||||
|
|
||||||
a20_test:
|
|
||||||
pushw %cx
|
|
||||||
pushw %ax
|
|
||||||
xorw %cx, %cx
|
|
||||||
movw %cx, %fs # Low memory
|
|
||||||
decw %cx
|
|
||||||
movw %cx, %gs # High memory area
|
|
||||||
movw $A20_TEST_LOOPS, %cx
|
|
||||||
movw %fs:(A20_TEST_ADDR), %ax
|
|
||||||
pushw %ax
|
|
||||||
a20_test_wait:
|
|
||||||
incw %ax
|
|
||||||
movw %ax, %fs:(A20_TEST_ADDR)
|
|
||||||
call delay # Serialize and make delay constant
|
|
||||||
cmpw %gs:(A20_TEST_ADDR+0x10), %ax
|
|
||||||
loope a20_test_wait
|
|
||||||
|
|
||||||
popw %fs:(A20_TEST_ADDR)
|
|
||||||
popw %ax
|
|
||||||
popw %cx
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
# This routine checks that the keyboard command queue is empty
|
|
||||||
# (after emptying the output buffers)
|
|
||||||
#
|
|
||||||
# Some machines have delusions that the keyboard buffer is always full
|
|
||||||
# with no keyboard attached...
|
|
||||||
#
|
|
||||||
# If there is no keyboard controller, we will usually get 0xff
|
|
||||||
# to all the reads. With each IO taking a microsecond and
|
|
||||||
# a timeout of 100,000 iterations, this can take about half a
|
|
||||||
# second ("delay" == outb to port 0x80). That should be ok,
|
|
||||||
# and should also be plenty of time for a real keyboard controller
|
|
||||||
# to empty.
|
|
||||||
#
|
|
||||||
|
|
||||||
empty_8042:
|
|
||||||
pushl %ecx
|
|
||||||
movl $100000, %ecx
|
|
||||||
|
|
||||||
empty_8042_loop:
|
|
||||||
decl %ecx
|
|
||||||
jz empty_8042_end_loop
|
|
||||||
|
|
||||||
call delay
|
|
||||||
|
|
||||||
inb $0x64, %al # 8042 status port
|
|
||||||
testb $1, %al # output buffer?
|
|
||||||
jz no_output
|
|
||||||
|
|
||||||
call delay
|
|
||||||
inb $0x60, %al # read it
|
|
||||||
jmp empty_8042_loop
|
|
||||||
|
|
||||||
no_output:
|
|
||||||
testb $2, %al # is input buffer full?
|
|
||||||
jnz empty_8042_loop # yes - loop
|
|
||||||
empty_8042_end_loop:
|
|
||||||
popl %ecx
|
|
||||||
|
|
||||||
|
|
||||||
# Delay is needed after doing I/O
|
|
||||||
delay:
|
|
||||||
outb %al,$0x80
|
|
||||||
ret
|
|
||||||
|
|
||||||
# Descriptor tables
|
|
||||||
#
|
|
||||||
# NOTE: The intel manual says gdt should be sixteen bytes aligned for
|
|
||||||
# efficiency reasons. However, there are machines which are known not
|
|
||||||
# to boot with misaligned GDTs, so alter this at your peril! If you alter
|
|
||||||
# GDT_ENTRY_BOOT_CS (in asm/segment.h) remember to leave at least two
|
|
||||||
# empty GDT entries (one for NULL and one reserved).
|
|
||||||
#
|
|
||||||
# NOTE: On some CPUs, the GDT must be 8 byte aligned. This is
|
|
||||||
# true for the Voyager Quad CPU card which will not boot without
|
|
||||||
# This directive. 16 byte aligment is recommended by intel.
|
|
||||||
#
|
|
||||||
.balign 16
|
|
||||||
bImage_gdt:
|
|
||||||
.fill GDT_ENTRY_BOOT_CS,8,0
|
|
||||||
|
|
||||||
.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)
|
|
||||||
bImage_gdt_end:
|
|
||||||
.balign 4
|
|
||||||
|
|
||||||
.word 0 # alignment byte
|
|
||||||
bImage_idt_48:
|
|
||||||
.word 0 # idt limit = 0
|
|
||||||
.long 0 # idt base = 0L
|
|
||||||
|
|
||||||
.word 0 # alignment byte
|
|
||||||
bImage_gdt_48:
|
|
||||||
.word bImage_gdt_end - bImage_gdt - 1 # gdt limit
|
|
||||||
.long bImage_gdt_48 - setup_code # gdt base (filled in later)
|
|
||||||
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
int $0x19 /* should try to boot machine */
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
|
|
||||||
|
|
||||||
.org (PREFIXSIZE - 4)
|
|
||||||
# Setup signature -- must be last
|
|
||||||
setup_sig1: .word SIG1
|
|
||||||
setup_sig2: .word SIG2
|
|
||||||
/* Etherboot expects to be contiguous in memory once loaded.
|
|
||||||
* The linux bImage protocol does not do this, but since we
|
|
||||||
* don't need any information that's left in the prefix, it
|
|
||||||
* doesn't matter: we just have to ensure that we make it to _start
|
|
||||||
*
|
|
||||||
* protected_start will live at 0x100000 and it will be the
|
|
||||||
* the first code called as we enter protected mode.
|
|
||||||
*/
|
|
||||||
.code32
|
|
||||||
protected_start:
|
|
||||||
/* Load segment registers */
|
|
||||||
movw $__BOOT_DS, %ax
|
|
||||||
movw %ax, %ss
|
|
||||||
movw %ax, %ds
|
|
||||||
movw %ax, %es
|
|
||||||
movw %ax, %fs
|
|
||||||
movw %ax, %gs
|
|
||||||
|
|
||||||
/* Use the internal etherboot stack */
|
|
||||||
movl $(_prefix_stack_end - protected_start + 0x100000), %esp
|
|
||||||
|
|
||||||
pushl $0 /* No parameters to preserve for exit path */
|
|
||||||
pushl $0 /* Use prefix exit path mechanism */
|
|
||||||
|
|
||||||
jmp _start
|
|
||||||
/*
|
|
||||||
That's about it.
|
|
||||||
*/
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* We need a real mode stack that won't be stomped on by Etherboot
|
|
||||||
which starts at 0x20000. Choose something that's sufficiently high,
|
|
||||||
but not in DOC territory. Note that we couldn't do this in a real
|
|
||||||
.com program since stack variables are in the same segment as the
|
|
||||||
code and data, but this isn't really a .com program, it just looks
|
|
||||||
like one to make DOS load it into memory. It still has the 64kB
|
|
||||||
limitation of .com files though. */
|
|
||||||
#define STACK_SEG 0x7000
|
|
||||||
#define STACK_SIZE 0x4000
|
|
||||||
|
|
||||||
.text
|
|
||||||
.code16
|
|
||||||
.arch i386
|
|
||||||
.section ".prefix", "ax", @progbits
|
|
||||||
|
|
||||||
/* Cheat a little with the relocations: .COM files are loaded at 0x100 */
|
|
||||||
_prefix:
|
|
||||||
/* Set up temporary stack */
|
|
||||||
movw $STACK_SEG, %ax
|
|
||||||
movw %ax, %ss
|
|
||||||
movw $STACK_SIZE, %sp
|
|
||||||
|
|
||||||
pushl $0 /* No parameters to preserve for exit path */
|
|
||||||
pushw $0 /* Dummy return address - use prefix_exit */
|
|
||||||
|
|
||||||
/* Calculate segment address of image start */
|
|
||||||
pushw %cs
|
|
||||||
popw %ax
|
|
||||||
addw $(0x100/16), %ax
|
|
||||||
pushw %ax
|
|
||||||
pushw $_start
|
|
||||||
/* Calculated lcall to _start with %cs:0000 = image start */
|
|
||||||
lret
|
|
||||||
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
movw $0x4c00,%ax /* return to DOS */
|
|
||||||
int $0x21 /* reach this on Quit */
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
|
|
||||||
/* The body of etherboot is attached here at build time.
|
|
||||||
* Force 16 byte alignment
|
|
||||||
*/
|
|
||||||
.align 16,0
|
|
||||||
_body:
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#include "elf.h"
|
|
||||||
|
|
||||||
.arch i386
|
|
||||||
.section ".prefix", "a", @progbits
|
|
||||||
|
|
||||||
#define LOAD_ADDR 0x10000
|
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
.globl elf_header
|
|
||||||
elf_header:
|
|
||||||
e_ident: .byte 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
e_type: .short ET_DYN
|
|
||||||
e_machine: .short EM_386
|
|
||||||
e_version: .long 1
|
|
||||||
e_entry: .long LOAD_ADDR + _start - elf_header
|
|
||||||
e_phoff: .long elf_program_header - elf_header
|
|
||||||
e_shoff: .long 0
|
|
||||||
e_flags: .long 0
|
|
||||||
e_ehsize: .short elf_header_end - elf_header
|
|
||||||
e_phentsize: .short ELF32_PHDR_SIZE
|
|
||||||
e_phnum: .short (elf_program_header_end - elf_program_header)/ELF32_PHDR_SIZE
|
|
||||||
e_shentsize: .short 0
|
|
||||||
e_shnum: .short 0
|
|
||||||
e_shstrndx: .short 0
|
|
||||||
elf_header_end:
|
|
||||||
|
|
||||||
elf_program_header:
|
|
||||||
phdr1_p_type: .long PT_NOTE
|
|
||||||
phdr1_p_offset: .long elf_note - elf_header
|
|
||||||
phdr1_p_vaddr: .long elf_note
|
|
||||||
phdr1_p_paddr: .long elf_note
|
|
||||||
phdr1_p_filesz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_memsz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr1_p_align: .long 0
|
|
||||||
|
|
||||||
/* The decompressor */
|
|
||||||
phdr2_p_type: .long PT_LOAD
|
|
||||||
phdr2_p_offset: .long 0
|
|
||||||
phdr2_p_vaddr: .long elf_header
|
|
||||||
phdr2_p_paddr: .long LOAD_ADDR
|
|
||||||
phdr2_p_filesz: .long _verbatim_size
|
|
||||||
phdr2_p_memsz: .long _image_size
|
|
||||||
phdr2_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr2_p_align: .long 16
|
|
||||||
|
|
||||||
elf_program_header_end:
|
|
||||||
|
|
||||||
.globl elf_note
|
|
||||||
elf_note:
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_NAME
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz "Etherboot"
|
|
||||||
4:
|
|
||||||
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_VERSION
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz VERSION
|
|
||||||
4:
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_CHECKSUM
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.word 0
|
|
||||||
4:
|
|
||||||
#endif
|
|
||||||
.balign 4
|
|
||||||
elf_note_end:
|
|
||||||
|
|
||||||
/* Dummy routines to satisfy the build */
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#include "elf.h"
|
|
||||||
|
|
||||||
.arch i386
|
|
||||||
.section ".prefix", "a", @progbits
|
|
||||||
|
|
||||||
#define LOAD_ADDR 0x10000
|
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
.globl elf_header
|
|
||||||
elf_header:
|
|
||||||
e_ident: .byte 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
e_type: .short ET_EXEC
|
|
||||||
e_machine: .short EM_386
|
|
||||||
e_version: .long 1
|
|
||||||
e_entry: .long LOAD_ADDR + _start - elf_header
|
|
||||||
e_phoff: .long elf_program_header - elf_header
|
|
||||||
e_shoff: .long 0
|
|
||||||
e_flags: .long 0
|
|
||||||
e_ehsize: .short elf_header_end - elf_header
|
|
||||||
e_phentsize: .short ELF32_PHDR_SIZE
|
|
||||||
e_phnum: .short (elf_program_header_end - elf_program_header)/ELF32_PHDR_SIZE
|
|
||||||
e_shentsize: .short 0
|
|
||||||
e_shnum: .short 0
|
|
||||||
e_shstrndx: .short 0
|
|
||||||
elf_header_end:
|
|
||||||
|
|
||||||
elf_program_header:
|
|
||||||
phdr1_p_type: .long PT_NOTE
|
|
||||||
phdr1_p_offset: .long elf_note - elf_header
|
|
||||||
phdr1_p_vaddr: .long elf_note
|
|
||||||
phdr1_p_paddr: .long elf_note
|
|
||||||
phdr1_p_filesz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_memsz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr1_p_align: .long 0
|
|
||||||
|
|
||||||
/* The decompressor */
|
|
||||||
phdr2_p_type: .long PT_LOAD
|
|
||||||
phdr2_p_offset: .long 0
|
|
||||||
phdr2_p_vaddr: .long elf_header
|
|
||||||
phdr2_p_paddr: .long LOAD_ADDR
|
|
||||||
phdr2_p_filesz: .long _verbatim_size
|
|
||||||
phdr2_p_memsz: .long _image_size
|
|
||||||
phdr2_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr2_p_align: .long 16
|
|
||||||
|
|
||||||
elf_program_header_end:
|
|
||||||
|
|
||||||
.globl elf_note
|
|
||||||
elf_note:
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_NAME
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz "Etherboot"
|
|
||||||
4:
|
|
||||||
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_VERSION
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz VERSION
|
|
||||||
4:
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_CHECKSUM
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.word 0
|
|
||||||
4:
|
|
||||||
#endif
|
|
||||||
.balign 4
|
|
||||||
elf_note_end:
|
|
||||||
|
|
||||||
/* Dummy routines to satisfy the build */
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Prefix for .exe images
|
|
||||||
Doesn't work yet, even though it starts off the same as a .com
|
|
||||||
image as shown by DOS debug.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.text
|
|
||||||
.code16
|
|
||||||
.arch i386
|
|
||||||
.section ".prefix", "ax", @progbits
|
|
||||||
|
|
||||||
_prefix:
|
|
||||||
.byte 'M', 'Z'
|
|
||||||
.short _exe_size_tail /* tail */
|
|
||||||
.short _exe_size_pages /* pages */
|
|
||||||
.short 0 /* relocations */
|
|
||||||
.short 2 /* header paras */
|
|
||||||
.short _exe_bss_size /* min */
|
|
||||||
.short 0xFFFF /* max paras */
|
|
||||||
.short _exe_ss_offset /* SS */
|
|
||||||
.short _stack_size /* SP */
|
|
||||||
.short 0 /* checksum */
|
|
||||||
.short 0 /* IP */
|
|
||||||
.short 0 /* CS */
|
|
||||||
.short 0x1C /* reloc offset */
|
|
||||||
.short 0 /* overlay number */
|
|
||||||
.short 0 /* fill */
|
|
||||||
.short 0 /* fill */
|
|
||||||
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
movw $0x4c00,%ax /* return to DOS */
|
|
||||||
int $0x21 /* reach this on Quit */
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
|
|
||||||
/* The body of etherboot is attached here at build time.
|
|
||||||
* Force 16 byte alignment
|
|
||||||
*/
|
|
||||||
.align 16,0
|
|
||||||
_body:
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
#include "elf.h"
|
|
||||||
.arch sledgehammer
|
|
||||||
.code32
|
|
||||||
.equ FLAT_CODE_SEG,_pmcs-_gdt
|
|
||||||
.equ FLAT_DATA_SEG,_pmds-_gdt
|
|
||||||
.equ MSR_K6_EFER, 0xC0000080
|
|
||||||
.equ EFER_LME, 0x00000100
|
|
||||||
.equ X86_CR4_PAE, 0x00000020
|
|
||||||
.equ CR0_PG, 0x80000000
|
|
||||||
|
|
||||||
.section ".prefix", "ax", @progbits
|
|
||||||
|
|
||||||
#define LOAD_ADDR 0x10000
|
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
.globl elf_header
|
|
||||||
elf_header:
|
|
||||||
e_ident: .byte 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
e_type: .short ET_DYN
|
|
||||||
e_machine: .short EM_X86_64
|
|
||||||
e_version: .long 1
|
|
||||||
e_entry: .long LOAD_ADDR + elf_start - elf_header
|
|
||||||
e_phoff: .long elf_program_header - elf_header
|
|
||||||
e_shoff: .long 0
|
|
||||||
e_flags: .long 0
|
|
||||||
e_ehsize: .short elf_header_end - elf_header
|
|
||||||
e_phentsize: .short ELF32_PHDR_SIZE
|
|
||||||
e_phnum: .short (elf_program_header_end - elf_program_header)/ELF32_PHDR_SIZE
|
|
||||||
e_shentsize: .short 0
|
|
||||||
e_shnum: .short 0
|
|
||||||
e_shstrndx: .short 0
|
|
||||||
elf_header_end:
|
|
||||||
|
|
||||||
elf_program_header:
|
|
||||||
phdr1_p_type: .long PT_NOTE
|
|
||||||
phdr1_p_offset: .long elf_note - elf_header
|
|
||||||
phdr1_p_vaddr: .long elf_note
|
|
||||||
phdr1_p_paddr: .long elf_note
|
|
||||||
phdr1_p_filesz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_memsz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr1_p_align: .long 0
|
|
||||||
|
|
||||||
/* The decompressor */
|
|
||||||
phdr2_p_type: .long PT_LOAD
|
|
||||||
phdr2_p_offset: .long 0
|
|
||||||
phdr2_p_vaddr: .long elf_header
|
|
||||||
phdr2_p_paddr: .long LOAD_ADDR
|
|
||||||
phdr2_p_filesz: .long _verbatim_size
|
|
||||||
phdr2_p_memsz: .long _image_size
|
|
||||||
phdr2_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr2_p_align: .long 16
|
|
||||||
|
|
||||||
elf_program_header_end:
|
|
||||||
|
|
||||||
.globl elf_note
|
|
||||||
elf_note:
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_NAME
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz "Etherboot"
|
|
||||||
4:
|
|
||||||
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_VERSION
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz VERSION
|
|
||||||
4:
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_CHECKSUM
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.word 0
|
|
||||||
4:
|
|
||||||
#endif
|
|
||||||
.balign 4
|
|
||||||
elf_note_end:
|
|
||||||
|
|
||||||
elf_start:
|
|
||||||
.code64
|
|
||||||
/* Reload the gdt to something I know */
|
|
||||||
leaq _gdt(%rip), %rax
|
|
||||||
movq %rax, 0x02 + gdtptr(%rip)
|
|
||||||
lgdt gdtptr(%rip)
|
|
||||||
|
|
||||||
/* Enter 32bit compatibility mode */
|
|
||||||
leaq elf_start32(%rip), %rax
|
|
||||||
movl %eax, 0x00 + elf_start32_addr(%rip)
|
|
||||||
ljmp *elf_start32_addr(%rip)
|
|
||||||
|
|
||||||
elf_start32:
|
|
||||||
.code32
|
|
||||||
/* Reload the data segments */
|
|
||||||
movl $FLAT_DATA_SEG, %eax
|
|
||||||
movl %eax, %ds
|
|
||||||
movl %eax, %es
|
|
||||||
movl %eax, %ss
|
|
||||||
|
|
||||||
/* Disable paging */
|
|
||||||
movl %cr0, %eax
|
|
||||||
andl $~CR0_PG, %eax
|
|
||||||
movl %eax, %cr0
|
|
||||||
|
|
||||||
/* Disable long mode */
|
|
||||||
movl $MSR_K6_EFER, %ecx
|
|
||||||
rdmsr
|
|
||||||
andl $~EFER_LME, %eax
|
|
||||||
wrmsr
|
|
||||||
|
|
||||||
/* Disable PAE */
|
|
||||||
movl %cr4, %eax
|
|
||||||
andl $~X86_CR4_PAE, %eax
|
|
||||||
movl %eax, %cr4
|
|
||||||
|
|
||||||
/* Save the first argument */
|
|
||||||
pushl %ebx
|
|
||||||
jmp _start
|
|
||||||
|
|
||||||
gdtptr:
|
|
||||||
.word _gdt_end - _gdt -1
|
|
||||||
.long _gdt
|
|
||||||
.long 0
|
|
||||||
_gdt:
|
|
||||||
elf_start32_addr:
|
|
||||||
.long elf_start32
|
|
||||||
.long FLAT_CODE_SEG
|
|
||||||
_pmcs:
|
|
||||||
/* 32 bit protected mode code segment, base 0 */
|
|
||||||
.word 0xffff,0
|
|
||||||
.byte 0,0x9f,0xcf,0
|
|
||||||
|
|
||||||
_pmds:
|
|
||||||
/* 32 bit protected mode data segment, base 0 */
|
|
||||||
.word 0xffff,0
|
|
||||||
.byte 0,0x93,0xcf,0
|
|
||||||
_gdt_end:
|
|
||||||
|
|
||||||
|
|
||||||
/* Dummy routines to satisfy the build */
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
#include "elf.h"
|
|
||||||
.arch sledgehammer
|
|
||||||
.code32
|
|
||||||
.equ FLAT_CODE_SEG,_pmcs-_gdt
|
|
||||||
.equ FLAT_DATA_SEG,_pmds-_gdt
|
|
||||||
.equ MSR_K6_EFER, 0xC0000080
|
|
||||||
.equ EFER_LME, 0x00000100
|
|
||||||
.equ X86_CR4_PAE, 0x00000020
|
|
||||||
.equ CR0_PG, 0x80000000
|
|
||||||
|
|
||||||
.section ".prefix", "ax", @progbits
|
|
||||||
|
|
||||||
#define LOAD_ADDR 0x10000
|
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
.globl elf_header
|
|
||||||
elf_header:
|
|
||||||
e_ident: .byte 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
e_type: .short ET_EXEC
|
|
||||||
e_machine: .short EM_X86_64
|
|
||||||
e_version: .long 1
|
|
||||||
e_entry: .long LOAD_ADDR + elf_start - elf_header
|
|
||||||
e_phoff: .long elf_program_header - elf_header
|
|
||||||
e_shoff: .long 0
|
|
||||||
e_flags: .long 0
|
|
||||||
e_ehsize: .short elf_header_end - elf_header
|
|
||||||
e_phentsize: .short ELF32_PHDR_SIZE
|
|
||||||
e_phnum: .short (elf_program_header_end - elf_program_header)/ELF32_PHDR_SIZE
|
|
||||||
e_shentsize: .short 0
|
|
||||||
e_shnum: .short 0
|
|
||||||
e_shstrndx: .short 0
|
|
||||||
elf_header_end:
|
|
||||||
|
|
||||||
elf_program_header:
|
|
||||||
phdr1_p_type: .long PT_NOTE
|
|
||||||
phdr1_p_offset: .long elf_note - elf_header
|
|
||||||
phdr1_p_vaddr: .long elf_note
|
|
||||||
phdr1_p_paddr: .long elf_note
|
|
||||||
phdr1_p_filesz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_memsz: .long elf_note_end - elf_note
|
|
||||||
phdr1_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr1_p_align: .long 0
|
|
||||||
|
|
||||||
/* The decompressor */
|
|
||||||
phdr2_p_type: .long PT_LOAD
|
|
||||||
phdr2_p_offset: .long 0
|
|
||||||
phdr2_p_vaddr: .long elf_header
|
|
||||||
phdr2_p_paddr: .long LOAD_ADDR
|
|
||||||
phdr2_p_filesz: .long _verbatim_size
|
|
||||||
phdr2_p_memsz: .long _image_size
|
|
||||||
phdr2_p_flags: .long PF_R | PF_W | PF_X
|
|
||||||
phdr2_p_align: .long 16
|
|
||||||
|
|
||||||
elf_program_header_end:
|
|
||||||
|
|
||||||
.globl elf_note
|
|
||||||
elf_note:
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_NAME
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz "Etherboot"
|
|
||||||
4:
|
|
||||||
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_VERSION
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.asciz VERSION
|
|
||||||
4:
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
.balign 4
|
|
||||||
.int 2f - 1f
|
|
||||||
.int 4f - 3f
|
|
||||||
.int EIN_PROGRAM_CHECKSUM
|
|
||||||
1: .asciz "ELFBoot"
|
|
||||||
2:
|
|
||||||
.balign 4
|
|
||||||
3:
|
|
||||||
.word 0
|
|
||||||
4:
|
|
||||||
#endif
|
|
||||||
.balign 4
|
|
||||||
elf_note_end:
|
|
||||||
|
|
||||||
elf_start:
|
|
||||||
.code64
|
|
||||||
/* Reload the gdt to something I know */
|
|
||||||
leaq _gdt(%rip), %rax
|
|
||||||
movq %rax, 0x02 + gdtptr(%rip)
|
|
||||||
lgdt gdtptr(%rip)
|
|
||||||
|
|
||||||
/* Enter 32bit compatibility mode */
|
|
||||||
leaq elf_start32(%rip), %rax
|
|
||||||
movl %eax, 0x00 + elf_start32_addr(%rip)
|
|
||||||
ljmp *elf_start32_addr(%rip)
|
|
||||||
|
|
||||||
elf_start32:
|
|
||||||
.code32
|
|
||||||
/* Reload the data segments */
|
|
||||||
movl $FLAT_DATA_SEG, %eax
|
|
||||||
movl %eax, %ds
|
|
||||||
movl %eax, %es
|
|
||||||
movl %eax, %ss
|
|
||||||
|
|
||||||
/* Disable paging */
|
|
||||||
movl %cr0, %eax
|
|
||||||
andl $~CR0_PG, %eax
|
|
||||||
movl %eax, %cr0
|
|
||||||
|
|
||||||
/* Disable long mode */
|
|
||||||
movl $MSR_K6_EFER, %ecx
|
|
||||||
rdmsr
|
|
||||||
andl $~EFER_LME, %eax
|
|
||||||
wrmsr
|
|
||||||
|
|
||||||
/* Disable PAE */
|
|
||||||
movl %cr4, %eax
|
|
||||||
andl $~X86_CR4_PAE, %eax
|
|
||||||
movl %eax, %cr4
|
|
||||||
|
|
||||||
/* Save the first argument */
|
|
||||||
pushl %ebx
|
|
||||||
jmp _start
|
|
||||||
|
|
||||||
gdtptr:
|
|
||||||
.word _gdt_end - _gdt -1
|
|
||||||
.long _gdt
|
|
||||||
.long 0
|
|
||||||
_gdt:
|
|
||||||
elf_start32_addr:
|
|
||||||
.long elf_start32
|
|
||||||
.long FLAT_CODE_SEG
|
|
||||||
_pmcs:
|
|
||||||
/* 32 bit protected mode code segment, base 0 */
|
|
||||||
.word 0xffff,0
|
|
||||||
.byte 0,0x9f,0xcf,0
|
|
||||||
|
|
||||||
_pmds:
|
|
||||||
/* 32 bit protected mode data segment, base 0 */
|
|
||||||
.word 0xffff,0
|
|
||||||
.byte 0,0x93,0xcf,0
|
|
||||||
_gdt_end:
|
|
||||||
|
|
||||||
|
|
||||||
/* Dummy routines to satisfy the build */
|
|
||||||
.section ".text16", "ax", @progbits
|
|
||||||
prefix_exit:
|
|
||||||
|
|
||||||
prefix_exit_end:
|
|
||||||
.previous
|
|
||||||
@@ -109,9 +109,6 @@ REQUIRE_OBJECT ( pxe_call );
|
|||||||
#ifdef DOWNLOAD_PROTO_TFTP
|
#ifdef DOWNLOAD_PROTO_TFTP
|
||||||
REQUIRE_OBJECT ( tftp );
|
REQUIRE_OBJECT ( tftp );
|
||||||
#endif
|
#endif
|
||||||
#ifdef DOWNLOAD_PROTO_NFS
|
|
||||||
REQUIRE_OBJECT ( nfs );
|
|
||||||
#endif
|
|
||||||
#ifdef DOWNLOAD_PROTO_HTTP
|
#ifdef DOWNLOAD_PROTO_HTTP
|
||||||
REQUIRE_OBJECT ( http );
|
REQUIRE_OBJECT ( http );
|
||||||
#endif
|
#endif
|
||||||
@@ -149,9 +146,6 @@ REQUIRE_OBJECT ( ib_srpboot );
|
|||||||
#ifdef DNS_RESOLVER
|
#ifdef DNS_RESOLVER
|
||||||
REQUIRE_OBJECT ( dns );
|
REQUIRE_OBJECT ( dns );
|
||||||
#endif
|
#endif
|
||||||
#ifdef NMB_RESOLVER
|
|
||||||
REQUIRE_OBJECT ( nmb );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Drag in all requested image formats
|
* Drag in all requested image formats
|
||||||
|
|||||||
@@ -54,13 +54,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define DOWNLOAD_PROTO_TFTP /* Trivial File Transfer Protocol */
|
#define DOWNLOAD_PROTO_TFTP /* Trivial File Transfer Protocol */
|
||||||
#undef DOWNLOAD_PROTO_NFS /* Network File System */
|
|
||||||
#define DOWNLOAD_PROTO_HTTP /* Hypertext Transfer Protocol */
|
#define DOWNLOAD_PROTO_HTTP /* Hypertext Transfer Protocol */
|
||||||
#undef DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
|
#undef DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
|
||||||
#undef DOWNLOAD_PROTO_FTP /* File Transfer Protocol */
|
#undef DOWNLOAD_PROTO_FTP /* File Transfer Protocol */
|
||||||
#undef DOWNLOAD_PROTO_TFTM /* Multicast Trivial File Transfer Protocol */
|
#undef DOWNLOAD_PROTO_TFTM /* Multicast Trivial File Transfer Protocol */
|
||||||
#undef DOWNLOAD_PROTO_SLAM /* Scalable Local Area Multicast */
|
#undef DOWNLOAD_PROTO_SLAM /* Scalable Local Area Multicast */
|
||||||
#undef DOWNLOAD_PROTO_FSP /* FSP? */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SAN boot protocols
|
* SAN boot protocols
|
||||||
@@ -85,7 +83,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define DNS_RESOLVER /* DNS resolver */
|
#define DNS_RESOLVER /* DNS resolver */
|
||||||
#undef NMB_RESOLVER /* NMB resolver */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Image types
|
* Image types
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ Literature dealing with the network protocols:
|
|||||||
DHCP - RFC2131, RFC2132 (options)
|
DHCP - RFC2131, RFC2132 (options)
|
||||||
TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
|
TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
|
||||||
RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
|
RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
|
||||||
NFS - RFC1094, RFC1813 (v3, useful for clarifications, not implemented)
|
|
||||||
IGMP - RFC1112
|
|
||||||
|
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1426,7 +1426,7 @@ struct setting filename_setting __setting = {
|
|||||||
/** Root path setting */
|
/** Root path setting */
|
||||||
struct setting root_path_setting __setting = {
|
struct setting root_path_setting __setting = {
|
||||||
.name = "root-path",
|
.name = "root-path",
|
||||||
.description = "NFS/iSCSI root path",
|
.description = "iSCSI root path",
|
||||||
.tag = DHCP_ROOT_PATH,
|
.tag = DHCP_ROOT_PATH,
|
||||||
.type = &setting_type_string,
|
.type = &setting_type_string,
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-4
@@ -225,12 +225,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri,
|
|||||||
dump_uri ( uri );
|
dump_uri ( uri );
|
||||||
DBG ( "\n" );
|
DBG ( "\n" );
|
||||||
|
|
||||||
|
/* Ensure buffer is NUL-terminated */
|
||||||
|
if ( size )
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
/* Special-case NULL URI */
|
/* Special-case NULL URI */
|
||||||
if ( ! uri ) {
|
if ( ! uri )
|
||||||
if ( size )
|
|
||||||
buf[0] = '\0';
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Iterate through requested fields */
|
/* Iterate through requested fields */
|
||||||
for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {
|
for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
/* Protocol numbers */
|
/* Protocol numbers */
|
||||||
|
|
||||||
#define IP_ICMP 1
|
#define IP_ICMP 1
|
||||||
#define IP_IGMP 2
|
|
||||||
#define IP_TCP 6
|
#define IP_TCP 6
|
||||||
#define IP_UDP 17
|
#define IP_UDP 17
|
||||||
#define IP_ICMP6 58
|
#define IP_ICMP6 58
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
#ifndef IGMP_H
|
|
||||||
#define IGMP_H
|
|
||||||
|
|
||||||
#include "stdint.h"
|
|
||||||
#include <gpxe/in.h>
|
|
||||||
|
|
||||||
#define IGMP_QUERY 0x11
|
|
||||||
#define IGMPv1_REPORT 0x12
|
|
||||||
#define IGMPv2_REPORT 0x16
|
|
||||||
#define IGMP_LEAVE 0x17
|
|
||||||
#define GROUP_ALL_HOSTS 0xe0000001 /* 224.0.0.1 Host byte order */
|
|
||||||
|
|
||||||
#define MULTICAST_MASK 0xf0000000
|
|
||||||
#define MULTICAST_NETWORK 0xe0000000
|
|
||||||
|
|
||||||
enum {
|
|
||||||
IGMP_SERVER,
|
|
||||||
MAX_IGMP
|
|
||||||
};
|
|
||||||
|
|
||||||
struct igmp {
|
|
||||||
uint8_t type;
|
|
||||||
uint8_t response_time;
|
|
||||||
uint16_t chksum;
|
|
||||||
struct in_addr group;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
struct igmp_ip_t { /* Format of an igmp ip packet */
|
|
||||||
struct iphdr ip;
|
|
||||||
uint8_t router_alert[4]; /* Router alert option */
|
|
||||||
struct igmp igmp;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
struct igmptable_t {
|
|
||||||
struct in_addr group;
|
|
||||||
unsigned long time;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
extern void join_group ( int slot, unsigned long group );
|
|
||||||
extern void leave_group ( int slot );
|
|
||||||
|
|
||||||
#endif /* IGMP_H */
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#ifndef _NFS_H
|
|
||||||
#define _NFS_H
|
|
||||||
|
|
||||||
#define SUNRPC_PORT 111
|
|
||||||
|
|
||||||
#define PROG_PORTMAP 100000
|
|
||||||
#define PROG_NFS 100003
|
|
||||||
#define PROG_MOUNT 100005
|
|
||||||
|
|
||||||
#define MSG_CALL 0
|
|
||||||
#define MSG_REPLY 1
|
|
||||||
|
|
||||||
#define PORTMAP_GETPORT 3
|
|
||||||
|
|
||||||
#define MOUNT_ADDENTRY 1
|
|
||||||
#define MOUNT_UMOUNTALL 4
|
|
||||||
|
|
||||||
#define NFS_LOOKUP 4
|
|
||||||
#define NFS_READLINK 5
|
|
||||||
#define NFS_READ 6
|
|
||||||
|
|
||||||
#define NFS_FHSIZE 32
|
|
||||||
|
|
||||||
#define NFSERR_PERM 1
|
|
||||||
#define NFSERR_NOENT 2
|
|
||||||
#define NFSERR_ACCES 13
|
|
||||||
#define NFSERR_ISDIR 21
|
|
||||||
#define NFSERR_INVAL 22
|
|
||||||
|
|
||||||
/* Block size used for NFS read accesses. A RPC reply packet (including all
|
|
||||||
* headers) must fit within a single Ethernet frame to avoid fragmentation.
|
|
||||||
* Chosen to be a power of two, as most NFS servers are optimized for this. */
|
|
||||||
#define NFS_READ_SIZE 1024
|
|
||||||
|
|
||||||
#define NFS_MAXLINKDEPTH 16
|
|
||||||
|
|
||||||
struct rpc_t {
|
|
||||||
struct iphdr ip;
|
|
||||||
struct udphdr udp;
|
|
||||||
union {
|
|
||||||
uint8_t data[300]; /* longest RPC call must fit!!!! */
|
|
||||||
struct {
|
|
||||||
uint32_t id;
|
|
||||||
uint32_t type;
|
|
||||||
uint32_t rpcvers;
|
|
||||||
uint32_t prog;
|
|
||||||
uint32_t vers;
|
|
||||||
uint32_t proc;
|
|
||||||
uint32_t data[1];
|
|
||||||
} call;
|
|
||||||
struct {
|
|
||||||
uint32_t id;
|
|
||||||
uint32_t type;
|
|
||||||
uint32_t rstatus;
|
|
||||||
uint32_t verifier;
|
|
||||||
uint32_t v2;
|
|
||||||
uint32_t astatus;
|
|
||||||
uint32_t data[1];
|
|
||||||
} reply;
|
|
||||||
} u;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
#endif /* _NFS_H */
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#ifndef NMB_H
|
|
||||||
#define NMB_H
|
|
||||||
|
|
||||||
#include <gpxe/dns.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* NetBIOS name query packets are basically the same as DNS packets,
|
|
||||||
* though the resource record format is different.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DNS_TYPE_NB 0x20
|
|
||||||
#define DNS_FLAG_BROADCAST ( 0x01 << 4 )
|
|
||||||
#define NBNS_UDP_PORT 137
|
|
||||||
|
|
||||||
struct dns_rr_info_nb {
|
|
||||||
struct dns_rr_info info;
|
|
||||||
uint16_t nb_flags;
|
|
||||||
struct in_addr nb_address;
|
|
||||||
} __attribute__ (( packed ));
|
|
||||||
|
|
||||||
#endif /* NMB_H */
|
|
||||||
+2
-1
@@ -452,11 +452,12 @@ static void http_step ( struct process *process ) {
|
|||||||
|
|
||||||
/* Send GET request */
|
/* Send GET request */
|
||||||
if ( ( rc = xfer_printf ( &http->socket,
|
if ( ( rc = xfer_printf ( &http->socket,
|
||||||
"GET %s HTTP/1.0\r\n"
|
"GET %s%s HTTP/1.0\r\n"
|
||||||
"User-Agent: gPXE/" VERSION "\r\n"
|
"User-Agent: gPXE/" VERSION "\r\n"
|
||||||
"%s%s%s"
|
"%s%s%s"
|
||||||
"Host: %s\r\n"
|
"Host: %s\r\n"
|
||||||
"\r\n",
|
"\r\n",
|
||||||
|
http->uri->path ? "" : "/",
|
||||||
request,
|
request,
|
||||||
( user ?
|
( user ?
|
||||||
"Authorization: Basic " : "" ),
|
"Authorization: Basic " : "" ),
|
||||||
|
|||||||
-243
@@ -1,243 +0,0 @@
|
|||||||
/*********************************************************************\
|
|
||||||
* Copyright (c) 2005 by Radim Kolar (hsn-sendmail.cz) *
|
|
||||||
* *
|
|
||||||
* You may copy or modify this file in any manner you wish, provided *
|
|
||||||
* that this notice is always included, and that you hold the author *
|
|
||||||
* harmless for any loss or damage resulting from the installation or *
|
|
||||||
* use of this software. *
|
|
||||||
* *
|
|
||||||
* This file provides support for FSP v2 protocol written from scratch *
|
|
||||||
* by Radim Kolar, FSP project leader. *
|
|
||||||
* *
|
|
||||||
* ABOUT FSP *
|
|
||||||
* FSP is a lightweight file transfer protocol and is being used for *
|
|
||||||
* booting, Internet firmware updates, embedded devices and in *
|
|
||||||
* wireless applications. FSP is very easy to implement; contact Radim *
|
|
||||||
* Kolar if you need hand optimized assembler FSP stacks for various *
|
|
||||||
* microcontrollers, CPUs or consultations. *
|
|
||||||
* http://fsp.sourceforge.net/ *
|
|
||||||
* *
|
|
||||||
* REVISION HISTORY *
|
|
||||||
* 1.0 2005-03-17 rkolar Initial coding *
|
|
||||||
* 1.1 2005-03-24 rkolar We really need to send CC_BYE to the server *
|
|
||||||
* at end of transfer, because next stage boot *
|
|
||||||
* loader is unable to contact FSP server *
|
|
||||||
* until session timeouts. *
|
|
||||||
* 1.2 2005-03-26 rkolar We need to query filesize in advance, *
|
|
||||||
* because NBI loader do not reads file until *
|
|
||||||
* eof is reached.
|
|
||||||
* REMARKS *
|
|
||||||
* there is no support for selecting port number of fsp server, maybe *
|
|
||||||
* we should parse fsp:// URLs in boot image filename. *
|
|
||||||
* this implementation has filename limit 255 chars. *
|
|
||||||
\*********************************************************************/
|
|
||||||
|
|
||||||
#ifdef DOWNLOAD_PROTO_FSP
|
|
||||||
|
|
||||||
#define FSP_PORT 21
|
|
||||||
|
|
||||||
/* FSP commands */
|
|
||||||
#define CC_GET_FILE 0x42
|
|
||||||
#define CC_BYE 0x4A
|
|
||||||
#define CC_ERR 0x40
|
|
||||||
#define CC_STAT 0x4D
|
|
||||||
|
|
||||||
/* etherboot limits */
|
|
||||||
#define FSP_MAXFILENAME 255
|
|
||||||
|
|
||||||
struct fsp_info {
|
|
||||||
in_addr server_ip;
|
|
||||||
uint16_t server_port;
|
|
||||||
uint16_t local_port;
|
|
||||||
const char *filename;
|
|
||||||
int (*fnc)(unsigned char *, unsigned int, unsigned int, int);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fsp_header {
|
|
||||||
uint8_t cmd;
|
|
||||||
uint8_t sum;
|
|
||||||
uint16_t key;
|
|
||||||
uint16_t seq;
|
|
||||||
uint16_t len;
|
|
||||||
uint32_t pos;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
#define FSP_MAXPAYLOAD (ETH_MAX_MTU - \
|
|
||||||
(sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct fsp_header)))
|
|
||||||
|
|
||||||
static struct fsp_request {
|
|
||||||
struct iphdr ip;
|
|
||||||
struct udphdr udp;
|
|
||||||
struct fsp_header fsp;
|
|
||||||
unsigned char data[FSP_MAXFILENAME + 1 + 2];
|
|
||||||
} request;
|
|
||||||
|
|
||||||
struct fsp_reply {
|
|
||||||
struct iphdr ip;
|
|
||||||
struct udphdr udp;
|
|
||||||
struct fsp_header fsp;
|
|
||||||
unsigned char data[FSP_MAXPAYLOAD];
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
|
|
||||||
static int await_fsp(int ival, void *ptr, unsigned short ptype __unused,
|
|
||||||
struct iphdr *ip, struct udphdr *udp)
|
|
||||||
{
|
|
||||||
if(!udp)
|
|
||||||
return 0;
|
|
||||||
if (ip->dest.s_addr != arptable[ARP_CLIENT].ipaddr.s_addr)
|
|
||||||
return 0;
|
|
||||||
if (ntohs(udp->dest) != ival)
|
|
||||||
return 0;
|
|
||||||
if (ntohs(udp->len) < 12+sizeof(struct udphdr))
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int proto_fsp(struct fsp_info *info)
|
|
||||||
{
|
|
||||||
uint32_t filepos;
|
|
||||||
uint32_t filelength=0;
|
|
||||||
int i,retry;
|
|
||||||
uint16_t reqlen;
|
|
||||||
struct fsp_reply *reply;
|
|
||||||
int block=1;
|
|
||||||
|
|
||||||
/* prepare FSP request packet */
|
|
||||||
filepos=0;
|
|
||||||
i=strlen(info->filename);
|
|
||||||
if(i>FSP_MAXFILENAME)
|
|
||||||
{
|
|
||||||
printf("Boot filename is too long.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
strcpy(request.data,info->filename);
|
|
||||||
*(uint16_t *)(request.data+i+1)=htons(FSP_MAXPAYLOAD);
|
|
||||||
request.fsp.len=htons(i+1);
|
|
||||||
reqlen=i+3+12;
|
|
||||||
|
|
||||||
rx_qdrain();
|
|
||||||
retry=0;
|
|
||||||
|
|
||||||
/* main loop */
|
|
||||||
for(;;) {
|
|
||||||
int sum;
|
|
||||||
long timeout;
|
|
||||||
|
|
||||||
/* query filelength if not known */
|
|
||||||
if(filelength == 0)
|
|
||||||
request.fsp.cmd=CC_STAT;
|
|
||||||
|
|
||||||
/* prepare request packet */
|
|
||||||
request.fsp.pos=htonl(filepos);
|
|
||||||
request.fsp.seq=random();
|
|
||||||
request.fsp.sum=0;
|
|
||||||
for(i=0,sum=reqlen;i<reqlen;i++)
|
|
||||||
{
|
|
||||||
sum += ((uint8_t *)&request.fsp)[i];
|
|
||||||
}
|
|
||||||
request.fsp.sum= sum + (sum >> 8);
|
|
||||||
/* send request */
|
|
||||||
if (!udp_transmit(info->server_ip.s_addr, info->local_port,
|
|
||||||
info->server_port, sizeof(request.ip) +
|
|
||||||
sizeof(request.udp) + reqlen, &request))
|
|
||||||
return (0);
|
|
||||||
/* wait for retry */
|
|
||||||
#ifdef CONGESTED
|
|
||||||
timeout =
|
|
||||||
rfc2131_sleep_interval(filepos ? TFTP_REXMT : TIMEOUT, retry);
|
|
||||||
#else
|
|
||||||
timeout = rfc2131_sleep_interval(TIMEOUT, retry);
|
|
||||||
#endif
|
|
||||||
retry++;
|
|
||||||
if (!await_reply(await_fsp, info->local_port, NULL, timeout))
|
|
||||||
continue;
|
|
||||||
reply=(struct fsp_reply *) &nic.packet[ETH_HLEN];
|
|
||||||
/* check received packet */
|
|
||||||
if (reply->fsp.seq != request.fsp.seq)
|
|
||||||
continue;
|
|
||||||
reply->udp.len=ntohs(reply->udp.len)-sizeof(struct udphdr);
|
|
||||||
if(reply->udp.len < ntohs(reply->fsp.len) + 12 )
|
|
||||||
continue;
|
|
||||||
sum=-reply->fsp.sum;
|
|
||||||
for(i=0;i<reply->udp.len;i++)
|
|
||||||
{
|
|
||||||
sum += ((uint8_t *)&(reply->fsp))[i];
|
|
||||||
}
|
|
||||||
sum = (sum + (sum >> 8)) & 0xff;
|
|
||||||
if(sum != reply->fsp.sum)
|
|
||||||
{
|
|
||||||
printf("FSP checksum failed. computed %d, but packet has %d.\n",sum,reply->fsp.sum);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(reply->fsp.cmd == CC_ERR)
|
|
||||||
{
|
|
||||||
printf("\nFSP error: %s",info->filename);
|
|
||||||
if(reply->fsp.len)
|
|
||||||
printf(" [%s]",reply->data);
|
|
||||||
printf("\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(reply->fsp.cmd == CC_BYE && filelength == 1)
|
|
||||||
{
|
|
||||||
info->fnc(request.data,block,1,1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(reply->fsp.cmd == CC_STAT)
|
|
||||||
{
|
|
||||||
if(reply->data[8] == 0)
|
|
||||||
{
|
|
||||||
/* file not found, etc. */
|
|
||||||
filelength=0xffffffff;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
filelength= ntohl(*((uint32_t *)&reply->data[4]));
|
|
||||||
}
|
|
||||||
request.fsp.cmd = CC_GET_FILE;
|
|
||||||
request.fsp.key = reply->fsp.key;
|
|
||||||
retry=0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(reply->fsp.cmd == CC_GET_FILE)
|
|
||||||
{
|
|
||||||
if(ntohl(reply->fsp.pos) != filepos)
|
|
||||||
continue;
|
|
||||||
request.fsp.key = reply->fsp.key;
|
|
||||||
retry=0;
|
|
||||||
i=ntohs(reply->fsp.len);
|
|
||||||
if(i == 1)
|
|
||||||
{
|
|
||||||
request.fsp.cmd=CC_BYE;
|
|
||||||
request.data[0]=reply->data[0];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* let last byte alone */
|
|
||||||
if(i >= filelength)
|
|
||||||
i = filelength - 1;
|
|
||||||
if(!info->fnc(reply->data,block++,i,0))
|
|
||||||
return 0;
|
|
||||||
filepos += i;
|
|
||||||
filelength -= i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int url_fsp(const char *name, int (*fnc)(unsigned char *, unsigned int, unsigned int, int))
|
|
||||||
{
|
|
||||||
struct fsp_info info;
|
|
||||||
/* Set the defaults */
|
|
||||||
info.server_ip.s_addr = arptable[ARP_SERVER].ipaddr.s_addr;
|
|
||||||
info.server_port = FSP_PORT;
|
|
||||||
info.local_port = 1024 + random() & 0xfbff;
|
|
||||||
info.fnc = fnc;
|
|
||||||
|
|
||||||
/* Now parse the url */
|
|
||||||
/* printf("fsp-URI: [%s]\n", name); */
|
|
||||||
/* quick hack for now */
|
|
||||||
info.filename=name;
|
|
||||||
return proto_fsp(&info);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
/*
|
|
||||||
* Eric Biederman wrote this code originally.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
#include <ip.h>
|
|
||||||
#include <igmp.h>
|
|
||||||
|
|
||||||
static unsigned long last_igmpv1 = 0;
|
|
||||||
static struct igmptable_t igmptable[MAX_IGMP];
|
|
||||||
|
|
||||||
static long rfc1112_sleep_interval ( long base, int exp ) {
|
|
||||||
unsigned long divisor, tmo;
|
|
||||||
|
|
||||||
if ( exp > BACKOFF_LIMIT )
|
|
||||||
exp = BACKOFF_LIMIT;
|
|
||||||
divisor = RAND_MAX / ( base << exp );
|
|
||||||
tmo = random() / divisor;
|
|
||||||
return tmo;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void send_igmp_reports ( unsigned long now ) {
|
|
||||||
struct igmp_ip_t igmp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for ( i = 0 ; i < MAX_IGMP ; i++ ) {
|
|
||||||
if ( ! igmptable[i].time )
|
|
||||||
continue;
|
|
||||||
if ( now < igmptable[i].time )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
igmp.router_alert[0] = 0x94;
|
|
||||||
igmp.router_alert[1] = 0x04;
|
|
||||||
igmp.router_alert[2] = 0;
|
|
||||||
igmp.router_alert[3] = 0;
|
|
||||||
build_ip_hdr ( igmptable[i].group.s_addr, 1, IP_IGMP,
|
|
||||||
sizeof ( igmp.router_alert ),
|
|
||||||
sizeof ( igmp ), &igmp );
|
|
||||||
igmp.igmp.type = IGMPv2_REPORT;
|
|
||||||
if ( last_igmpv1 &&
|
|
||||||
( now < last_igmpv1 + IGMPv1_ROUTER_PRESENT_TIMEOUT ) ) {
|
|
||||||
igmp.igmp.type = IGMPv1_REPORT;
|
|
||||||
}
|
|
||||||
igmp.igmp.response_time = 0;
|
|
||||||
igmp.igmp.chksum = 0;
|
|
||||||
igmp.igmp.group.s_addr = igmptable[i].group.s_addr;
|
|
||||||
igmp.igmp.chksum = ipchksum ( &igmp.igmp,
|
|
||||||
sizeof ( igmp.igmp ) );
|
|
||||||
ip_transmit ( sizeof ( igmp ), &igmp );
|
|
||||||
DBG ( "IGMP sent report to %s\n", inet_ntoa ( igmp.igmp.group ) );
|
|
||||||
/* Don't send another igmp report until asked */
|
|
||||||
igmptable[i].time = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void process_igmp ( unsigned long now, unsigned short ptype __unused,
|
|
||||||
struct iphdr *ip ) {
|
|
||||||
struct igmp *igmp;
|
|
||||||
int i;
|
|
||||||
unsigned iplen;
|
|
||||||
|
|
||||||
if ( ( ! ip ) || ( ip->protocol != IP_IGMP ) ||
|
|
||||||
( nic.packetlen < ( sizeof ( struct iphdr ) +
|
|
||||||
sizeof ( struct igmp ) ) ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
iplen = ( ip->verhdrlen & 0xf ) * 4;
|
|
||||||
igmp = ( struct igmp * ) &nic.packet[ sizeof( struct iphdr ) ];
|
|
||||||
if ( ipchksum ( igmp, ntohs ( ip->len ) - iplen ) != 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( ( igmp->type == IGMP_QUERY ) &&
|
|
||||||
( ip->dest.s_addr == htonl ( GROUP_ALL_HOSTS ) ) ) {
|
|
||||||
unsigned long interval = IGMP_INTERVAL;
|
|
||||||
|
|
||||||
if ( igmp->response_time == 0 ) {
|
|
||||||
last_igmpv1 = now;
|
|
||||||
} else {
|
|
||||||
interval = ( igmp->response_time * TICKS_PER_SEC ) /10;
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG ( "IGMP received query for %s\n", inet_ntoa ( igmp->group ) );
|
|
||||||
for ( i = 0 ; i < MAX_IGMP ; i++ ) {
|
|
||||||
uint32_t group = igmptable[i].group.s_addr;
|
|
||||||
if ( ( group == 0 ) ||
|
|
||||||
( group == igmp->group.s_addr ) ) {
|
|
||||||
unsigned long time;
|
|
||||||
time = currticks() +
|
|
||||||
rfc1112_sleep_interval ( interval, 0 );
|
|
||||||
if ( time < igmptable[i].time ) {
|
|
||||||
igmptable[i].time = time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( ( ( igmp->type == IGMPv1_REPORT ) ||
|
|
||||||
( igmp->type == IGMPv2_REPORT ) ) &&
|
|
||||||
( ip->dest.s_addr == igmp->group.s_addr ) ) {
|
|
||||||
DBG ( "IGMP received report for %s\n",
|
|
||||||
inet_ntoa ( igmp->group ) );
|
|
||||||
for ( i = 0 ; i < MAX_IGMP ; i++ ) {
|
|
||||||
if ( ( igmptable[i].group.s_addr ==
|
|
||||||
igmp->group.s_addr ) &&
|
|
||||||
( igmptable[i].time != 0 ) ) {
|
|
||||||
igmptable[i].time = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct background igmp_background __background = {
|
|
||||||
.send = send_igmp_reports,
|
|
||||||
.process = process_igmp,
|
|
||||||
};
|
|
||||||
|
|
||||||
void leave_group ( int slot ) {
|
|
||||||
/* Be very stupid and always send a leave group message if
|
|
||||||
* I have subscribed. Imperfect but it is standards
|
|
||||||
* compliant, easy and reliable to implement.
|
|
||||||
*
|
|
||||||
* The optimal group leave method is to only send leave when,
|
|
||||||
* we were the last host to respond to a query on this group,
|
|
||||||
* and igmpv1 compatibility is not enabled.
|
|
||||||
*/
|
|
||||||
if ( igmptable[slot].group.s_addr ) {
|
|
||||||
struct igmp_ip_t igmp;
|
|
||||||
|
|
||||||
igmp.router_alert[0] = 0x94;
|
|
||||||
igmp.router_alert[1] = 0x04;
|
|
||||||
igmp.router_alert[2] = 0;
|
|
||||||
igmp.router_alert[3] = 0;
|
|
||||||
build_ip_hdr ( htonl ( GROUP_ALL_HOSTS ), 1, IP_IGMP,
|
|
||||||
sizeof ( igmp.router_alert ), sizeof ( igmp ),
|
|
||||||
&igmp);
|
|
||||||
igmp.igmp.type = IGMP_LEAVE;
|
|
||||||
igmp.igmp.response_time = 0;
|
|
||||||
igmp.igmp.chksum = 0;
|
|
||||||
igmp.igmp.group.s_addr = igmptable[slot].group.s_addr;
|
|
||||||
igmp.igmp.chksum = ipchksum ( &igmp.igmp, sizeof ( igmp ) );
|
|
||||||
ip_transmit ( sizeof ( igmp ), &igmp );
|
|
||||||
DBG ( "IGMP left group %s\n", inet_ntoa ( igmp.igmp.group ) );
|
|
||||||
}
|
|
||||||
memset ( &igmptable[slot], 0, sizeof ( igmptable[0] ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void join_group ( int slot, unsigned long group ) {
|
|
||||||
/* I have already joined */
|
|
||||||
if ( igmptable[slot].group.s_addr == group )
|
|
||||||
return;
|
|
||||||
if ( igmptable[slot].group.s_addr ) {
|
|
||||||
leave_group ( slot );
|
|
||||||
}
|
|
||||||
/* Only join a group if we are given a multicast ip, this way
|
|
||||||
* code can be given a non-multicast (broadcast or unicast ip)
|
|
||||||
* and still work...
|
|
||||||
*/
|
|
||||||
if ( ( group & htonl ( MULTICAST_MASK ) ) ==
|
|
||||||
htonl ( MULTICAST_NETWORK ) ) {
|
|
||||||
igmptable[slot].group.s_addr = group;
|
|
||||||
igmptable[slot].time = currticks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-616
@@ -1,616 +0,0 @@
|
|||||||
#if 0
|
|
||||||
|
|
||||||
#include <gpxe/init.h>
|
|
||||||
#include <gpxe/in.h>
|
|
||||||
|
|
||||||
/* NOTE: the NFS code is heavily inspired by the NetBSD netboot code (read:
|
|
||||||
* large portions are copied verbatim) as distributed in OSKit 0.97. A few
|
|
||||||
* changes were necessary to adapt the code to Etherboot and to fix several
|
|
||||||
* inconsistencies. Also the RPC message preparation is done "by hand" to
|
|
||||||
* avoid adding netsprintf() which I find hard to understand and use. */
|
|
||||||
|
|
||||||
/* NOTE 2: Etherboot does not care about things beyond the kernel image, so
|
|
||||||
* it loads the kernel image off the boot server (ARP_SERVER) and does not
|
|
||||||
* access the client root disk (root-path in dhcpd.conf), which would use
|
|
||||||
* ARP_ROOTSERVER. The root disk is something the operating system we are
|
|
||||||
* about to load needs to use. This is different from the OSKit 0.97 logic. */
|
|
||||||
|
|
||||||
/* NOTE 3: Symlink handling introduced by Anselm M Hoffmeister, 2003-July-14
|
|
||||||
* If a symlink is encountered, it is followed as far as possible (recursion
|
|
||||||
* possible, maximum 16 steps). There is no clearing of ".."'s inside the
|
|
||||||
* path, so please DON'T DO THAT. thx. */
|
|
||||||
|
|
||||||
#define START_OPORT 700 /* mountd usually insists on secure ports */
|
|
||||||
#define OPORT_SWEEP 200 /* make sure we don't leave secure range */
|
|
||||||
|
|
||||||
static int oport = START_OPORT;
|
|
||||||
static struct sockaddr_in mount_server;
|
|
||||||
static struct sockaddr_in nfs_server;
|
|
||||||
static unsigned long rpc_id;
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
RPC_INIT - set up the ID counter to something fairly random
|
|
||||||
**************************************************************************/
|
|
||||||
void rpc_init(void)
|
|
||||||
{
|
|
||||||
unsigned long t;
|
|
||||||
|
|
||||||
t = currticks();
|
|
||||||
rpc_id = t ^ (t << 8) ^ (t << 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
RPC_PRINTERROR - Print a low level RPC error message
|
|
||||||
**************************************************************************/
|
|
||||||
static void rpc_printerror(struct rpc_t *rpc)
|
|
||||||
{
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus) {
|
|
||||||
/* rpc_printerror() is called for any RPC related error,
|
|
||||||
* suppress output if no low level RPC error happened. */
|
|
||||||
DBG("RPC error: (%ld,%ld,%ld)\n", ntohl(rpc->u.reply.rstatus),
|
|
||||||
ntohl(rpc->u.reply.verifier),
|
|
||||||
ntohl(rpc->u.reply.astatus));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
AWAIT_RPC - Wait for an rpc packet
|
|
||||||
**************************************************************************/
|
|
||||||
static int await_rpc(int ival, void *ptr,
|
|
||||||
unsigned short ptype __unused, struct iphdr *ip,
|
|
||||||
struct udphdr *udp, struct tcphdr *tcp __unused)
|
|
||||||
{
|
|
||||||
struct rpc_t *rpc;
|
|
||||||
if (!udp)
|
|
||||||
return 0;
|
|
||||||
if (arptable[ARP_CLIENT].ipaddr.s_addr != ip->dest.s_addr)
|
|
||||||
return 0;
|
|
||||||
if (ntohs(udp->dest) != ival)
|
|
||||||
return 0;
|
|
||||||
if (nic.packetlen < ETH_HLEN + sizeof(struct iphdr) + sizeof(struct udphdr) + 8)
|
|
||||||
return 0;
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (*(unsigned long *)ptr != ntohl(rpc->u.reply.id))
|
|
||||||
return 0;
|
|
||||||
if (MSG_REPLY != ntohl(rpc->u.reply.type))
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
RPC_LOOKUP - Lookup RPC Port numbers
|
|
||||||
**************************************************************************/
|
|
||||||
static int rpc_lookup(struct sockaddr_in *addr, int prog, int ver, int sport)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
int retries;
|
|
||||||
long *p;
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_PORTMAP);
|
|
||||||
buf.u.call.vers = htonl(2); /* portmapper is version 2 */
|
|
||||||
buf.u.call.proc = htonl(PORTMAP_GETPORT);
|
|
||||||
p = (long *)buf.u.call.data;
|
|
||||||
*p++ = 0; *p++ = 0; /* auth credential */
|
|
||||||
*p++ = 0; *p++ = 0; /* auth verifier */
|
|
||||||
*p++ = htonl(prog);
|
|
||||||
*p++ = htonl(ver);
|
|
||||||
*p++ = htonl(IP_UDP);
|
|
||||||
*p++ = 0;
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout;
|
|
||||||
udp_transmit(addr->sin_addr.s_addr, sport, addr->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
if (await_reply(await_rpc, sport, &id, timeout)) {
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return ntohl(rpc->u.reply.data[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
|
|
||||||
**************************************************************************/
|
|
||||||
static long *rpc_add_credentials(long *p)
|
|
||||||
{
|
|
||||||
int hl;
|
|
||||||
|
|
||||||
/* Here's the executive summary on authentication requirements of the
|
|
||||||
* various NFS server implementations: Linux accepts both AUTH_NONE
|
|
||||||
* and AUTH_UNIX authentication (also accepts an empty hostname field
|
|
||||||
* in the AUTH_UNIX scheme). *BSD refuses AUTH_NONE, but accepts
|
|
||||||
* AUTH_UNIX (also accepts an empty hostname field in the AUTH_UNIX
|
|
||||||
* scheme). To be safe, use AUTH_UNIX and pass the hostname if we have
|
|
||||||
* it (if the BOOTP/DHCP reply didn't give one, just use an empty
|
|
||||||
* hostname). */
|
|
||||||
|
|
||||||
hl = (hostnamelen + 3) & ~3;
|
|
||||||
|
|
||||||
/* Provide an AUTH_UNIX credential. */
|
|
||||||
*p++ = htonl(1); /* AUTH_UNIX */
|
|
||||||
*p++ = htonl(hl+20); /* auth length */
|
|
||||||
*p++ = htonl(0); /* stamp */
|
|
||||||
*p++ = htonl(hostnamelen); /* hostname string */
|
|
||||||
if (hostnamelen & 3) {
|
|
||||||
*(p + hostnamelen / 4) = 0; /* add zero padding */
|
|
||||||
}
|
|
||||||
memcpy(p, hostname, hostnamelen);
|
|
||||||
p += hl / 4;
|
|
||||||
*p++ = 0; /* uid */
|
|
||||||
*p++ = 0; /* gid */
|
|
||||||
*p++ = 0; /* auxiliary gid list */
|
|
||||||
|
|
||||||
/* Provide an AUTH_NONE verifier. */
|
|
||||||
*p++ = 0; /* AUTH_NONE */
|
|
||||||
*p++ = 0; /* auth length */
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_PRINTERROR - Print a NFS error message
|
|
||||||
**************************************************************************/
|
|
||||||
static void nfs_printerror(int err)
|
|
||||||
{
|
|
||||||
switch (-err) {
|
|
||||||
case NFSERR_PERM:
|
|
||||||
printf("Not owner\n");
|
|
||||||
break;
|
|
||||||
case NFSERR_NOENT:
|
|
||||||
printf("No such file or directory\n");
|
|
||||||
break;
|
|
||||||
case NFSERR_ACCES:
|
|
||||||
printf("Permission denied\n");
|
|
||||||
break;
|
|
||||||
case NFSERR_ISDIR:
|
|
||||||
printf("Directory given where filename expected\n");
|
|
||||||
break;
|
|
||||||
case NFSERR_INVAL:
|
|
||||||
printf("Invalid filehandle\n");
|
|
||||||
break; // INVAL is not defined in NFSv2, some NFS-servers
|
|
||||||
// seem to use it in answers to v2 nevertheless.
|
|
||||||
case 9998:
|
|
||||||
printf("low-level RPC failure (parameter decoding problem?)\n");
|
|
||||||
break;
|
|
||||||
case 9999:
|
|
||||||
printf("low-level RPC failure (authentication problem?)\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("Unknown NFS error %d\n", -err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_MOUNT - Mount an NFS Filesystem
|
|
||||||
**************************************************************************/
|
|
||||||
static int nfs_mount(struct sockaddr_in *server, char *path, char *fh, int sport)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
int retries;
|
|
||||||
long *p;
|
|
||||||
int pathlen = strlen(path);
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_MOUNT);
|
|
||||||
buf.u.call.vers = htonl(1); /* mountd is version 1 */
|
|
||||||
buf.u.call.proc = htonl(MOUNT_ADDENTRY);
|
|
||||||
p = rpc_add_credentials((long *)buf.u.call.data);
|
|
||||||
*p++ = htonl(pathlen);
|
|
||||||
if (pathlen & 3) {
|
|
||||||
*(p + pathlen / 4) = 0; /* add zero padding */
|
|
||||||
}
|
|
||||||
memcpy(p, path, pathlen);
|
|
||||||
p += (pathlen + 3) / 4;
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout;
|
|
||||||
udp_transmit(server->sin_addr.s_addr, sport, server->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
if (await_reply(await_rpc, sport, &id, timeout)) {
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus || rpc->u.reply.data[0]) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
if (rpc->u.reply.rstatus) {
|
|
||||||
/* RPC failed, no verifier, data[0] */
|
|
||||||
return -9999;
|
|
||||||
}
|
|
||||||
if (rpc->u.reply.astatus) {
|
|
||||||
/* RPC couldn't decode parameters */
|
|
||||||
return -9998;
|
|
||||||
}
|
|
||||||
return -ntohl(rpc->u.reply.data[0]);
|
|
||||||
} else {
|
|
||||||
memcpy(fh, rpc->u.reply.data + 1, NFS_FHSIZE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
|
|
||||||
**************************************************************************/
|
|
||||||
static void nfs_umountall(struct sockaddr_in *server)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
int retries;
|
|
||||||
long *p;
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_MOUNT);
|
|
||||||
buf.u.call.vers = htonl(1); /* mountd is version 1 */
|
|
||||||
buf.u.call.proc = htonl(MOUNT_UMOUNTALL);
|
|
||||||
p = rpc_add_credentials((long *)buf.u.call.data);
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
udp_transmit(server->sin_addr.s_addr, oport, server->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
if (await_reply(await_rpc, oport, &id, timeout)) {
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_RESET - Reset the NFS subsystem
|
|
||||||
**************************************************************************/
|
|
||||||
static void nfs_reset ( void ) {
|
|
||||||
/* If we have a mount server, call nfs_umountall() */
|
|
||||||
if ( mount_server.sin_addr.s_addr ) {
|
|
||||||
nfs_umountall ( &mount_server );
|
|
||||||
}
|
|
||||||
/* Zero the data structures */
|
|
||||||
memset ( &mount_server, 0, sizeof ( mount_server ) );
|
|
||||||
memset ( &nfs_server, 0, sizeof ( nfs_server ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
* NFS_READLINK (AH 2003-07-14)
|
|
||||||
* This procedure is called when read of the first block fails -
|
|
||||||
* this probably happens when it's a directory or a symlink
|
|
||||||
* In case of successful readlink(), the dirname is manipulated,
|
|
||||||
* so that inside the nfs() function a recursion can be done.
|
|
||||||
**************************************************************************/
|
|
||||||
static int nfs_readlink(struct sockaddr_in *server, char *fh __unused,
|
|
||||||
char *path, char *nfh, int sport)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
long *p;
|
|
||||||
int retries;
|
|
||||||
int pathlen = strlen(path);
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_NFS);
|
|
||||||
buf.u.call.vers = htonl(2); /* nfsd is version 2 */
|
|
||||||
buf.u.call.proc = htonl(NFS_READLINK);
|
|
||||||
p = rpc_add_credentials((long *)buf.u.call.data);
|
|
||||||
memcpy(p, nfh, NFS_FHSIZE);
|
|
||||||
p += (NFS_FHSIZE / 4);
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
udp_transmit(server->sin_addr.s_addr, sport, server->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
if (await_reply(await_rpc, sport, &id, timeout)) {
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus || rpc->u.reply.data[0]) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
if (rpc->u.reply.rstatus) {
|
|
||||||
/* RPC failed, no verifier, data[0] */
|
|
||||||
return -9999;
|
|
||||||
}
|
|
||||||
if (rpc->u.reply.astatus) {
|
|
||||||
/* RPC couldn't decode parameters */
|
|
||||||
return -9998;
|
|
||||||
}
|
|
||||||
return -ntohl(rpc->u.reply.data[0]);
|
|
||||||
} else {
|
|
||||||
// It *is* a link.
|
|
||||||
// If it's a relative link, append everything to dirname, filename TOO!
|
|
||||||
retries = strlen ( (char *)(&(rpc->u.reply.data[2]) ));
|
|
||||||
if ( *((char *)(&(rpc->u.reply.data[2]))) != '/' ) {
|
|
||||||
path[pathlen++] = '/';
|
|
||||||
while ( ( retries + pathlen ) > 298 ) {
|
|
||||||
retries--;
|
|
||||||
}
|
|
||||||
if ( retries > 0 ) {
|
|
||||||
memcpy(path + pathlen, &(rpc->u.reply.data[2]), retries + 1);
|
|
||||||
} else { retries = 0; }
|
|
||||||
path[pathlen + retries] = 0;
|
|
||||||
} else {
|
|
||||||
// Else make it the only path.
|
|
||||||
if ( retries > 298 ) { retries = 298; }
|
|
||||||
memcpy ( path, &(rpc->u.reply.data[2]), retries + 1 );
|
|
||||||
path[retries] = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_LOOKUP - Lookup Pathname
|
|
||||||
**************************************************************************/
|
|
||||||
static int nfs_lookup(struct sockaddr_in *server, char *fh, char *path, char *nfh,
|
|
||||||
int sport)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
long *p;
|
|
||||||
int retries;
|
|
||||||
int pathlen = strlen(path);
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_NFS);
|
|
||||||
buf.u.call.vers = htonl(2); /* nfsd is version 2 */
|
|
||||||
buf.u.call.proc = htonl(NFS_LOOKUP);
|
|
||||||
p = rpc_add_credentials((long *)buf.u.call.data);
|
|
||||||
memcpy(p, fh, NFS_FHSIZE);
|
|
||||||
p += (NFS_FHSIZE / 4);
|
|
||||||
*p++ = htonl(pathlen);
|
|
||||||
if (pathlen & 3) {
|
|
||||||
*(p + pathlen / 4) = 0; /* add zero padding */
|
|
||||||
}
|
|
||||||
memcpy(p, path, pathlen);
|
|
||||||
p += (pathlen + 3) / 4;
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
udp_transmit(server->sin_addr.s_addr, sport, server->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
if (await_reply(await_rpc, sport, &id, timeout)) {
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus || rpc->u.reply.data[0]) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
if (rpc->u.reply.rstatus) {
|
|
||||||
/* RPC failed, no verifier, data[0] */
|
|
||||||
return -9999;
|
|
||||||
}
|
|
||||||
if (rpc->u.reply.astatus) {
|
|
||||||
/* RPC couldn't decode parameters */
|
|
||||||
return -9998;
|
|
||||||
}
|
|
||||||
return -ntohl(rpc->u.reply.data[0]);
|
|
||||||
} else {
|
|
||||||
memcpy(nfh, rpc->u.reply.data + 1, NFS_FHSIZE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS_READ - Read File on NFS Server
|
|
||||||
**************************************************************************/
|
|
||||||
static int nfs_read(struct sockaddr_in *server, char *fh, int offset, int len,
|
|
||||||
int sport)
|
|
||||||
{
|
|
||||||
struct rpc_t buf, *rpc;
|
|
||||||
unsigned long id;
|
|
||||||
int retries;
|
|
||||||
long *p;
|
|
||||||
|
|
||||||
static int tokens=0;
|
|
||||||
/*
|
|
||||||
* Try to implement something similar to a window protocol in
|
|
||||||
* terms of response to losses. On successful receive, increment
|
|
||||||
* the number of tokens by 1 (cap at 256). On failure, halve it.
|
|
||||||
* When the number of tokens is >= 2, use a very short timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
id = rpc_id++;
|
|
||||||
buf.u.call.id = htonl(id);
|
|
||||||
buf.u.call.type = htonl(MSG_CALL);
|
|
||||||
buf.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
||||||
buf.u.call.prog = htonl(PROG_NFS);
|
|
||||||
buf.u.call.vers = htonl(2); /* nfsd is version 2 */
|
|
||||||
buf.u.call.proc = htonl(NFS_READ);
|
|
||||||
p = rpc_add_credentials((long *)buf.u.call.data);
|
|
||||||
memcpy(p, fh, NFS_FHSIZE);
|
|
||||||
p += NFS_FHSIZE / 4;
|
|
||||||
*p++ = htonl(offset);
|
|
||||||
*p++ = htonl(len);
|
|
||||||
*p++ = 0; /* unused parameter */
|
|
||||||
for (retries = 0; retries < MAX_RPC_RETRIES; retries++) {
|
|
||||||
long timeout = rfc2131_sleep_interval(TIMEOUT, retries);
|
|
||||||
if (tokens >= 2)
|
|
||||||
timeout = TICKS_PER_SEC/2;
|
|
||||||
|
|
||||||
udp_transmit(server->sin_addr.s_addr, sport, server->sin_port,
|
|
||||||
(char *)p - (char *)&buf, &buf);
|
|
||||||
if (await_reply(await_rpc, sport, &id, timeout)) {
|
|
||||||
if (tokens < 256)
|
|
||||||
tokens++;
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
|
|
||||||
rpc->u.reply.astatus || rpc->u.reply.data[0]) {
|
|
||||||
rpc_printerror(rpc);
|
|
||||||
if (rpc->u.reply.rstatus) {
|
|
||||||
/* RPC failed, no verifier, data[0] */
|
|
||||||
return -9999;
|
|
||||||
}
|
|
||||||
if (rpc->u.reply.astatus) {
|
|
||||||
/* RPC couldn't decode parameters */
|
|
||||||
return -9998;
|
|
||||||
}
|
|
||||||
return -ntohl(rpc->u.reply.data[0]);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
tokens >>= 1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
NFS - Download extended BOOTP data, or kernel image from NFS server
|
|
||||||
**************************************************************************/
|
|
||||||
static int nfs ( char *url __unused, struct sockaddr_in *server,
|
|
||||||
char *name, struct buffer *buffer ) {
|
|
||||||
static int recursion = 0;
|
|
||||||
int sport;
|
|
||||||
int err, namelen = strlen(name);
|
|
||||||
char dirname[300], *fname;
|
|
||||||
char dirfh[NFS_FHSIZE]; /* file handle of directory */
|
|
||||||
char filefh[NFS_FHSIZE]; /* file handle of kernel image */
|
|
||||||
int rlen, size, offs, len;
|
|
||||||
struct rpc_t *rpc;
|
|
||||||
|
|
||||||
sport = oport++;
|
|
||||||
if (oport > START_OPORT+OPORT_SWEEP) {
|
|
||||||
oport = START_OPORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_server.sin_addr = nfs_server.sin_addr = server->sin_addr;
|
|
||||||
mount_server.sin_port = rpc_lookup(server, PROG_MOUNT, 1, sport);
|
|
||||||
if ( ! mount_server.sin_port ) {
|
|
||||||
DBG ( "Cannot get mount port from %s:%d\n",
|
|
||||||
inet_ntoa ( server->sin_addr ), server->sin_port );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
nfs_server.sin_port = rpc_lookup(server, PROG_NFS, 2, sport);
|
|
||||||
if ( ! mount_server.sin_port ) {
|
|
||||||
DBG ( "Cannot get nfs port from %s:%d\n",
|
|
||||||
inet_ntoa ( server->sin_addr ), server->sin_port );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name != dirname ) {
|
|
||||||
memcpy(dirname, name, namelen + 1);
|
|
||||||
}
|
|
||||||
recursion = 0;
|
|
||||||
nfssymlink:
|
|
||||||
if ( recursion > NFS_MAXLINKDEPTH ) {
|
|
||||||
DBG ( "\nRecursion: More than %d symlinks followed. Abort.\n",
|
|
||||||
NFS_MAXLINKDEPTH );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
recursion++;
|
|
||||||
fname = dirname + (namelen - 1);
|
|
||||||
while (fname >= dirname) {
|
|
||||||
if (*fname == '/') {
|
|
||||||
*fname = '\0';
|
|
||||||
fname++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fname--;
|
|
||||||
}
|
|
||||||
if (fname < dirname) {
|
|
||||||
DBG("can't parse file name %s\n", name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = nfs_mount(&mount_server, dirname, dirfh, sport);
|
|
||||||
if (err) {
|
|
||||||
DBG("mounting %s: ", dirname);
|
|
||||||
nfs_printerror(err);
|
|
||||||
/* just to be sure... */
|
|
||||||
nfs_reset();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = nfs_lookup(&nfs_server, dirfh, fname, filefh, sport);
|
|
||||||
if (err) {
|
|
||||||
DBG("looking up %s: ", fname);
|
|
||||||
nfs_printerror(err);
|
|
||||||
nfs_reset();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
offs = 0;
|
|
||||||
size = -1; /* will be set properly with the first reply */
|
|
||||||
len = NFS_READ_SIZE; /* first request is always full size */
|
|
||||||
do {
|
|
||||||
err = nfs_read(&nfs_server, filefh, offs, len, sport);
|
|
||||||
if ((err <= -NFSERR_ISDIR)&&(err >= -NFSERR_INVAL) && (offs == 0)) {
|
|
||||||
// An error occured. NFS servers tend to sending
|
|
||||||
// errors 21 / 22 when symlink instead of real file
|
|
||||||
// is requested. So check if it's a symlink!
|
|
||||||
if ( nfs_readlink(&nfs_server, dirfh, dirname,
|
|
||||||
filefh, sport) == 0 ) {
|
|
||||||
printf("\nLoading symlink:%s ..",dirname);
|
|
||||||
goto nfssymlink;
|
|
||||||
}
|
|
||||||
nfs_printerror(err);
|
|
||||||
nfs_reset();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (err) {
|
|
||||||
printf("\nError reading at offset %d: ", offs);
|
|
||||||
nfs_printerror(err);
|
|
||||||
nfs_reset();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc = (struct rpc_t *)&nic.packet[ETH_HLEN];
|
|
||||||
|
|
||||||
/* size must be found out early to allow EOF detection */
|
|
||||||
if (size == -1) {
|
|
||||||
size = ntohl(rpc->u.reply.data[6]);
|
|
||||||
}
|
|
||||||
rlen = ntohl(rpc->u.reply.data[18]);
|
|
||||||
if (rlen > len) {
|
|
||||||
rlen = len; /* shouldn't happen... */
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! fill_buffer ( buffer, &rpc->u.reply.data[19],
|
|
||||||
offs, rlen ) ) {
|
|
||||||
nfs_reset();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
offs += rlen;
|
|
||||||
/* last request is done with matching requested read size */
|
|
||||||
if (size-offs < NFS_READ_SIZE) {
|
|
||||||
len = size-offs;
|
|
||||||
}
|
|
||||||
} while (len != 0);
|
|
||||||
/* len == 0 means that all the file has been read */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct protocol nfs_protocol __protocol = {
|
|
||||||
.name = "nfs",
|
|
||||||
.default_port = SUNRPC_PORT,
|
|
||||||
.load = nfs,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-110
@@ -1,110 +0,0 @@
|
|||||||
#if 0
|
|
||||||
|
|
||||||
#include "resolv.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include <gpxe/dns.h>
|
|
||||||
#include "nic.h"
|
|
||||||
#include "nmb.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert a standard NUL-terminated string to an NBNS query name.
|
|
||||||
*
|
|
||||||
* Returns a pointer to the character following the constructed NBNS
|
|
||||||
* query name.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static inline char * nbns_make_name ( char *dest, const char *name ) {
|
|
||||||
char nb_name[16];
|
|
||||||
char c;
|
|
||||||
int i;
|
|
||||||
uint16_t *d;
|
|
||||||
|
|
||||||
*(dest++) = 32; /* Length is always 32 */
|
|
||||||
|
|
||||||
/* Name encoding is as follows: pad the name with spaces to
|
|
||||||
* length 15, and add a NUL. Take this 16-byte string, split
|
|
||||||
* it into nibbles and add 0x41 to each nibble to form a byte
|
|
||||||
* of the resulting name string.
|
|
||||||
*/
|
|
||||||
memset ( nb_name, ' ', 15 );
|
|
||||||
nb_name[15] = '\0';
|
|
||||||
memcpy ( nb_name, name, strlen ( name ) ); /* Do not copy NUL */
|
|
||||||
|
|
||||||
d = ( uint16_t * ) dest;
|
|
||||||
for ( i = 0 ; i < 16 ; i++ ) {
|
|
||||||
c = nb_name[i];
|
|
||||||
*( d++ ) = htons ( ( ( c | ( c << 4 ) ) & 0x0f0f ) + 0x4141 );
|
|
||||||
}
|
|
||||||
dest = ( char * ) d;
|
|
||||||
|
|
||||||
*(dest++) = 0; /* Terminating 0-length name component */
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Resolve a name using NMB
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static int nmb_resolv ( struct in_addr *addr, const char *name ) {
|
|
||||||
struct dns_query query;
|
|
||||||
struct dns_query_info *query_info;
|
|
||||||
struct dns_header *reply;
|
|
||||||
struct dns_rr_info *rr_info;
|
|
||||||
struct dns_rr_info_nb *rr_info_nb;
|
|
||||||
struct sockaddr_in nameserver;
|
|
||||||
|
|
||||||
DBG ( "NMB resolving %s\n", name );
|
|
||||||
|
|
||||||
/* Set up the query data */
|
|
||||||
nameserver.sin_addr.s_addr = INADDR_BROADCAST;
|
|
||||||
nameserver.sin_port = NBNS_UDP_PORT;
|
|
||||||
memset ( &query, 0, sizeof ( query ) );
|
|
||||||
query.dns.id = htons ( 1 );
|
|
||||||
query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY |
|
|
||||||
DNS_FLAG_RD | DNS_FLAG_BROADCAST );
|
|
||||||
query.dns.qdcount = htons ( 1 );
|
|
||||||
query_info = ( void * ) nbns_make_name ( query.payload, name );
|
|
||||||
query_info->qtype = htons ( DNS_TYPE_NB );
|
|
||||||
query_info->qclass = htons ( DNS_CLASS_IN );
|
|
||||||
|
|
||||||
/* Issue query, wait for reply */
|
|
||||||
reply = dns_query ( &query,
|
|
||||||
( ( ( char * ) query_info )
|
|
||||||
+ sizeof ( *query_info )
|
|
||||||
- ( ( char * ) &query ) ),
|
|
||||||
&nameserver );
|
|
||||||
if ( ! reply ) {
|
|
||||||
DBG ( "NMB got no response via %@ (port %d)\n",
|
|
||||||
nameserver.sin_addr.s_addr,
|
|
||||||
nameserver.sin_port );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Search through response for useful answers. */
|
|
||||||
rr_info = dns_find_rr ( &query, reply );
|
|
||||||
if ( ! rr_info ) {
|
|
||||||
DBG ( "NMB got invalid response\n" );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check type of response */
|
|
||||||
if ( ntohs ( rr_info->type ) != DNS_TYPE_NB ) {
|
|
||||||
DBG ( "NMB got answer type %hx (wanted %hx)\n",
|
|
||||||
ntohs ( rr_info->type ), DNS_TYPE_NB );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read response */
|
|
||||||
rr_info_nb = ( struct dns_rr_info_nb * ) rr_info;
|
|
||||||
*addr = rr_info_nb->nb_address;
|
|
||||||
DBG ( "NMB found address %@\n", addr->s_addr );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct resolver nmb_resolver __resolver = {
|
|
||||||
.name = "NMB",
|
|
||||||
.resolv = nmb_resolv,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user