Commit 98a48c5de545e5a5eedba0a868024ef0d4ae5347

Authored by Chander Kashyap
Committed by Albert ARIBAUD
1 parent b9a1ef219e

ORIGEN: Add MMC SPL support

Adds mmc boot support.

Signed-off-by: Chander Kashyap <chander.kashyap@linaro.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

Showing 5 changed files with 221 additions and 1 deletions Side-by-side Diff

board/samsung/origen/Makefile
... ... @@ -26,15 +26,33 @@
26 26  
27 27 SOBJS := mem_setup.o
28 28 SOBJS += lowlevel_init.o
  29 +
  30 +ifndef CONFIG_SPL_BUILD
29 31 COBJS += origen.o
  32 +endif
30 33  
  34 +ifdef CONFIG_SPL_BUILD
  35 +COBJS += mmc_boot.o
  36 +endif
  37 +
31 38 SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
32 39 OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS))
33 40  
34   -all: $(obj).depend $(LIB)
  41 +ALL +=$(obj).depend $(LIB)
35 42  
  43 +ifdef CONFIG_SPL_BUILD
  44 +ALL += tools/mk$(BOARD)spl.exe
  45 +endif
  46 +
  47 +all: $(ALL)
  48 +
36 49 $(LIB): $(OBJS)
37 50 $(AR) $(ARFLAGS) $@ $(OBJS)
  51 +
  52 +ifdef CONFIG_SPL_BUILD
  53 +tools/mk$(BOARD)spl.exe: tools/mkv310_image.c
  54 + $(HOSTCC) tools/mkv310_image.c -o tools/mk$(BOARD)spl.exe
  55 +endif
38 56  
39 57 #########################################################################
40 58  
board/samsung/origen/mmc_boot.c
  1 +/*
  2 + * Copyright (C) 2011 Samsung Electronics
  3 + *
  4 + * See file CREDITS for list of people who contributed to this
  5 + * project.
  6 + *
  7 + * This program is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU General Public License as
  9 + * published by the Free Software Foundation; either version 2 of
  10 + * the License, or (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20 + * MA 02111-1307 USA
  21 + */
  22 +
  23 +#include<common.h>
  24 +#include<config.h>
  25 +
  26 +/*
  27 +* Copy U-boot from mmc to RAM:
  28 +* COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains
  29 +* Pointer to API (Data transfer from mmc to ram)
  30 +*/
  31 +void copy_uboot_to_ram(void)
  32 +{
  33 + u32 (*copy_bl2)(u32, u32, u32) = (void *) *(u32 *)COPY_BL2_FNPTR_ADDR;
  34 +
  35 + copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE);
  36 +}
  37 +
  38 +void board_init_f(unsigned long bootflag)
  39 +{
  40 + __attribute__((noreturn)) void (*uboot)(void);
  41 + copy_uboot_to_ram();
  42 +
  43 + /* Jump to U-Boot image */
  44 + uboot = (void *)CONFIG_SYS_TEXT_BASE;
  45 + (*uboot)();
  46 + /* Never returns Here */
  47 +}
  48 +
  49 +/* Place Holders */
  50 +void board_init_r(gd_t *id, ulong dest_addr)
  51 +{
  52 + /* Function attribute is no-return */
  53 + /* This Function never executes */
  54 + while (1)
  55 + ;
  56 +}
  57 +
  58 +void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}
board/samsung/origen/tools/mkv310_image.c
  1 +/*
  2 + * Copyright (C) 2011 Samsung Electronics
  3 + *
  4 + * See file CREDITS for list of people who contributed to this
  5 + * project.
  6 + *
  7 + * This program is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU General Public License as
  9 + * published by the Free Software Foundation; either version 2 of
  10 + * the License, or (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20 + * MA 02111-1307 USA
  21 + */
  22 +
  23 +#include <stdio.h>
  24 +#include <stdlib.h>
  25 +#include <unistd.h>
  26 +#include <fcntl.h>
  27 +#include <errno.h>
  28 +#include <string.h>
  29 +#include <sys/stat.h>
  30 +
  31 +#define BUFSIZE (16*1024)
  32 +#define IMG_SIZE (16*1024)
  33 +#define SPL_HEADER_SIZE 16
  34 +#define FILE_PERM (S_IRUSR | S_IWUSR | S_IRGRP \
  35 + | S_IWGRP | S_IROTH | S_IWOTH)
  36 +#define SPL_HEADER "S5PC210 HEADER "
  37 +/*
  38 +* Requirement:
  39 +* IROM code reads first 14K bytes from boot device.
  40 +* It then calculates the checksum of 14K-4 bytes and compare with data at
  41 +* 14K-4 offset.
  42 +*
  43 +* This function takes two filenames:
  44 +* IN "u-boot-spl.bin" and
  45 +* OUT "$(BOARD)-spl.bin as filenames.
  46 +* It reads the "u-boot-spl.bin" in 16K buffer.
  47 +* It calculates checksum of 14K-4 Bytes and stores at 14K-4 offset in buffer.
  48 +* It writes the buffer to "$(BOARD)-spl.bin" file.
  49 +*/
  50 +
  51 +int main(int argc, char **argv)
  52 +{
  53 + int i, len;
  54 + unsigned char buffer[BUFSIZE] = {0};
  55 + int ifd, ofd;
  56 + unsigned int checksum = 0, count;
  57 +
  58 + if (argc != 3) {
  59 + printf(" %d Wrong number of arguments\n", argc);
  60 + exit(EXIT_FAILURE);
  61 + }
  62 +
  63 + ifd = open(argv[1], O_RDONLY);
  64 + if (ifd < 0) {
  65 + fprintf(stderr, "%s: Can't open %s: %s\n",
  66 + argv[0], argv[1], strerror(errno));
  67 + exit(EXIT_FAILURE);
  68 + }
  69 +
  70 + ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
  71 + if (ifd < 0) {
  72 + fprintf(stderr, "%s: Can't open %s: %s\n",
  73 + argv[0], argv[2], strerror(errno));
  74 + if (ifd)
  75 + close(ifd);
  76 + exit(EXIT_FAILURE);
  77 + }
  78 +
  79 + len = lseek(ifd, 0, SEEK_END);
  80 + lseek(ifd, 0, SEEK_SET);
  81 +
  82 + memcpy(&buffer[0], SPL_HEADER, SPL_HEADER_SIZE);
  83 +
  84 + count = (len < (IMG_SIZE - SPL_HEADER_SIZE))
  85 + ? len : (IMG_SIZE - SPL_HEADER_SIZE);
  86 +
  87 + if (read(ifd, buffer + SPL_HEADER_SIZE, count) != count) {
  88 + fprintf(stderr, "%s: Can't read %s: %s\n",
  89 + argv[0], argv[1], strerror(errno));
  90 +
  91 + if (ifd)
  92 + close(ifd);
  93 + if (ofd)
  94 + close(ofd);
  95 +
  96 + exit(EXIT_FAILURE);
  97 + }
  98 +
  99 + for (i = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
  100 + checksum += buffer[i+16];
  101 +
  102 + *(ulong *)buffer ^= 0x1f;
  103 + *(ulong *)(buffer+4) ^= checksum;
  104 +
  105 + for (i = 1; i < SPL_HEADER_SIZE; i++)
  106 + buffer[i] ^= buffer[i-1];
  107 +
  108 + if (write(ofd, buffer, BUFSIZE) != BUFSIZE) {
  109 + fprintf(stderr, "%s: Can't write %s: %s\n",
  110 + argv[0], argv[2], strerror(errno));
  111 +
  112 + if (ifd)
  113 + close(ifd);
  114 + if (ofd)
  115 + close(ofd);
  116 +
  117 + exit(EXIT_FAILURE);
  118 + }
  119 +
  120 + if (ifd)
  121 + close(ifd);
  122 + if (ofd)
  123 + close(ofd);
  124 +
  125 + return EXIT_SUCCESS;
  126 +}
include/configs/origen.h
... ... @@ -94,6 +94,9 @@
94 94  
95 95 #define CONFIG_BOOTDELAY 3
96 96 #define CONFIG_ZERO_BOOTDELAY_CHECK
  97 +/* MMC SPL */
  98 +#define CONFIG_SPL
  99 +#define COPY_BL2_FNPTR_ADDR 0x02020030
97 100  
98 101 #define CONFIG_BOOTCOMMAND "fatload mmc 0 40007000 uImage; bootm 40007000"
99 102  
... ... @@ -157,5 +160,10 @@
157 160 #define CONFIG_DOS_PARTITION 1
158 161  
159 162 #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE)
  163 +
  164 +/* U-boot copy size from boot Media to DRAM.*/
  165 +#define COPY_BL2_SIZE 0x80000
  166 +#define BL2_START_OFFSET ((CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE)/512)
  167 +#define BL2_SIZE_BLOC_COUNT (COPY_BL2_SIZE/512)
160 168 #endif /* __CONFIG_H */
... ... @@ -93,7 +93,17 @@
93 93  
94 94 ALL-y += $(obj)u-boot-spl.bin
95 95  
  96 +ifdef CONFIG_SAMSUNG
  97 +ALL-y += $(obj)$(BOARD)-spl.bin
  98 +endif
  99 +
96 100 all: $(ALL-y)
  101 +
  102 +ifdef CONFIG_SAMSUNG
  103 +$(obj)$(BOARD)-spl.bin: $(obj)u-boot-spl.bin
  104 + $(TOPDIR)/board/$(BOARDDIR)/tools/mk$(BOARD)spl.exe \
  105 + $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin
  106 +endif
97 107  
98 108 $(obj)u-boot-spl.bin: $(obj)u-boot-spl
99 109 $(OBJCOPY) $(OBJCFLAGS) -O binary $< $@