Skip to content

Commit

Permalink
OXNAS: add fat support to SPL
Browse files Browse the repository at this point in the history
  • Loading branch information
kref committed Oct 11, 2013
1 parent 5c869c7 commit 4c1c0ce
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 100 deletions.
12 changes: 12 additions & 0 deletions board/ox820/ox820.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void board_inithw(void)
puts("memory test done\n");
}
#endif /* DEBUG */
#ifdef CONFIG_SPL_BSS_DRAM_START
extern char __bss_dram_start;
extern char __bss_dram_end;
memset(&__bss_dram_start, 0, &__bss_dram_end - &__bss_dram_start);
#endif
}

void board_init_f(ulong dummy)
Expand All @@ -114,6 +119,13 @@ u32 spl_boot_device(void)
return CONFIG_SPL_BOOT_DEVICE;
}

#ifdef CONFIG_SPL_BLOCK_SUPPORT
void spl_block_device_init(void)
{
ide_init();
}
#endif

void spl_display_print(void)
{
/* print a hint, so that we will not use the wrong SPL by mistake */
Expand Down
11 changes: 11 additions & 0 deletions board/ox820/u-boot-spl.lds
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ SECTIONS

_end = .;

#ifdef CONFIG_SPL_BSS_DRAM_START
. = CONFIG_SPL_BSS_DRAM_START;
.bss.dram : {
__bss_dram_start = .;
#ifdef CONFIG_SPL_FAT_SUPPORT
fs/fat/libfat.o(.bss*)
#endif /* CONFIG_SPL_FAT_SUPPORT */
__bss_dram_end = .;
}
#endif /* CONFIG_SPL_BSS_DRAM_START */

.bss __rel_dyn_start (OVERLAY) : {
__bss_start = .;
*(.bss*)
Expand Down
1 change: 1 addition & 0 deletions boards.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ woodburn arm arm1136 - -
woodburn_sd arm arm1136 woodburn - mx35 woodburn_sd:IMX_CONFIG=board/woodburn/imximage.cfg
ox820 arm arm1136 ox820 - nas782x ox820
ox820_sata arm arm1136 ox820 - nas782x ox820:BOOT_FROM_SATA
ox820_fat arm arm1136 ox820 - nas782x ox820:BOOT_FROM_SATA,BOOT_FROM_FAT
ox820_nand arm arm1136 ox820 - nas782x ox820:BOOT_FROM_NAND
tnetv107x_evm arm arm1176 tnetv107xevm ti tnetv107x
rpi_b arm arm1176 rpi_b raspberrypi bcm2835
Expand Down
2 changes: 1 addition & 1 deletion common/spl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COBJS-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
COBJS-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
COBJS-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
COBJS-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o
COBJS-$(CONFIG_SPL_BLOCK_SUPPORT) += spl_ide.o
COBJS-$(CONFIG_SPL_BLOCK_SUPPORT) += spl_block.o
endif

COBJS := $(sort $(COBJS-y))
Expand Down
202 changes: 202 additions & 0 deletions common/spl/spl_block.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* (C) Copyright 2013
*
* Ma Haijun <mahaijuns@gmail.com>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <common.h>
#include <spl.h>
#include <asm/u-boot.h>
#include <asm/utils.h>
#include <version.h>
#include <part.h>
#include <fat.h>

/* should be implemented by board */
extern void spl_block_device_init(void);

block_dev_desc_t * spl_get_block_device(void)
{
block_dev_desc_t * device;

spl_block_device_init();

device = get_dev(CONFIG_SPL_BLOCKDEV_INTERFACE, CONFIG_SPL_BLOCKDEV_ID);
if (!device) {
printf("blk device %s%d not exists\n",
CONFIG_SPL_BLOCKDEV_INTERFACE,
CONFIG_SPL_BLOCKDEV_ID);
hang();
}

return device;
}

#ifdef CONFIG_SPL_FAT_SUPPORT
static int block_load_image_fat(const char *filename)
{
int err;
struct image_header *header;

header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));

err = file_fat_read(filename, header, sizeof(struct image_header));
if (err <= 0)
goto end;

spl_parse_image_header(header);

err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);

end:
if (err <= 0)
printf("spl: error reading image %s, err - %d\n",
filename, err);

return (err <= 0);
}

#ifdef CONFIG_SPL_OS_BOOT
static int block_load_image_fat_os()
{
int err;

err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME,
(void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
if (err <= 0) {
printf("spl: error reading image %s, err - %d\n",
CONFIG_SPL_FAT_LOAD_ARGS_NAME, err);
return -1;
}

return block_load_image_fat(CONFIG_SPL_FAT_LOAD_KERNEL_NAME);
}
#endif

void spl_block_load_image(void)
{
int err;
block_dev_desc_t * device;

device = spl_get_block_device();
err = fat_register_device(device, CONFIG_BLOCKDEV_FAT_BOOT_PARTITION);
if (err) {
printf("spl: fat register err - %d\n", err);
hang();
}
#ifdef CONFIG_SPL_OS_BOOT
if (spl_start_uboot() || block_load_image_fat_os())
#endif
err = block_load_image_fat(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME);
if (err)
hang();
}

/* quick and dirty memory allocation */
static ulong next_mem = CONFIG_SPL_MALLOC_START;

void *memalign(size_t alignment, size_t bytes)
{
ulong mem = next_mem;

mem += alignment;
mem &= ~alignment;
next_mem = mem + bytes;

if (next_mem > CONFIG_SYS_SDRAM_BASE + SDRAM_SIZE) {
printf("spl: out of memory\n");
hang();
}

return (void *)mem;
}

void free(void* mem)
{
}

#else /* CONFIG_SPL_FAT_SUPPORT */
static int block_load_image_raw(block_dev_desc_t * device, unsigned long sector)
{
int n;
u32 image_size_sectors;
struct image_header *header;

header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));

/* read image header to find the image size & load address */
n = device->block_read(device->dev, sector, 1, header);

if (n != 1) {
printf("spl: blk read err\n");
return 1;
}

spl_parse_image_header(header);

/* convert size to sectors - round up */
image_size_sectors = (spl_image.size + 512 - 1) / 512;
n = device->block_read(device->dev, sector, image_size_sectors,
(void *)spl_image.load_addr);

if (n != image_size_sectors) {
printf("spl: blk read err\n");
return 1;
}
return 0;
}

#ifdef CONFIG_SPL_OS_BOOT
static int block_load_image_raw_os(block_dev_desc_t * device)
{
int n;

n = device->block_read(device->dev, CONFIG_SYS_BLOCK_RAW_MODE_ARGS_SECTOR,
CONFIG_SYS_BLOCK_RAW_MODE_ARGS_SECTORS,
(u32 *)CONFIG_SYS_SPL_ARGS_ADDR);
/* flush cache after read */
flush_cache(addr, CONFIG_SYS_BLOCK_RAW_MODE_ARGS_SECTORS * 512);

if (n != CONFIG_SYS_BLOCK_RAW_MODE_ARGS_SECTORS) {
printf("args blk read error\n");
return -1;
}

return block_load_image_raw(device, CONFIG_SYS_BLOCK_RAW_MODE_KERNEL_SECTOR);
}
#endif

void spl_block_load_image(void)
{
int err;
block_dev_desc_t * device;

device = spl_get_block_device();
#ifdef CONFIG_SPL_OS_BOOT
if (spl_start_uboot() || block_load_image_raw_os(device))
#endif
err = block_load_image_raw(device,
CONFIG_SYS_BLOCK_RAW_MODE_U_BOOT_SECTOR);
if (err)
hang();
}
#endif /* CONFIG_SPL_FAT_SUPPORT */
99 changes: 0 additions & 99 deletions common/spl/spl_ide.c

This file was deleted.

0 comments on commit 4c1c0ce

Please sign in to comment.