From 5cc5b901e6d319af18b8dc59537c503bbd3ca7f0 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 27 Nov 2015 12:07:16 +0800 Subject: Revert "rockchip: Add max spl size & spl header configs" This reverts commit 10b4615f9d7e177ec7fe644fbb2616e0e0956f6e Signed-off-by: Jeffy Chen Acked-by: Simon Glass diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index aef1a45..d3bddb7 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -17,21 +17,6 @@ config ROCKCHIP_RK3036 and video codec support. Peripherals include Gigabit Ethernet, USB2 host and OTG, SDIO, I2S, UART, SPI, I2C and PWMs. -config ROCKCHIP_SPL_HDR - string "Header of rockchip's spl loader" - help - Rockchip's bootrom requires the spl loader to start with a 4-bytes - header. The content of this header depends on the chip type. - -config ROCKCHIP_MAX_SPL_SIZE - hex "Max size of rockchip's spl loader" - help - Different chip may have different sram size. And if we want to jump - back to the bootrom after spl, we may need to reserve some sram space - for the bootrom. - The max spl loader size should be sram size minus reserved - size(if needed) - config SYS_MALLOC_F default y diff --git a/arch/arm/mach-rockchip/rk3036/Kconfig b/arch/arm/mach-rockchip/rk3036/Kconfig index 95fb2b9..0fbc58e 100644 --- a/arch/arm/mach-rockchip/rk3036/Kconfig +++ b/arch/arm/mach-rockchip/rk3036/Kconfig @@ -9,12 +9,6 @@ config SYS_SOC config SYS_MALLOC_F_LEN default 0x400 -config ROCKCHIP_SPL_HDR - default "RK30" - -config ROCKCHIP_MAX_SPL_SIZE - default 0x1000 - config ROCKCHIP_COMMON bool "Support rk common fuction" diff --git a/arch/arm/mach-rockchip/rk3288/Kconfig b/arch/arm/mach-rockchip/rk3288/Kconfig index 3de3878..d0a7276 100644 --- a/arch/arm/mach-rockchip/rk3288/Kconfig +++ b/arch/arm/mach-rockchip/rk3288/Kconfig @@ -16,12 +16,6 @@ config TARGET_CHROMEBOOK_JERRY WiFi. It includes a Chrome OS EC (Cortex-M3) to provide access to the keyboard and battery functions. -config ROCKCHIP_SPL_HDR - default "RK32" - -config ROCKCHIP_MAX_SPL_SIZE - default 0x8000 - config SYS_SOC default "rockchip" diff --git a/tools/Makefile b/tools/Makefile index 7b4cd3f..9cfd80b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -64,7 +64,7 @@ RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ rsa-sign.o rsa-verify.o rsa-checksum.o \ rsa-mod-exp.o) -ROCKCHIP_OBS = $(if $(CONFIG_ARCH_ROCKCHIP),lib/rc4.o rkcommon.o rkimage.o rksd.o,) +ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o # common objs for dumpimage and mkimage dumpimage-mkimage-objs := aisimage.o \ @@ -109,12 +109,6 @@ fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o # TODO(sjg@chromium.org): Is this correct on Mac OS? -ifneq ($(CONFIG_ARCH_ROCKCHIP),) -HOST_EXTRACFLAGS += \ - -DCONFIG_ROCKCHIP_MAX_SPL_SIZE=$(CONFIG_ROCKCHIP_MAX_SPL_SIZE) \ - -DCONFIG_ROCKCHIP_SPL_HDR="\"$(CONFIG_ROCKCHIP_SPL_HDR)\"" -endif - ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 249c862..9e2173f 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -49,7 +49,7 @@ int rkcommon_set_header(void *buf, uint file_size) { struct header0_info *hdr; - if (file_size > CONFIG_ROCKCHIP_MAX_SPL_SIZE) + if (file_size > RK_MAX_CODE1_SIZE) return -ENOSPC; memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 0fc1e96..222156e 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -12,6 +12,7 @@ enum { RK_BLK_SIZE = 512, RK_INIT_OFFSET = 4, RK_MAX_BOOT_SIZE = 512 << 10, + RK_MAX_CODE1_SIZE = 32 << 10, }; /** diff --git a/tools/rkimage.c b/tools/rkimage.c index 73634e3..7b292f4 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -30,7 +30,7 @@ static void rkimage_print_header(const void *buf) static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - memcpy(buf, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf, "RK32", 4); } static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) diff --git a/tools/rksd.c b/tools/rksd.c index f660d56..39f5c75 100644 --- a/tools/rksd.c +++ b/tools/rksd.c @@ -50,7 +50,7 @@ static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, size); } - memcpy(buf + RKSD_SPL_HDR_START, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); } static int rksd_extract_subimage(void *buf, struct image_tool_params *params) @@ -72,7 +72,7 @@ static int rksd_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = RKSD_SPL_HDR_START + CONFIG_ROCKCHIP_MAX_SPL_SIZE; + pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; debug("pad_size %x\n", pad_size); return pad_size - params->file_size; diff --git a/tools/rkspi.c b/tools/rkspi.c index 69a12f0..eb8119b 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -53,7 +53,7 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, size); } - memcpy(buf + RKSPI_SPL_HDR_START, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4); /* * Spread the image out so we only use the first 2KB of each 4KB @@ -89,7 +89,7 @@ static int rkspi_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = (CONFIG_ROCKCHIP_MAX_SPL_SIZE + 0x7ff) / 0x800 * 0x800; + pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800; params->orig_file_size = pad_size; /* We will double the image size due to the SPI format */ -- cgit v0.10.2 From 7bf274b9caab6de072d4dab34ab0aa66bb128195 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 27 Nov 2015 12:07:17 +0800 Subject: rockchip: mkimage: use imagename to select spl hdr & spl size Our chips may have different spl size and spl header, so use imagename(passed by "mkimage -n") to select them now. Signed-off-by: Jeffy Chen Acked-by: Simon Glass diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 9e2173f..72621fd 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -40,16 +40,84 @@ struct header0_info { uint8_t reserved2[2]; }; +/** + * struct spl_info - spl info for each chip + * + * @imagename: Image name(passed by "mkimage -n") + * @spl_hdr: Boot ROM requires a 4-bytes spl header + * @spl_size: Spl size(include extra 4-bytes spl header) + */ +struct spl_info { + const char *imagename; + const char *spl_hdr; + const uint32_t spl_size; +}; + +static struct spl_info spl_infos[] = { + { "rk3036", "RK30", 0x1000 }, + { "rk3288", "RK32", 0x8000 }, +}; + static unsigned char rc4_key[16] = { 124, 78, 3, 4, 85, 5, 9, 7, 45, 44, 123, 56, 23, 13, 23, 17 }; -int rkcommon_set_header(void *buf, uint file_size) +static struct spl_info *rkcommon_get_spl_info(char *imagename) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + if (!strncmp(imagename, spl_infos[i].imagename, 6)) + return spl_infos + i; + + return NULL; +} + +int rkcommon_check_params(struct image_tool_params *params) +{ + int i; + + if (rkcommon_get_spl_info(params->imagename) != NULL) + return 0; + + fprintf(stderr, "ERROR: imagename (%s) is not supported!\n", + strlen(params->imagename) > 0 ? params->imagename : "NULL"); + + fprintf(stderr, "Available imagename:"); + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + fprintf(stderr, "\t%s", spl_infos[i].imagename); + fprintf(stderr, "\n"); + + return -1; +} + +const char *rkcommon_get_spl_hdr(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_hdr; +} + +int rkcommon_get_spl_size(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_size; +} + +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params) { struct header0_info *hdr; - if (file_size > RK_MAX_CODE1_SIZE) + if (file_size > rkcommon_get_spl_size(params)) return -ENOSPC; memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 222156e..c69540f 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -12,10 +12,38 @@ enum { RK_BLK_SIZE = 512, RK_INIT_OFFSET = 4, RK_MAX_BOOT_SIZE = 512 << 10, - RK_MAX_CODE1_SIZE = 32 << 10, + RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, + RK_SPL_HDR_SIZE = 4, + RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE, + RK_IMAGE_HEADER_LEN = RK_SPL_START, }; /** + * rkcommon_check_params() - check params + * + * @return 0 if OK, -1 if ERROR. + */ +int rkcommon_check_params(struct image_tool_params *params); + +/** + * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image + * + * Rockchip's bootrom requires the spl loader to start with a 4-bytes + * header. The content of this header depends on the chip type. + */ +const char *rkcommon_get_spl_hdr(struct image_tool_params *params); + +/** + * rkcommon_get_spl_size() - get spl size for a Rockchip boot image + * + * Different chip may have different sram size. And if we want to jump + * back to the bootrom after spl, we may need to reserve some sram space + * for the bootrom. + * The spl loader size should be sram size minus reserved size(if needed) + */ +int rkcommon_get_spl_size(struct image_tool_params *params); + +/** * rkcommon_set_header() - set up the header for a Rockchip boot image * * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. @@ -24,6 +52,7 @@ enum { * @file_size: Size of the file we want the boot ROM to load, in bytes * @return 0 if OK, -ENOSPC if too large */ -int rkcommon_set_header(void *buf, uint file_size); +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params); #endif diff --git a/tools/rkimage.c b/tools/rkimage.c index 7b292f4..f9fdcfa 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -9,6 +9,7 @@ #include "imagetool.h" #include +#include "rkcommon.h" static uint32_t header; @@ -30,7 +31,8 @@ static void rkimage_print_header(const void *buf) static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - memcpy(buf, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); } static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) diff --git a/tools/rksd.c b/tools/rksd.c index 39f5c75..a2baa74 100644 --- a/tools/rksd.c +++ b/tools/rksd.c @@ -13,18 +13,7 @@ #include "mkimage.h" #include "rkcommon.h" -enum { - RKSD_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, - RKSD_SPL_START = RKSD_SPL_HDR_START + 4, - RKSD_HEADER_LEN = RKSD_SPL_START, -}; - -static char dummy_hdr[RKSD_HEADER_LEN]; - -static int rksd_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN]; static int rksd_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -42,15 +31,16 @@ static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, unsigned int size; int ret; - size = params->file_size - RKSD_SPL_HDR_START; - ret = rkcommon_set_header(buf, size); + size = params->file_size - RK_SPL_HDR_START; + ret = rkcommon_set_header(buf, size, params); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ printf("Warning: SPL image is too large (size %#x) and will not boot\n", size); } - memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); } static int rksd_extract_subimage(void *buf, struct image_tool_params *params) @@ -72,7 +62,7 @@ static int rksd_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; + pad_size = RK_SPL_HDR_START + rkcommon_get_spl_size(params); debug("pad_size %x\n", pad_size); return pad_size - params->file_size; @@ -84,9 +74,9 @@ static int rksd_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rksd, "Rockchip SD Boot Image support", - RKSD_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rksd_check_params, + rkcommon_check_params, rksd_verify_header, rksd_print_header, rksd_set_header, diff --git a/tools/rkspi.c b/tools/rkspi.c index eb8119b..800e235 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -14,18 +14,10 @@ #include "rkcommon.h" enum { - RKSPI_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, - RKSPI_SPL_START = RKSPI_SPL_HDR_START + 4, - RKSPI_HEADER_LEN = RKSPI_SPL_START, RKSPI_SECT_LEN = RK_BLK_SIZE * 4, }; -static char dummy_hdr[RKSPI_HEADER_LEN]; - -static int rkspi_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN]; static int rkspi_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -45,7 +37,7 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, int ret; size = params->orig_file_size; - ret = rkcommon_set_header(buf, size); + ret = rkcommon_set_header(buf, size, params); debug("size %x\n", size); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ @@ -53,7 +45,8 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, size); } - memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); /* * Spread the image out so we only use the first 2KB of each 4KB @@ -89,12 +82,12 @@ static int rkspi_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800; + pad_size = (rkcommon_get_spl_size(params) + 0x7ff) / 0x800 * 0x800; params->orig_file_size = pad_size; /* We will double the image size due to the SPI format */ pad_size *= 2; - pad_size += RKSPI_SPL_HDR_START; + pad_size += RK_SPL_HDR_START; debug("pad_size %x\n", pad_size); return pad_size - params->file_size; @@ -106,9 +99,9 @@ static int rkspi_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rkspi, "Rockchip SPI Boot Image support", - RKSPI_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rkspi_check_params, + rkcommon_check_params, rkspi_verify_header, rkspi_print_header, rkspi_set_header, -- cgit v0.10.2 From 717f8845ac4b25cfd329d161423622433dfeb990 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 27 Nov 2015 12:07:18 +0800 Subject: rockchip: doc: add imagename We now using imagename to select rockchip's spl hdr & spl size. Signed-off-by: Jeffy Chen Acked-by: Simon Glass diff --git a/doc/README.rockchip b/doc/README.rockchip index 874441c..b455f6f 100644 --- a/doc/README.rockchip +++ b/doc/README.rockchip @@ -71,7 +71,7 @@ Connect your board's OTG port to your computer. To create a suitable image and write it to the board: - ./firefly-rk3288/tools/mkimage -T rkimage -d \ + ./firefly-rk3288/tools/mkimage -n rk3288 -T rkimage -d \ ./firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ cat out | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool l @@ -94,7 +94,7 @@ Booting from an SD card To write an image that boots from an SD card (assumed to be /dev/sdc): - ./firefly-rk3288/tools/mkimage -T rksd -d \ + ./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \ firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ sudo dd if=out of=/dev/sdc seek=64 && \ sudo dd if=firefly-rk3288/u-boot-dtb.img of=/dev/sdc seek=256 @@ -123,7 +123,7 @@ something like: => For evb_rk3036 board: - ./evb-rk3036/tools/mkimage -T rksd -d evb-rk3036/spl/u-boot-spl.bin out && \ + ./evb-rk3036/tools/mkimage -n rk3036 -T rksd -d evb-rk3036/spl/u-boot-spl.bin out && \ cat evb-rk3036/u-boot-dtb.bin >> out && \ sudo dd if=out of=/dev/sdc seek=64 @@ -135,7 +135,7 @@ Booting from SPI To write an image that boots from SPI flash (e.g. for the Haier Chromebook): - ./chromebook_jerry/tools/mkimage -T rkspi -d chromebook_jerry/spl/u-boot-spl-dtb.bin out + ./chromebook_jerry/tools/mkimage -n rk3036 -T rkspi -d chromebook_jerry/spl/u-boot-spl-dtb.bin out dd if=spl.bin of=out.bin bs=128K conv=sync cat chromebook_jerry/u-boot-dtb.img out.bin dd if=out.bin of=out.bin.pad bs=4M conv=sync -- cgit v0.10.2 From 4363de63a88f3e9490cb46ce4c92e7c2d2497ba8 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:35 +0100 Subject: spl: use panic_str instead of panic For a simple static string, use panic_str() which prevents calling printf needlessly. Signed-off-by: Sjoerd Simons Reviewed-by: Simon Glass diff --git a/common/spl/spl.c b/common/spl/spl.c index 7a393dc..6e6dee7 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -452,7 +452,7 @@ ulong spl_relocate_stack_gd(void) #ifdef CONFIG_SPL_SYS_MALLOC_SIMPLE if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) { if (!(gd->flags & GD_FLG_SPL_INIT)) - panic("spl_init must be called before heap reloc"); + panic_str("spl_init must be called before heap reloc"); ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN; gd->malloc_base = ptr; -- cgit v0.10.2 From 962a43cc9628fcfc048c563e0fd295b8743e0504 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:37 +0100 Subject: lib/tiny-printf.c: Implement vprintf Implement both printf and vprintf for a bit more flexibility, e.g. allows the panic() function to work with tiny-printf. Signed-off-by: Sjoerd Simons diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 6766a8f..403b134 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -40,17 +40,14 @@ static void div_out(unsigned int *num, unsigned int div) out_dgt(dgt); } -int printf(const char *fmt, ...) +int vprintf(const char *fmt, va_list va) { - va_list va; char ch; char *p; unsigned int num; char buf[12]; unsigned int div; - va_start(va, fmt); - while ((ch = *(fmt++))) { if (ch != '%') { putc(ch); @@ -117,6 +114,17 @@ int printf(const char *fmt, ...) } abort: - va_end(va); return 0; } + +int printf(const char *fmt, ...) +{ + va_list va; + int ret; + + va_start(va, fmt); + ret = vprintf(fmt, va); + va_end(va); + + return ret; +} -- cgit v0.10.2 From 2b22a99c65c437891ab88703dff25e256f78c21f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:38 +0100 Subject: lib: Split panic functions out of vsprintf.c To allow panic and panic_str to still be used when using tiny-printf, split them out into their own file which gets build regardless of what printf implementation is used. Signed-off-by: Sjoerd Simons diff --git a/lib/Makefile b/lib/Makefile index 1f1ff6f..ae84833 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -85,13 +85,13 @@ obj-$(CONFIG_LIB_RAND) += rand.o ifdef CONFIG_SPL_BUILD # SPL U-Boot may use full-printf, tiny-printf or none at all ifdef CONFIG_USE_TINY_PRINTF -obj-$(CONFIG_SPL_SERIAL_SUPPORT) += tiny-printf.o +obj-$(CONFIG_SPL_SERIAL_SUPPORT) += tiny-printf.o panic.o else -obj-$(CONFIG_SPL_SERIAL_SUPPORT) += vsprintf.o +obj-$(CONFIG_SPL_SERIAL_SUPPORT) += vsprintf.o panic.o endif else # Main U-Boot always uses the full printf support -obj-y += vsprintf.o +obj-y += vsprintf.o panic.o endif subdir-ccflags-$(CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED) += -O2 diff --git a/lib/panic.c b/lib/panic.c new file mode 100644 index 0000000..e2b8b74 --- /dev/null +++ b/lib/panic.c @@ -0,0 +1,45 @@ +/* + * linux/lib/vsprintf.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include +#if !defined(CONFIG_PANIC_HANG) +#include +#endif + +static void panic_finish(void) __attribute__ ((noreturn)); + +static void panic_finish(void) +{ + putc('\n'); +#if defined(CONFIG_PANIC_HANG) + hang(); +#else + udelay(100000); /* allow messages to go out */ + do_reset(NULL, 0, 0, NULL); +#endif + while (1) + ; +} + +void panic_str(const char *str) +{ + puts(str); + panic_finish(); +} + +void panic(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + panic_finish(); +} diff --git a/lib/vsprintf.c b/lib/vsprintf.c index dd8380b..bf5fd01 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -897,35 +897,6 @@ int vprintf(const char *fmt, va_list args) return i; } -static void panic_finish(void) __attribute__ ((noreturn)); - -static void panic_finish(void) -{ - putc('\n'); -#if defined(CONFIG_PANIC_HANG) - hang(); -#else - udelay(100000); /* allow messages to go out */ - do_reset(NULL, 0, 0, NULL); -#endif - while (1) - ; -} - -void panic_str(const char *str) -{ - puts(str); - panic_finish(); -} - -void panic(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); - panic_finish(); -} void __assert_fail(const char *assertion, const char *file, unsigned line, const char *function) -- cgit v0.10.2 From e4c5383e4d46ef196d022b481cab364bd3b9c877 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:39 +0100 Subject: lib: split out strtoxxxx functions out of vsprintf.c To allow the various string to number conversion functions to be used when using tiny-printf,split them out into their own file which gets build regardless of what printf implementation is used. Signed-off-by: Sjoerd Simons diff --git a/lib/Makefile b/lib/Makefile index ae84833..dd36f25 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -85,13 +85,13 @@ obj-$(CONFIG_LIB_RAND) += rand.o ifdef CONFIG_SPL_BUILD # SPL U-Boot may use full-printf, tiny-printf or none at all ifdef CONFIG_USE_TINY_PRINTF -obj-$(CONFIG_SPL_SERIAL_SUPPORT) += tiny-printf.o panic.o +obj-$(CONFIG_SPL_SERIAL_SUPPORT) += tiny-printf.o panic.o strto.o else -obj-$(CONFIG_SPL_SERIAL_SUPPORT) += vsprintf.o panic.o +obj-$(CONFIG_SPL_SERIAL_SUPPORT) += vsprintf.o panic.o strto.o endif else # Main U-Boot always uses the full printf support -obj-y += vsprintf.o panic.o +obj-y += vsprintf.o panic.o strto.o endif subdir-ccflags-$(CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED) += -O2 diff --git a/lib/strto.c b/lib/strto.c new file mode 100644 index 0000000..a6c0157 --- /dev/null +++ b/lib/strto.c @@ -0,0 +1,174 @@ +/* + * linux/lib/vsprintf.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include +#include +#include + +unsigned long simple_strtoul(const char *cp, char **endp, + unsigned int base) +{ + unsigned long result = 0; + unsigned long value; + + if (*cp == '0') { + cp++; + if ((*cp == 'x') && isxdigit(cp[1])) { + base = 16; + cp++; + } + + if (!base) + base = 8; + } + + if (!base) + base = 10; + + while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) + ? toupper(*cp) : *cp)-'A'+10) < base) { + result = result*base + value; + cp++; + } + + if (endp) + *endp = (char *)cp; + + return result; +} + +int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) +{ + char *tail; + unsigned long val; + size_t len; + + *res = 0; + len = strlen(cp); + if (len == 0) + return -EINVAL; + + val = simple_strtoul(cp, &tail, base); + if (tail == cp) + return -EINVAL; + + if ((*tail == '\0') || + ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { + *res = val; + return 0; + } + + return -EINVAL; +} + +long simple_strtol(const char *cp, char **endp, unsigned int base) +{ + if (*cp == '-') + return -simple_strtoul(cp + 1, endp, base); + + return simple_strtoul(cp, endp, base); +} + +unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) +{ + unsigned long result = simple_strtoul(cp, endp, base); + switch (**endp) { + case 'G': + result *= 1024; + /* fall through */ + case 'M': + result *= 1024; + /* fall through */ + case 'K': + case 'k': + result *= 1024; + if ((*endp)[1] == 'i') { + if ((*endp)[2] == 'B') + (*endp) += 3; + else + (*endp) += 2; + } + } + return result; +} + +unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) +{ + unsigned long long result = simple_strtoull(cp, endp, base); + switch (**endp) { + case 'G': + result *= 1024; + /* fall through */ + case 'M': + result *= 1024; + /* fall through */ + case 'K': + case 'k': + result *= 1024; + if ((*endp)[1] == 'i') { + if ((*endp)[2] == 'B') + (*endp) += 3; + else + (*endp) += 2; + } + } + return result; +} + +unsigned long long simple_strtoull(const char *cp, char **endp, + unsigned int base) +{ + unsigned long long result = 0, value; + + if (*cp == '0') { + cp++; + if ((*cp == 'x') && isxdigit(cp[1])) { + base = 16; + cp++; + } + + if (!base) + base = 8; + } + + if (!base) + base = 10; + + while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0' + : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) { + result = result * base + value; + cp++; + } + + if (endp) + *endp = (char *) cp; + + return result; +} + +long trailing_strtoln(const char *str, const char *end) +{ + const char *p; + + if (!end) + end = str + strlen(str); + for (p = end - 1; p > str; p--) { + if (!isdigit(*p)) + return simple_strtoul(p + 1, NULL, 10); + } + + return -1; +} + +long trailing_strtol(const char *str) +{ + return trailing_strtoln(str, NULL); +} diff --git a/lib/vsprintf.c b/lib/vsprintf.c index bf5fd01..24167a1 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -15,176 +15,12 @@ #include #include #include -#include #include -#if !defined(CONFIG_PANIC_HANG) -#include -#endif #include #define noinline __attribute__((noinline)) -unsigned long simple_strtoul(const char *cp, char **endp, - unsigned int base) -{ - unsigned long result = 0; - unsigned long value; - - if (*cp == '0') { - cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - base = 16; - cp++; - } - - if (!base) - base = 8; - } - - if (!base) - base = 10; - - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - - if (endp) - *endp = (char *)cp; - - return result; -} - -int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) -{ - char *tail; - unsigned long val; - size_t len; - - *res = 0; - len = strlen(cp); - if (len == 0) - return -EINVAL; - - val = simple_strtoul(cp, &tail, base); - if (tail == cp) - return -EINVAL; - - if ((*tail == '\0') || - ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { - *res = val; - return 0; - } - - return -EINVAL; -} - -long simple_strtol(const char *cp, char **endp, unsigned int base) -{ - if (*cp == '-') - return -simple_strtoul(cp + 1, endp, base); - - return simple_strtoul(cp, endp, base); -} - -unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) -{ - unsigned long result = simple_strtoul(cp, endp, base); - switch (**endp) { - case 'G': - result *= 1024; - /* fall through */ - case 'M': - result *= 1024; - /* fall through */ - case 'K': - case 'k': - result *= 1024; - if ((*endp)[1] == 'i') { - if ((*endp)[2] == 'B') - (*endp) += 3; - else - (*endp) += 2; - } - } - return result; -} - -unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) -{ - unsigned long long result = simple_strtoull(cp, endp, base); - switch (**endp) { - case 'G': - result *= 1024; - /* fall through */ - case 'M': - result *= 1024; - /* fall through */ - case 'K': - case 'k': - result *= 1024; - if ((*endp)[1] == 'i') { - if ((*endp)[2] == 'B') - (*endp) += 3; - else - (*endp) += 2; - } - } - return result; -} - -unsigned long long simple_strtoull(const char *cp, char **endp, - unsigned int base) -{ - unsigned long long result = 0, value; - - if (*cp == '0') { - cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - base = 16; - cp++; - } - - if (!base) - base = 8; - } - - if (!base) - base = 10; - - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0' - : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) { - result = result * base + value; - cp++; - } - - if (endp) - *endp = (char *) cp; - - return result; -} - -long trailing_strtoln(const char *str, const char *end) -{ - const char *p; - - if (!end) - end = str + strlen(str); - for (p = end - 1; p > str; p--) { - if (!isdigit(*p)) - return simple_strtoul(p + 1, NULL, 10); - } - - return -1; -} - -long trailing_strtol(const char *str) -{ - return trailing_strtoln(str, NULL); -} - /* we use this so that we can do without the ctype library */ #define is_digit(c) ((c) >= '0' && (c) <= '9') -- cgit v0.10.2 From fc011f6402d3d63fe826260fcc5940d7b7fb138e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:40 +0100 Subject: mmc: mmc: Don't use sprintf when using tiny-printf There is no sprintf implementation in tiny-printf, so don't try to use it when tiny-printf if used. Signed-off-by: Sjoerd Simons diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 2a58702..3a34028 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1469,7 +1469,9 @@ static int mmc_startup(struct mmc *mmc) mmc->block_dev.blksz = mmc->read_bl_len; mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz); mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len); -#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT) +#if !defined(CONFIG_SPL_BUILD) || \ + (defined(CONFIG_SPL_LIBCOMMON_SUPPORT) && \ + !defined(CONFIG_USE_TINY_PRINTF)) sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x", mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff), (mmc->cid[3] >> 16) & 0xffff); -- cgit v0.10.2 From f4a8a1757b5c53a6f86b2724aea51436d4e4f9cc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Dec 2015 23:27:41 +0100 Subject: rockchip: firefly: Use tiny-printf Switch to using tiny-printf for the firefly SPL, this reduces the SPL by around 1800 bytes bringing it back under the 32k limit for both gcc 4.9 and gcc 5. Signed-off-by: Sjoerd Simons diff --git a/configs/firefly-rk3288_defconfig b/configs/firefly-rk3288_defconfig index b645af5..be4ca88 100644 --- a/configs/firefly-rk3288_defconfig +++ b/configs/firefly-rk3288_defconfig @@ -42,5 +42,6 @@ CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYS_NS16550=y CONFIG_USE_PRIVATE_LIBGCC=y +CONFIG_USE_TINY_PRINTF=y CONFIG_CMD_DHRYSTONE=y CONFIG_ERRNO_STR=y -- cgit v0.10.2 From e390680015c79c8ce390b5245646324eb6f9d9c6 Mon Sep 17 00:00:00 2001 From: huang lin Date: Mon, 7 Dec 2015 11:08:56 +0800 Subject: rockchip: rk3036 sdram setting cs1_row when rank larger than 1 only rank large than 1, we will use cs1_row, so check rank, when rank larger than 1, we set the cs1_row. Signed-off-by: Lin Huang Acked-by: Simon Glass diff --git a/arch/arm/mach-rockchip/rk3036/sdram_rk3036.c b/arch/arm/mach-rockchip/rk3036/sdram_rk3036.c index 7a05e31..e3ca870 100644 --- a/arch/arm/mach-rockchip/rk3036/sdram_rk3036.c +++ b/arch/arm/mach-rockchip/rk3036/sdram_rk3036.c @@ -701,15 +701,19 @@ finish: static void sdram_all_config(struct rk3036_sdram_priv *priv) { u32 os_reg = 0; + u32 cs1_row = 0; struct rk3036_ddr_config config = priv->ddr_config; + if (config.rank > 1) + cs1_row = config.cs1_row - 13; + os_reg = config.ddr_type << DDR_TYPE_SHIFT | 0 << DDR_CHN_CNT_SHIFT | (config.rank - 1) << DDR_RANK_CNT_SHIFT | (config.col - 1) << DDR_COL_SHIFT | (config.bank == 3 ? 0 : 1) << DDR_BANK_SHIFT | (config.cs0_row - 13) << DDR_CS0_ROW_SHIFT | - (config.cs1_row - 13) << DDR_CS1_ROW_SHIFT | + cs1_row << DDR_CS1_ROW_SHIFT | 1 << DDR_BW_SHIFT | config.bw << DDR_DIE_BW_SHIFT; writel(os_reg, &priv->grf->os_reg[1]); } -- cgit v0.10.2 From 47b4c228b5ae72598dc38ca2764c11ea1c6693cc Mon Sep 17 00:00:00 2001 From: huang lin Date: Mon, 7 Dec 2015 11:08:57 +0800 Subject: rockchip: Add basic support for kylin board kylin board use rk3036 SOC, 512M sdram, 8G emmc. This add some basic files required to allow the board to output serial message and can run command(mmc info etc). Signed-off-by: Lin Huang Acked-by: Simon Glass diff --git a/arch/arm/mach-rockchip/rk3036/Kconfig b/arch/arm/mach-rockchip/rk3036/Kconfig index 0fbc58e..cc03808 100644 --- a/arch/arm/mach-rockchip/rk3036/Kconfig +++ b/arch/arm/mach-rockchip/rk3036/Kconfig @@ -3,6 +3,9 @@ if ROCKCHIP_RK3036 config TARGET_EVB_RK3036 bool "EVB_RK3036" +config TARGET_KYLIN_RK3036 + bool "KYLIN_RK3036" + config SYS_SOC default "rockchip" @@ -13,5 +16,6 @@ config ROCKCHIP_COMMON bool "Support rk common fuction" source "board/evb_rk3036/evb_rk3036/Kconfig" +source "board/kylin/kylin_rk3036/Kconfig" endif diff --git a/board/kylin/kylin_rk3036/Kconfig b/board/kylin/kylin_rk3036/Kconfig new file mode 100644 index 0000000..5d75c1f --- /dev/null +++ b/board/kylin/kylin_rk3036/Kconfig @@ -0,0 +1,15 @@ +if TARGET_KYLIN_RK3036 + +config SYS_BOARD + default "kylin_rk3036" + +config SYS_VENDOR + default "kylin" + +config SYS_CONFIG_NAME + default "kylin_rk3036" + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + +endif diff --git a/board/kylin/kylin_rk3036/MAINTAINERS b/board/kylin/kylin_rk3036/MAINTAINERS new file mode 100644 index 0000000..e69de29 diff --git a/board/kylin/kylin_rk3036/Makefile b/board/kylin/kylin_rk3036/Makefile new file mode 100644 index 0000000..0663270 --- /dev/null +++ b/board/kylin/kylin_rk3036/Makefile @@ -0,0 +1,7 @@ +# +# (C) Copyright 2015 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += kylin_rk3036.o diff --git a/board/kylin/kylin_rk3036/kylin_rk3036.c b/board/kylin/kylin_rk3036/kylin_rk3036.c new file mode 100644 index 0000000..40d6b52 --- /dev/null +++ b/board/kylin/kylin_rk3036/kylin_rk3036.c @@ -0,0 +1,49 @@ +/* + * (C) Copyright 2015 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +void get_ddr_config(struct rk3036_ddr_config *config) +{ + /* K4B4G1646Q config */ + config->ddr_type = 3; + config->rank = 1; + config->cs0_row = 15; + config->cs1_row = 15; + + /* 8bank */ + config->bank = 3; + config->col = 10; + + /* 16bit bw */ + config->bw = 1; +} + +int board_init(void) +{ + return 0; +} + +int dram_init(void) +{ + gd->ram_size = sdram_size(); + + return 0; +} + +#ifndef CONFIG_SYS_DCACHE_OFF +void enable_caches(void) +{ + /* Enable D-cache. I-cache is already enabled in start.S */ + dcache_enable(); +} +#endif diff --git a/configs/kylin-rk3036_defconfig b/configs/kylin-rk3036_defconfig new file mode 100644 index 0000000..60cdebf --- /dev/null +++ b/configs/kylin-rk3036_defconfig @@ -0,0 +1,26 @@ +CONFIG_ARM=y +CONFIG_ARCH_ROCKCHIP=y +CONFIG_ROCKCHIP_RK3036=y +CONFIG_TARGET_KYLIN_RK3036=y +CONFIG_DEFAULT_DEVICE_TREE="rk3036-sdk" +CONFIG_SPL_STACK_R=y +CONFIG_SPL_STACK_R_ADDR=0x80000 +# CONFIG_CMD_IMLS is not set +# CONFIG_CMD_SETEXPR is not set +CONFIG_CMD_PMIC=y +CONFIG_CMD_REGULATOR=y +CONFIG_CLK=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y +CONFIG_RESET=y +CONFIG_LED=y +CONFIG_SYS_I2C_ROCKCHIP=y +CONFIG_PINCTRL=y +CONFIG_ROCKCHIP_DWMMC=y +CONFIG_ROCKCHIP_3036_PINCTRL=y +CONFIG_ROCKCHIP_GPIO=y +CONFIG_RAM=y +CONFIG_DM_MMC=y +CONFIG_USE_PRIVATE_LIBGCC=y +CONFIG_CMD_DHRYSTONE=y +CONFIG_ERRNO_STR=y diff --git a/include/configs/kylin_rk3036.h b/include/configs/kylin_rk3036.h new file mode 100644 index 0000000..aa07889 --- /dev/null +++ b/include/configs/kylin_rk3036.h @@ -0,0 +1,12 @@ +/* + * (C) Copyright 2015 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +#include + +#endif -- cgit v0.10.2