core: corified zlib to support compressed btrfs

Add a corified zlib, decompression support only.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Correct initialization of the cache doubly-linked list

The initialization of the cache doubly-linked list had
head->next->prev instead of head->prev->next; this entry is supposed
to initialize the ->next entry of the last entry in the list (which
points back to the head node.)

For clarity, consistently use "head" to refer to the head node; the
mixing of "head" and "dev->cache_head" needlessly obfuscated the code.

The wild pointer reference caused crashes on some systems.

Reported-by: Jan Safrata <jsafrata@centrum.cz>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
ldlinux: Return immediately after we execute() a command

If we successfully lookup the filetype of a command we need to return
once we've called execute(), otherwise we'll also end up calling
new_linux_kernel().

Reported-by: Sebastian Herbszt <herbszt@gmx.de>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge branch 'master' into elflink

The reason for this merge is that we need the fix to core/fs/cache.c
without which we can potentially dereference an invalid pointer.

The below conflict is a result of the new setup_data blob code being
merged from the master branch.

Conflicts:
	com32/lib/Makefile
Only compile dprintf/vdprintf if DEBUG_PORT is defined

We really, really don't want to accidentally spew output to a debug
port in production, so make it obligatory to define DEBUG_PORT or
DEBUG_STDIO in order for the debugging code to be compiled in.  Since
DEBUG_STDIO just turns the debugging code into stdio references, we
only need to compile the code for the DEBUG_PORT case.

Add a commented-out line to mk/devel.mk to make it easier for users.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Matt Fleming <matt.fleming@intel.com>
core/elflink: Delete ADV code that's already in ldlinux

The exact same ADV code is in both com32/elflink/ldlinux and
core/elflink. Since there's no need to have the same code in two place
at once delete the copy from the core since there are no users in
core/.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
ldlinux: Stop using the internal KT_* image types

The KT_* image types were never meant to be used outside of
com32/menu, so use the external image types from syslinux/boot.h

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
lib/sys/module: Add support for weak symbols

We need a means of allowing Syslinux derivative-specific functions to
remain unresolved when there is no implementation for them. For
example, unload_pxe() is referenced by common code in com32/lib, but
is only implemented for PXELINUX. By marking unload_pxe() as __weak we
can substitute references with the undefined_symbol() function for
SYSLINUX, EXTLINUX and ISOLINUX. Provided that those references are
never executed everything works fine. However, if code calls actually
calls unload_pxe() from SYSLINUX, EXTLINUX or ISOLINUX an error
message is displayed and execution is halted.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
elflink: Replace __intcall() with direct function calls

There's no reason to use the COMBOOT API at all now that we can have
any undefined symbols resolved at runtime - we can just access
functions directly.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Use pxe_call() instead of COMBOOT API

This involved some other changes, such as passing flags to
unload_pxe() now that we only call it from C code, and hence don't
need to update KeepPXE.

We also needed to move some of the pxe function prototypes to
com32/include/syslinux/pxe_api.h because they are now referenced
outside of the core.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
com32: Use --as-needed for LDFLAGS

This extends commit 4678fd92a21e ("elflink: fix dependency problem in
cmenu/Makefile") and basically reverts commit fb543aa635ff ("com32:
Per-object file LDFLAGS"). By using the --as-needed ld argument we can
specify all the required shared libraries for a directory, even if not
all of the libraries are needed by every .c32 file. --as-needed takes
care of only creating DT_NEEDED entries for the shared libraries that
are actually required to resolve undefined symbols in a given module.

Furthermore, by using $(LIBS) we create a dependency between .c32
files and their shared libraries, which allows multiple make jobs to
run in parallel.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
ldlinux: Return to command prompt after loading COM32

The old COM32 loading code would drop the user at a command prompt
once execution returned from the COM32 amodule. We need to replicate
this because most callers of execute() don't expect it to return.

This bug was noticed when loading a COM32 module from
vesamenu.c32. Once execution returned from the COM32 module the
display became garbled because no code exists to reinitialise the
screen for VGA.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
rawcon_read: Fix reading high part of input keys

commit 8486142cf304 ("elflink: Replace __intcall() with direct
function calls") made the mistake of zero'ing the high part of the
input key on every invocation of __rawcon_read() instead of preserving
it across calls like the old code, which lead to function keys such as
KEY_UP, KEY_DOWN, etc not working.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
ldlinux: Use findpath() to lookup filenames

We should use the same method of opening files as the module code when
searching for extensions. In particular, we should search all of PATH.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
fix for boot crash of syslinux-4.xx

All syslinux 4.xx versions (tested up to 4.04) seems to contain a bug, that
causes a crash in early phase of syslinux boot from an usb stick.
This is always possible to reproduce, but only on certain hw (atom based
embedded board).
Version 3.86 of syslinux always works with that hw.

When syslinux 4.xx is used to setup bootable usb stick (which works on general
desktop pc), that usb stick does not work with embedded atom based board.
Screen is garbaged, flickering and the system hangs, instead of loading the
image to be booted.

Dissecting syslinux source code reveals, that the problem is within
core/fs/cache.c
function cache_init(), where seems to be an invalid pointer used to store an
initial value - following patch fixes the problem by removing the
offending line, that seems not to be needed anyway.

Signed-off-by: Jan Safrata <jsafrata@centrum.cz>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
core: move disklib into core

Move disklib into core so that it can be used by multidisk support.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
core: initial implementation of fopen with multidisk acess

An initial implementation of fopen. Should work for GPT/MBR.

cache still needs to be modified as syslinux will break after opening
file.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
core: add data structure to hold fs_info for all disks/partition

A new data structure is implemented to hold filesystem information for
all accessed disk/partitions.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
core: modify disk cache to work with multidisk

Disk cache was modified to work with multidisk. Now fopen with
different disks/partitions should be fully working.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
core: multidisk parser related changes

This commits makes a small change to multidisk path syntax it's now
"(hdx,y)/path/to/file". opendir() has also been changed to accept multidisk
paths. Parser code has moved to multidisk.c.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>