Conflicts: MAINTAINERS boards.cfg Signed-off-by: Stefano Babic <sbabic@denx.de>master
commit
c4a7ece020
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@ |
||||
#
|
||||
# Copyright (C) 2013 Samsung Electronics
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
|
||||
include $(TOPDIR)/config.mk |
||||
|
||||
LIB = $(obj)lib$(BOARD).o
|
||||
|
||||
COBJS += arndale_spl.o
|
||||
|
||||
ifndef CONFIG_SPL_BUILD |
||||
COBJS += arndale.o
|
||||
endif |
||||
|
||||
SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
|
||||
OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS))
|
||||
|
||||
ALL := $(obj).depend $(LIB)
|
||||
|
||||
all: $(ALL) |
||||
|
||||
$(LIB): $(OBJS) |
||||
$(call cmd_link_o_target, $(OBJS))
|
||||
|
||||
#########################################################################
|
||||
|
||||
# defines $(obj).depend target
|
||||
include $(SRCTREE)/rules.mk |
||||
|
||||
sinclude $(obj).depend |
||||
|
||||
#########################################################################
|
@ -0,0 +1,101 @@ |
||||
/*
|
||||
* Copyright (C) 2013 Samsung Electronics |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/arch/pinmux.h> |
||||
#include <asm/arch/dwmmc.h> |
||||
#include <asm/arch/power.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
int board_init(void) |
||||
{ |
||||
gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL); |
||||
return 0; |
||||
} |
||||
|
||||
int dram_init(void) |
||||
{ |
||||
int i; |
||||
u32 addr; |
||||
|
||||
for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
||||
addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
||||
gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int power_init_board(void) |
||||
{ |
||||
set_ps_hold_ctrl(); |
||||
return 0; |
||||
} |
||||
|
||||
void dram_init_banksize(void) |
||||
{ |
||||
int i; |
||||
u32 addr, size; |
||||
|
||||
for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
||||
addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
||||
size = get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
||||
|
||||
gd->bd->bi_dram[i].start = addr; |
||||
gd->bd->bi_dram[i].size = size; |
||||
} |
||||
} |
||||
|
||||
#ifdef CONFIG_GENERIC_MMC |
||||
int board_mmc_init(bd_t *bis) |
||||
{ |
||||
int ret; |
||||
/* dwmmc initializattion for available channels */ |
||||
ret = exynos_dwmmc_init(gd->fdt_blob); |
||||
if (ret) |
||||
debug("dwmmc init failed\n"); |
||||
|
||||
return ret; |
||||
} |
||||
#endif |
||||
|
||||
static int board_uart_init(void) |
||||
{ |
||||
int err = 0, uart_id; |
||||
|
||||
for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) { |
||||
err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE); |
||||
if (err) { |
||||
debug("UART%d not configured\n", |
||||
(uart_id - PERIPH_ID_UART0)); |
||||
return err; |
||||
} |
||||
} |
||||
return err; |
||||
} |
||||
|
||||
#ifdef CONFIG_BOARD_EARLY_INIT_F |
||||
int board_early_init_f(void) |
||||
{ |
||||
int err; |
||||
|
||||
err = board_uart_init(); |
||||
if (err) { |
||||
debug("UART init failed\n"); |
||||
return err; |
||||
} |
||||
return err; |
||||
} |
||||
#endif |
||||
|
||||
#ifdef CONFIG_DISPLAY_BOARDINFO |
||||
int checkboard(void) |
||||
{ |
||||
printf("\nBoard: Arndale\n"); |
||||
|
||||
return 0; |
||||
} |
||||
#endif |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* Copyright (c) 2012 The Chromium OS Authors. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/arch/spl.h> |
||||
|
||||
#define SIGNATURE 0xdeadbeef |
||||
|
||||
/* Parameters of early board initialization in SPL */ |
||||
static struct spl_machine_param machine_param |
||||
__attribute__((section(".machine_param"))) = { |
||||
.signature = SIGNATURE, |
||||
.version = 1, |
||||
.params = "vmubfasirM", |
||||
.size = sizeof(machine_param), |
||||
|
||||
.mem_iv_size = 0x1f, |
||||
.mem_type = DDR_MODE_DDR3, |
||||
|
||||
/*
|
||||
* Set uboot_size to 0x100000 bytes. |
||||
* |
||||
* This is an overly conservative value chosen to accommodate all |
||||
* possible U-Boot image. You are advised to set this value to a |
||||
* smaller realistic size via scripts that modifies the .machine_param |
||||
* section of output U-Boot image. |
||||
*/ |
||||
.uboot_size = 0x100000, |
||||
|
||||
.boot_source = BOOT_MODE_OM, |
||||
.frequency_mhz = 800, |
||||
.arm_freq_mhz = 1000, |
||||
.serial_base = 0x12c30000, |
||||
.i2c_base = 0x12c60000, |
||||
.mem_manuf = MEM_MANUF_SAMSUNG, |
||||
}; |
||||
|
||||
struct spl_machine_param *spl_get_machine_params(void) |
||||
{ |
||||
if (machine_param.signature != SIGNATURE) { |
||||
/* Will hang if SIGNATURE dont match */ |
||||
while (1) |
||||
; |
||||
} |
||||
|
||||
return &machine_param; |
||||
} |
@ -0,0 +1,39 @@ |
||||
/* |
||||
* SAMSUNG Arndale board device tree source |
||||
* |
||||
* Copyright (c) 2013 Samsung Electronics Co., Ltd. |
||||
* http://www.samsung.com |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/dts-v1/; |
||||
#include "exynos5250.dtsi" |
||||
|
||||
/ { |
||||
model = "SAMSUNG Arndale board based on EXYNOS5250"; |
||||
compatible = "samsung,arndale", "samsung,exynos5250"; |
||||
|
||||
aliases { |
||||
serial0 = "/serial@12C20000"; |
||||
console = "/serial@12C20000"; |
||||
}; |
||||
|
||||
mmc@12200000 { |
||||
samsung,bus-width = <8>; |
||||
samsung,timing = <1 3 3>; |
||||
}; |
||||
|
||||
mmc@12210000 { |
||||
status = "disabled"; |
||||
}; |
||||
|
||||
mmc@12220000 { |
||||
samsung,bus-width = <4>; |
||||
samsung,timing = <1 2 3>; |
||||
}; |
||||
|
||||
mmc@12230000 { |
||||
status = "disabled"; |
||||
}; |
||||
}; |
@ -1,18 +0,0 @@ |
||||
#
|
||||
# Copyright (C) 2010 Samsung Electronics
|
||||
# Kyungmin Park <kyungmin.park@samsung.com>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
|
||||
# On S5PC100 we use the 128 MiB OneDRAM bank at
|
||||
#
|
||||
# 0x30000000 to 0x35000000 (80MiB)
|
||||
# 0x38000000 to 0x40000000 (128MiB)
|
||||
#
|
||||
# On S5PC110 we use the 128 MiB OneDRAM bank at
|
||||
#
|
||||
# 0x30000000 to 0x35000000 (80MiB)
|
||||
# 0x40000000 to 0x50000000 (256MiB)
|
||||
#
|
||||
CONFIG_SYS_TEXT_BASE = 0x34800000
|
@ -1,16 +0,0 @@ |
||||
#
|
||||
# Copyright (C) 2008 # Samsung Elecgtronics
|
||||
# Kyungmin Park <kyungmin.park@samsung.com>
|
||||
#
|
||||
|
||||
# On S5PC100 we use the 128 MiB OneDRAM bank at
|
||||
#
|
||||
# 0x30000000 to 0x35000000 (80MiB)
|
||||
# 0x38000000 to 0x40000000 (128MiB)
|
||||
#
|
||||
# On S5PC110 we use the 128 MiB OneDRAM bank at
|
||||
#
|
||||
# 0x30000000 to 0x35000000 (80MiB)
|
||||
# 0x40000000 to 0x48000000 (128MiB)
|
||||
#
|
||||
CONFIG_SYS_TEXT_BASE = 0x34800000
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,255 @@ |
||||
/*
|
||||
* Copyright (C) 2013 Samsung Electronics |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
* |
||||
* Configuration settings for the SAMSUNG Arndale board. |
||||
*/ |
||||
|
||||
#ifndef __CONFIG_ARNDALE_H |
||||
#define __CONFIG_ARNDALE_H |
||||
|
||||
/* High Level Configuration Options */ |
||||
#define CONFIG_SAMSUNG /* in a SAMSUNG core */ |
||||
#define CONFIG_S5P /* S5P Family */ |
||||
#define CONFIG_EXYNOS5 /* which is in a Exynos5 Family */ |
||||
#define CONFIG_EXYNOS5250 |
||||
|
||||
#include <asm/arch/cpu.h> /* get chip and board defs */ |
||||
|
||||
#define CONFIG_SYS_GENERIC_BOARD |
||||
#define CONFIG_ARCH_CPU_INIT |
||||
#define CONFIG_DISPLAY_CPUINFO |
||||
#define CONFIG_DISPLAY_BOARDINFO |
||||
|
||||
/* Enable fdt support for Exynos5250 */ |
||||
#define CONFIG_ARCH_DEVICE_TREE exynos5250 |
||||
#define CONFIG_OF_CONTROL |
||||
#define CONFIG_OF_SEPARATE |
||||
|
||||
/* Allow tracing to be enabled */ |
||||
#define CONFIG_TRACE |
||||
#define CONFIG_CMD_TRACE |
||||
#define CONFIG_TRACE_BUFFER_SIZE (16 << 20) |
||||
#define CONFIG_TRACE_EARLY_SIZE (8 << 20) |
||||
#define CONFIG_TRACE_EARLY |
||||
#define CONFIG_TRACE_EARLY_ADDR 0x50000000 |
||||
|
||||
/* Keep L2 Cache Disabled */ |
||||
#define CONFIG_SYS_DCACHE_OFF |
||||
|
||||
#define CONFIG_SYS_SDRAM_BASE 0x40000000 |
||||
#define CONFIG_SYS_TEXT_BASE 0x43E00000 |
||||
|
||||
/* input clock of PLL: SMDK5250 has 24MHz input clock */ |
||||
#define CONFIG_SYS_CLK_FREQ 24000000 |
||||
|
||||
#define CONFIG_SETUP_MEMORY_TAGS |
||||
#define CONFIG_CMDLINE_TAG |
||||
#define CONFIG_INITRD_TAG |
||||
#define CONFIG_CMDLINE_EDITING |
||||
|
||||
/* Power Down Modes */ |
||||
#define S5P_CHECK_SLEEP 0x00000BAD |
||||
#define S5P_CHECK_DIDLE 0xBAD00000 |
||||
#define S5P_CHECK_LPA 0xABAD0000 |
||||
|
||||
/* Offset for inform registers */ |
||||
#define INFORM0_OFFSET 0x800 |
||||
#define INFORM1_OFFSET 0x804 |
||||
|
||||
/* Size of malloc() pool */ |
||||
#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + (4 << 20)) |
||||
|
||||
/* select serial console configuration */ |
||||
#define CONFIG_BAUDRATE 115200 |
||||
#define EXYNOS5_DEFAULT_UART_OFFSET 0x010000 |
||||
#define CONFIG_SILENT_CONSOLE |
||||
|
||||
/* Console configuration */ |
||||
#define CONFIG_CONSOLE_MUX |
||||
#define CONFIG_SYS_CONSOLE_IS_IN_ENV |
||||
#define EXYNOS_DEVICE_SETTINGS \ |
||||
"stdin=serial\0" \
|
||||
"stdout=serial\0" \
|
||||
"stderr=serial\0" |
||||
|
||||
#define CONFIG_EXTRA_ENV_SETTINGS \ |
||||
EXYNOS_DEVICE_SETTINGS |
||||
|
||||
/* SD/MMC configuration */ |
||||
#define CONFIG_GENERIC_MMC |
||||
#define CONFIG_MMC |
||||
#define CONFIG_SDHCI |
||||
#define CONFIG_S5P_SDHCI |
||||
#define CONFIG_DWMMC |
||||
#define CONFIG_EXYNOS_DWMMC |
||||
#define CONFIG_SUPPORT_EMMC_BOOT |
||||
|
||||
|
||||
#define CONFIG_BOARD_EARLY_INIT_F |
||||
#define CONFIG_SKIP_LOWLEVEL_INIT |
||||
|
||||
/* PWM */ |
||||
#define CONFIG_PWM |
||||
|
||||
/* allow to overwrite serial and ethaddr */ |
||||
#define CONFIG_ENV_OVERWRITE |
||||
|
||||
/* Command definition*/ |
||||
#include <config_cmd_default.h> |
||||
|
||||
#define CONFIG_CMD_PING |
||||
#define CONFIG_CMD_ELF |
||||
#define CONFIG_CMD_MMC |
||||
#define CONFIG_CMD_EXT2 |
||||
#define CONFIG_CMD_FAT |
||||
#define CONFIG_CMD_NET |
||||
#define CONFIG_CMD_HASH |
||||
|
||||
#define CONFIG_BOOTDELAY 3 |
||||
#define CONFIG_ZERO_BOOTDELAY_CHECK |
||||
|
||||
/* USB */ |
||||
#define CONFIG_CMD_USB |
||||
#define CONFIG_USB_EHCI |
||||
#define CONFIG_USB_EHCI_EXYNOS |
||||
#define CONFIG_USB_STORAGE |
||||
|
||||
/* MMC SPL */ |
||||
#define CONFIG_SPL |
||||
#define COPY_BL2_FNPTR_ADDR 0x02020030 |
||||
|
||||
#define CONFIG_SPL_LIBCOMMON_SUPPORT |
||||
|
||||
/* specific .lds file */ |
||||
#define CONFIG_SPL_LDSCRIPT "board/samsung/common/exynos-uboot-spl.lds" |
||||
#define CONFIG_SPL_TEXT_BASE 0x02023400 |
||||
#define CONFIG_SPL_MAX_FOOTPRINT (14 * 1024) |
||||
|
||||
#define CONFIG_BOOTCOMMAND "mmc read 40007000 451 2000; bootm 40007000" |
||||
|
||||
/* Miscellaneous configurable options */ |
||||
#define CONFIG_SYS_LONGHELP /* undef to save memory */ |
||||
#define CONFIG_SYS_HUSH_PARSER /* use "hush" command parser */ |
||||
#define CONFIG_SYS_PROMPT "ARNDALE # " |
||||
#define CONFIG_SYS_CBSIZE 256 /* Console I/O Buffer Size */ |
||||
#define CONFIG_SYS_PBSIZE 384 /* Print Buffer Size */ |
||||
#define CONFIG_SYS_MAXARGS 16 /* max number of command args */ |
||||
#define CONFIG_DEFAULT_CONSOLE "console=ttySAC2,115200n8\0" |
||||
/* Boot Argument Buffer Size */ |
||||
#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE |
||||
/* memtest works on */ |
||||
#define CONFIG_SYS_MEMTEST_START CONFIG_SYS_SDRAM_BASE |
||||
#define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_SDRAM_BASE + 0x5E00000) |
||||
#define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + 0x3E00000) |
||||
|
||||
#define CONFIG_SYS_HZ 1000 |
||||
|
||||
#define CONFIG_RD_LVL |
||||
|
||||
#define CONFIG_NR_DRAM_BANKS 8 |
||||
#define SDRAM_BANK_SIZE (256UL << 20UL) /* 256 MB */ |
||||
#define PHYS_SDRAM_1 CONFIG_SYS_SDRAM_BASE |
||||
#define PHYS_SDRAM_1_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_2 (CONFIG_SYS_SDRAM_BASE + SDRAM_BANK_SIZE) |
||||
#define PHYS_SDRAM_2_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_3 (CONFIG_SYS_SDRAM_BASE + (2 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_3_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_4 (CONFIG_SYS_SDRAM_BASE + (3 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_4_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_5 (CONFIG_SYS_SDRAM_BASE + (4 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_5_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_6 (CONFIG_SYS_SDRAM_BASE + (5 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_6_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_7 (CONFIG_SYS_SDRAM_BASE + (6 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_7_SIZE SDRAM_BANK_SIZE |
||||
#define PHYS_SDRAM_8 (CONFIG_SYS_SDRAM_BASE + (7 * SDRAM_BANK_SIZE)) |
||||
#define PHYS_SDRAM_8_SIZE SDRAM_BANK_SIZE |
||||
|
||||
#define CONFIG_SYS_MONITOR_BASE 0x00000000 |
||||
|
||||
/* FLASH and environment organization */ |
||||
#define CONFIG_SYS_NO_FLASH |
||||
#undef CONFIG_CMD_IMLS |
||||
#define CONFIG_IDENT_STRING " for ARNDALE" |
||||
|
||||
#define CONFIG_SYS_MMC_ENV_DEV 0 |
||||
|
||||
#define CONFIG_ENV_IS_IN_MMC |
||||
#define CONFIG_SECURE_BL1_ONLY |
||||
|
||||
/* Secure FW size configuration */ |
||||
#ifdef CONFIG_SECURE_BL1_ONLY |
||||
#define CONFIG_SEC_FW_SIZE (8 << 10) /* 8KB */ |
||||
#else |
||||
#define CONFIG_SEC_FW_SIZE 0 |
||||
#endif |
||||
|
||||
/* Configuration of BL1, BL2, ENV Blocks on mmc */ |
||||
#define CONFIG_RES_BLOCK_SIZE (512) |
||||
#define CONFIG_BL1_SIZE (16 << 10) /*16 K reserved for BL1*/ |
||||
#define CONFIG_BL2_SIZE (512UL << 10UL) /* 512 KB */ |
||||
#define CONFIG_ENV_SIZE (16 << 10) /* 16 KB */ |
||||
|
||||
#define CONFIG_BL1_OFFSET (CONFIG_RES_BLOCK_SIZE + CONFIG_SEC_FW_SIZE) |
||||
#define CONFIG_BL2_OFFSET (CONFIG_BL1_OFFSET + CONFIG_BL1_SIZE) |
||||
#define CONFIG_ENV_OFFSET (CONFIG_BL2_OFFSET + CONFIG_BL2_SIZE) |
||||
|
||||
/* U-boot copy size from boot Media to DRAM.*/ |
||||
#define BL2_START_OFFSET (CONFIG_BL2_OFFSET/512) |
||||
#define BL2_SIZE_BLOC_COUNT (CONFIG_BL2_SIZE/512) |
||||
|
||||
#define CONFIG_SPI_BOOTING |
||||
#define EXYNOS_COPY_SPI_FNPTR_ADDR 0x02020058 |
||||
#define SPI_FLASH_UBOOT_POS (CONFIG_SEC_FW_SIZE + CONFIG_BL1_SIZE) |
||||
|
||||
#define CONFIG_DOS_PARTITION |
||||
#define CONFIG_EFI_PARTITION |
||||
#define CONFIG_CMD_PART |
||||
#define CONFIG_PARTITION_UUIDS |
||||
|
||||
|
||||
#define CONFIG_IRAM_STACK 0x02050000 |
||||
|
||||
#define CONFIG_SYS_INIT_SP_ADDR CONFIG_IRAM_STACK |
||||
|
||||
/* I2C */ |
||||
#define CONFIG_SYS_I2C_INIT_BOARD |
||||
#define CONFIG_HARD_I2C |
||||
#define CONFIG_CMD_I2C |
||||
#define CONFIG_SYS_I2C_SPEED 100000 /* 100 Kbps */ |
||||
#define CONFIG_DRIVER_S3C24X0_I2C |
||||
#define CONFIG_I2C_MULTI_BUS |
||||
#define CONFIG_MAX_I2C_NUM 8 |
||||
#define CONFIG_SYS_I2C_SLAVE 0x0 |
||||
#define CONFIG_I2C_EDID |
||||
|
||||
/* PMIC */ |
||||
#define CONFIG_PMIC |
||||
#define CONFIG_PMIC_I2C |
||||
#define CONFIG_PMIC_MAX77686 |
||||
|
||||
#define CONFIG_DEFAULT_DEVICE_TREE exynos5250-arndale |
||||
|
||||
/* Ethernet Controllor Driver */ |
||||
#ifdef CONFIG_CMD_NET |
||||
#define CONFIG_SMC911X |
||||
#define CONFIG_SMC911X_BASE 0x5000000 |
||||
#define CONFIG_SMC911X_16_BIT |
||||
#define CONFIG_ENV_SROM_BANK 1 |
||||
#endif /*CONFIG_CMD_NET*/ |
||||
|
||||
/* Enable PXE Support */ |
||||
#ifdef CONFIG_CMD_NET |
||||
#define CONFIG_CMD_PXE |
||||
#define CONFIG_MENU |
||||
#endif |
||||
|
||||
/* Enable devicetree support */ |
||||
#define CONFIG_OF_LIBFDT |
||||
|
||||
/* Enable Time Command */ |
||||
#define CONFIG_CMD_TIME |
||||
|
||||
#endif /* __CONFIG_H */ |
@ -0,0 +1,335 @@ |
||||
/*
|
||||
* Copyright (c) 2013, The Chromium Authors |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#define DEBUG |
||||
|
||||
#include <common.h> |
||||
#include <command.h> |
||||
#include <malloc.h> |
||||
|
||||
#include <u-boot/zlib.h> |
||||
#include <bzlib.h> |
||||
|
||||
#include <lzma/LzmaTypes.h> |
||||
#include <lzma/LzmaDec.h> |
||||
#include <lzma/LzmaTools.h> |
||||
|
||||
#include <linux/lzo.h> |
||||
|
||||
static const char plain[] = |
||||
"I am a highly compressable bit of text.\n" |
||||
"I am a highly compressable bit of text.\n" |
||||
"I am a highly compressable bit of text.\n" |
||||
"There are many like me, but this one is mine.\n" |
||||
"If I were any shorter, there wouldn't be much sense in\n" |
||||
"compressing me in the first place. At least with lzo, anyway,\n" |
||||
"which appears to behave poorly in the face of short text\n" |
||||
"messages.\n"; |
||||
|
||||
/* bzip2 -c /tmp/plain.txt > /tmp/plain.bz2 */ |
||||
static const char bzip2_compressed[] = |
||||
"\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\xe5\x63\xdd\x09\x00\x00" |
||||
"\x28\x57\x80\x00\x10\x40\x85\x20\x20\x04\x00\x3f\xef\xdf\xf0\x30" |
||||
"\x00\xd6\xd0\x34\x91\x89\xa6\xf5\x4d\x19\x1a\x19\x0d\x02\x34\xd4" |
||||
"\xc9\x00\x34\x34\x00\x02\x48\x41\x35\x4f\xd4\xc6\x88\xd3\x50\x3d" |
||||
"\x4f\x51\x82\x4f\x88\xc3\x0d\x05\x62\x4f\x91\xa3\x52\x1b\xd0\x52" |
||||
"\x41\x4a\xa3\x98\xc2\x6b\xca\xa3\x82\xa5\xac\x8b\x15\x99\x68\xad" |
||||
"\xdf\x29\xd6\xf1\xf7\x5a\x10\xcd\x8c\x26\x61\x94\x95\xfe\x9e\x16" |
||||
"\x18\x28\x69\xd4\x23\x64\xcc\x2b\xe5\xe8\x5f\x00\xa4\x70\x26\x2c" |
||||
"\xee\xbd\x59\x6d\x6a\xec\xfc\x31\xda\x59\x0a\x14\x2a\x60\x1c\xf0" |
||||
"\x04\x86\x73\x9a\xc5\x5b\x87\x3f\x5b\x4c\x93\xe6\xb5\x35\x0d\xa6" |
||||
"\xb1\x2e\x62\x7b\xab\x67\xe7\x99\x2a\x14\x5e\x9f\x64\xcb\x96\xf4" |
||||
"\x0d\x65\xd4\x39\xe6\x8b\x7e\xea\x1c\x03\x69\x97\x83\x58\x91\x96" |
||||
"\xe1\xf0\x9d\xa4\x15\x8b\xb8\xc6\x93\xdc\x3d\xd9\x3c\x22\x55\xef" |
||||
"\xfb\xbb\x2a\xd3\x87\xa2\x8b\x04\xd9\x19\xf8\xe2\xfd\x4f\xdb\x1a" |
||||
"\x07\xc8\x60\xa3\x3f\xf8\xbb\x92\x29\xc2\x84\x87\x2b\x1e\xe8\x48"; |
||||
static const unsigned long bzip2_compressed_size = 240; |
||||
|
||||
/* lzma -z -c /tmp/plain.txt > /tmp/plain.lzma */ |
||||
static const char lzma_compressed[] = |
||||
"\x5d\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x24\x88" |
||||
"\x08\x26\xd8\x41\xff\x99\xc8\xcf\x66\x3d\x80\xac\xba\x17\xf1\xc8" |
||||
"\xb9\xdf\x49\x37\xb1\x68\xa0\x2a\xdd\x63\xd1\xa7\xa3\x66\xf8\x15" |
||||
"\xef\xa6\x67\x8a\x14\x18\x80\xcb\xc7\xb1\xcb\x84\x6a\xb2\x51\x16" |
||||
"\xa1\x45\xa0\xd6\x3e\x55\x44\x8a\x5c\xa0\x7c\xe5\xa8\xbd\x04\x57" |
||||
"\x8f\x24\xfd\xb9\x34\x50\x83\x2f\xf3\x46\x3e\xb9\xb0\x00\x1a\xf5" |
||||
"\xd3\x86\x7e\x8f\x77\xd1\x5d\x0e\x7c\xe1\xac\xde\xf8\x65\x1f\x4d" |
||||
"\xce\x7f\xa7\x3d\xaa\xcf\x26\xa7\x58\x69\x1e\x4c\xea\x68\x8a\xe5" |
||||
"\x89\xd1\xdc\x4d\xc7\xe0\x07\x42\xbf\x0c\x9d\x06\xd7\x51\xa2\x0b" |
||||
"\x7c\x83\x35\xe1\x85\xdf\xee\xfb\xa3\xee\x2f\x47\x5f\x8b\x70\x2b" |
||||
"\xe1\x37\xf3\x16\xf6\x27\x54\x8a\x33\x72\x49\xea\x53\x7d\x60\x0b" |
||||
"\x21\x90\x66\xe7\x9e\x56\x61\x5d\xd8\xdc\x59\xf0\xac\x2f\xd6\x49" |
||||
"\x6b\x85\x40\x08\x1f\xdf\x26\x25\x3b\x72\x44\xb0\xb8\x21\x2f\xb3" |
||||
"\xd7\x9b\x24\x30\x78\x26\x44\x07\xc3\x33\xd1\x4d\x03\x1b\xe1\xff" |
||||
"\xfd\xf5\x50\x8d\xca"; |
||||
static const unsigned long lzma_compressed_size = 229; |
||||
|
||||
/* lzop -c /tmp/plain.txt > /tmp/plain.lzo */ |
||||
static const char lzo_compressed[] = |
||||
"\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a\x10\x30\x20\x60\x09\x40\x01" |
||||
"\x05\x03\x00\x00\x09\x00\x00\x81\xb4\x52\x09\x54\xf1\x00\x00\x00" |
||||
"\x00\x09\x70\x6c\x61\x69\x6e\x2e\x74\x78\x74\x65\xb1\x07\x9c\x00" |
||||
"\x00\x01\x5e\x00\x00\x01\x0f\xc3\xc7\x7a\xe0\x00\x16\x49\x20\x61" |
||||
"\x6d\x20\x61\x20\x68\x69\x67\x68\x6c\x79\x20\x63\x6f\x6d\x70\x72" |
||||
"\x65\x73\x73\x61\x62\x6c\x65\x20\x62\x69\x74\x20\x6f\x66\x20\x74" |
||||
"\x65\x78\x74\x2e\x0a\x20\x2f\x9c\x00\x00\x22\x54\x68\x65\x72\x65" |
||||
"\x20\x61\x72\x65\x20\x6d\x61\x6e\x79\x20\x6c\x69\x6b\x65\x20\x6d" |
||||
"\x65\x2c\x20\x62\x75\x74\x20\x74\x68\x69\x73\x20\x6f\x6e\x65\x20" |
||||
"\x69\x73\x20\x6d\x69\x6e\x65\x2e\x0a\x49\x66\x20\x49\x20\x77\x84" |
||||
"\x06\x0a\x6e\x79\x20\x73\x68\x6f\x72\x74\x65\x72\x2c\x20\x74\x90" |
||||
"\x08\x00\x08\x77\x6f\x75\x6c\x64\x6e\x27\x74\x20\x62\x65\x20\x6d" |
||||
"\x75\x63\x68\x20\x73\x65\x6e\x73\x65\x20\x69\x6e\x0a\xf8\x19\x02" |
||||
"\x69\x6e\x67\x20\x6d\x64\x02\x64\x06\x00\x5a\x20\x66\x69\x72\x73" |
||||
"\x74\x20\x70\x6c\x61\x63\x65\x2e\x20\x41\x74\x20\x6c\x65\x61\x73" |
||||
"\x74\x20\x77\x69\x74\x68\x20\x6c\x7a\x6f\x2c\x20\x61\x6e\x79\x77" |
||||
"\x61\x79\x2c\x0a\x77\x68\x69\x63\x68\x20\x61\x70\x70\x65\x61\x72" |
||||
"\x73\x20\x74\x6f\x20\x62\x65\x68\x61\x76\x65\x20\x70\x6f\x6f\x72" |
||||
"\x6c\x79\x20\x69\x6e\x20\x74\x68\x65\x20\x66\x61\x63\x65\x20\x6f" |
||||
"\x66\x20\x73\x68\x6f\x72\x74\x20\x74\x65\x78\x74\x0a\x6d\x65\x73" |
||||
"\x73\x61\x67\x65\x73\x2e\x0a\x11\x00\x00\x00\x00\x00\x00"; |
||||
static const unsigned long lzo_compressed_size = 334; |
||||
|
||||
|
||||
#define TEST_BUFFER_SIZE 512 |
||||
|
||||
typedef int (*mutate_func)(void *, unsigned long, void *, unsigned long, |
||||
unsigned long *); |
||||
|
||||
static int compress_using_gzip(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
int ret; |
||||
unsigned long inout_size = out_max; |
||||
|
||||
ret = gzip(out, &inout_size, in, in_size); |
||||
if (out_size) |
||||
*out_size = inout_size; |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int uncompress_using_gzip(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
int ret; |
||||
unsigned long inout_size = in_size; |
||||
|
||||
ret = gunzip(out, out_max, in, &inout_size); |
||||
if (out_size) |
||||
*out_size = inout_size; |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int compress_using_bzip2(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
/* There is no bzip2 compression in u-boot, so fake it. */ |
||||
assert(in_size == strlen(plain)); |
||||
assert(memcmp(plain, in, in_size) == 0); |
||||
|
||||
if (bzip2_compressed_size > out_max) |
||||
return -1; |
||||
|
||||
memcpy(out, bzip2_compressed, bzip2_compressed_size); |
||||
if (out_size) |
||||
*out_size = bzip2_compressed_size; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int uncompress_using_bzip2(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
int ret; |
||||
unsigned int inout_size = out_max; |
||||
|
||||
ret = BZ2_bzBuffToBuffDecompress(out, &inout_size, in, in_size, |
||||
CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); |
||||
if (out_size) |
||||
*out_size = inout_size; |
||||
|
||||
return (ret != BZ_OK); |
||||
} |
||||
|
||||
static int compress_using_lzma(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
/* There is no lzma compression in u-boot, so fake it. */ |
||||
assert(in_size == strlen(plain)); |
||||
assert(memcmp(plain, in, in_size) == 0); |
||||
|
||||
if (lzma_compressed_size > out_max) |
||||
return -1; |
||||
|
||||
memcpy(out, lzma_compressed, lzma_compressed_size); |
||||
if (out_size) |
||||
*out_size = lzma_compressed_size; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int uncompress_using_lzma(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
int ret; |
||||
SizeT inout_size = out_max; |
||||
|
||||
ret = lzmaBuffToBuffDecompress(out, &inout_size, in, in_size); |
||||
if (out_size) |
||||
*out_size = inout_size; |
||||
|
||||
return (ret != SZ_OK); |
||||
} |
||||
|
||||
static int compress_using_lzo(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
/* There is no lzo compression in u-boot, so fake it. */ |
||||
assert(in_size == strlen(plain)); |
||||
assert(memcmp(plain, in, in_size) == 0); |
||||
|
||||
if (lzo_compressed_size > out_max) |
||||
return -1; |
||||
|
||||
memcpy(out, lzo_compressed, lzo_compressed_size); |
||||
if (out_size) |
||||
*out_size = lzo_compressed_size; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int uncompress_using_lzo(void *in, unsigned long in_size, |
||||
void *out, unsigned long out_max, |
||||
unsigned long *out_size) |
||||
{ |
||||
int ret; |
||||
size_t input_size = in_size; |
||||
size_t output_size = out_max; |
||||
|
||||
ret = lzop_decompress(in, input_size, out, &output_size); |
||||
if (out_size) |
||||
*out_size = output_size; |
||||
|
||||
return (ret != LZO_E_OK); |
||||
} |
||||
|
||||
#define errcheck(statement) if (!(statement)) { \ |
||||
fprintf(stderr, "\tFailed: %s\n", #statement); \
|
||||
ret = 1; \
|
||||
goto out; \
|
||||
} |
||||
|
||||
static int run_test(char *name, mutate_func compress, mutate_func uncompress) |
||||
{ |
||||
ulong orig_size, compressed_size, uncompressed_size; |
||||
void *orig_buf; |
||||
void *compressed_buf = NULL; |
||||
void *uncompressed_buf = NULL; |
||||
void *compare_buf = NULL; |
||||
int ret; |
||||
|
||||
printf(" testing %s ...\n", name); |
||||
|
||||
orig_buf = (void *)plain; |
||||
orig_size = strlen(orig_buf); /* Trailing NULL not included. */ |
||||
errcheck(orig_size > 0); |
||||
|
||||
compressed_size = uncompressed_size = TEST_BUFFER_SIZE; |
||||
compressed_buf = malloc(compressed_size); |
||||
errcheck(compressed_buf != NULL); |
||||
uncompressed_buf = malloc(uncompressed_size); |
||||
errcheck(uncompressed_buf != NULL); |
||||
compare_buf = malloc(uncompressed_size); |
||||
errcheck(compare_buf != NULL); |
||||
|
||||
/* Compress works as expected. */ |
||||
printf("\torig_size:%lu\n", orig_size); |
||||
memset(compressed_buf, 'A', TEST_BUFFER_SIZE); |
||||
errcheck(compress(orig_buf, orig_size, |
||||
compressed_buf, compressed_size, |
||||
&compressed_size) == 0); |
||||
printf("\tcompressed_size:%lu\n", compressed_size); |
||||
errcheck(compressed_size > 0); |
||||
errcheck(compressed_size < orig_size); |
||||
errcheck(((char *)compressed_buf)[compressed_size-1] != 'A'); |
||||
errcheck(((char *)compressed_buf)[compressed_size] == 'A'); |
||||
|
||||
/* Uncompresses with space remaining. */ |
||||
errcheck(uncompress(compressed_buf, compressed_size, |
||||
uncompressed_buf, uncompressed_size, |
||||
&uncompressed_size) == 0); |
||||
printf("\tuncompressed_size:%lu\n", uncompressed_size); |
||||
errcheck(uncompressed_size == orig_size); |
||||
errcheck(memcmp(orig_buf, uncompressed_buf, orig_size) == 0); |
||||
|
||||
/* Uncompresses with exactly the right size output buffer. */ |
||||
memset(uncompressed_buf, 'A', TEST_BUFFER_SIZE); |
||||
errcheck(uncompress(compressed_buf, compressed_size, |
||||
uncompressed_buf, orig_size, |
||||
&uncompressed_size) == 0); |
||||
errcheck(uncompressed_size == orig_size); |
||||
errcheck(memcmp(orig_buf, uncompressed_buf, orig_size) == 0); |
||||
errcheck(((char *)uncompressed_buf)[orig_size] == 'A'); |
||||
|
||||
/* Make sure compression does not over-run. */ |
||||
memset(compare_buf, 'A', TEST_BUFFER_SIZE); |
||||
ret = compress(orig_buf, orig_size, |
||||
compare_buf, compressed_size - 1, |
||||
NULL); |
||||
errcheck(((char *)compare_buf)[compressed_size] == 'A'); |
||||
errcheck(ret != 0); |
||||
printf("\tcompress does not overrun\n"); |
||||
|
||||
/* Make sure decompression does not over-run. */ |
||||
memset(compare_buf, 'A', TEST_BUFFER_SIZE); |
||||
ret = uncompress(compressed_buf, compressed_size, |
||||
compare_buf, uncompressed_size - 1, |
||||
NULL); |
||||
errcheck(((char *)compare_buf)[uncompressed_size - 1] == 'A'); |
||||
errcheck(ret != 0); |
||||
printf("\tuncompress does not overrun\n"); |
||||
|
||||
/* Got here, everything is fine. */ |
||||
ret = 0; |
||||
|
||||
out: |
||||
printf(" %s: %s\n", name, ret == 0 ? "ok" : "FAILED"); |
||||
|
||||
free(compare_buf); |
||||
free(uncompressed_buf); |
||||
free(compressed_buf); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
|
||||
static int do_test_compression(cmd_tbl_t *cmdtp, int flag, int argc, |
||||
char * const argv[]) |
||||
{ |
||||
int err = 0; |
||||
|
||||
err += run_test("gzip", compress_using_gzip, uncompress_using_gzip); |
||||
err += run_test("bzip2", compress_using_bzip2, uncompress_using_bzip2); |
||||
err += run_test("lzma", compress_using_lzma, uncompress_using_lzma); |
||||
err += run_test("lzo", compress_using_lzo, uncompress_using_lzo); |
||||
|
||||
printf("test_compression %s\n", err == 0 ? "ok" : "FAILED"); |
||||
|
||||
return err; |
||||
} |
||||
|
||||
U_BOOT_CMD( |
||||
test_compression, 5, 1, do_test_compression, |
||||
"Basic test of compressors: gzip bzip2 lzma lzo", "" |
||||
); |
@ -0,0 +1,132 @@ |
||||
#! /usr/bin/python |
||||
######################################################################## |
||||
# |
||||
# reorder and reformat a file in columns |
||||
# |
||||
# this utility takes lines from its standard input and reproduces them, |
||||
# partially reordered and reformatted, on its standard output. |
||||
# |
||||
# It has the same effect as a 'sort | column -t', with the exception |
||||
# that empty lines, as well as lines which start with a '#' sign, are |
||||
# not affected, i.e. they keep their position and formatting, and act |
||||
# as separators, i.e. the parts before and after them are each sorted |
||||
# separately (but overall field widths are computed across the whole |
||||
# input). |
||||
# |
||||
# Options: |
||||
# -i: |
||||
# --ignore-case: |
||||
# Do not consider case when sorting. |
||||
# -d: |
||||
# --default: |
||||
# What to chage empty fields to. |
||||
# -s <N>: |
||||
# --split=<N>: |
||||
# Treat only the first N whitespace sequences as separators. |
||||
# line content after the Nth separator will count as only one |
||||
# field even if it contains whitespace. |
||||
# Example : '-s 2' causes input 'a b c d e' to be split into |
||||
# three fields, 'a', 'b', and 'c d e'. |
||||
# |
||||
# boards.cfg requires -ids 6. |
||||
# |
||||
######################################################################## |
||||
|
||||
import sys, getopt, locale |
||||
|
||||
# ensure we sort using the C locale. |
||||
|
||||
locale.setlocale(locale.LC_ALL, 'C') |
||||
|
||||
# check options |
||||
|
||||
maxsplit = 0 |
||||
ignore_case = 0 |
||||
default_field ='' |
||||
|
||||
try: |
||||
opts, args = getopt.getopt(sys.argv[1:], "id:s:", |
||||
["ignore-case","default","split="]) |
||||
except getopt.GetoptError as err: |
||||
print str(err) # will print something like "option -a not recognized" |
||||
sys.exit(2) |
||||
|
||||
for o, a in opts: |
||||
if o in ("-s", "--split"): |
||||
maxsplit = eval(a) |
||||
elif o in ("-i", "--ignore-case"): |
||||
ignore_case = 1 |
||||
elif o in ("-d", "--default"): |
||||
default_field = a |
||||
else: |
||||
assert False, "unhandled option" |
||||
|
||||
# collect all lines from standard input and, for the ones which must be |
||||
# reformatted and sorted, count their fields and compute each field's |
||||
# maximum size |
||||
|
||||
input_lines = [] |
||||
field_width = [] |
||||
|
||||
for line in sys.stdin: |
||||
# remove final end of line |
||||
input_line = line.strip('\n') |
||||
if (len(input_line)>0) and (input_line[0] != '#'): |
||||
# sortable line: split into fields |
||||
fields = input_line.split(None,maxsplit) |
||||
# if there are new fields, top up field_widths |
||||
for f in range(len(field_width), len(fields)): |
||||
field_width.append(0) |
||||
# compute the maximum witdh of each field |
||||
for f in range(len(fields)): |
||||
field_width[f] = max(field_width[f],len(fields[f])) |
||||
# collect the line for next stage |
||||
input_lines.append(input_line) |
||||
|
||||
# run through collected input lines, collect the ones which must be |
||||
# reformatted and sorted, and whenever a non-reformattable, non-sortable |
||||
# line is met, sort the collected lines before it and append them to the |
||||
# output lines, then add the non-sortable line too. |
||||
|
||||
output_lines = [] |
||||
sortable_lines = [] |
||||
for input_line in input_lines: |
||||
if (len(input_line)>0) and (input_line[0] != '#'): |
||||
# this line should be reformatted and sorted |
||||
input_fields = input_line.split(None,maxsplit) |
||||
output_fields = []; |
||||
# reformat each field to this field's column width |
||||
for f in range(len(input_fields)): |
||||
output_field = input_fields[f]; |
||||
output_fields.append(output_field.ljust(field_width[f])) |
||||
# any missing field is set to default if it exists |
||||
if default_field != '': |
||||
for f in range(len(input_fields),len(field_width)): |
||||
output_fields.append(default_field.ljust(field_width[f])) |
||||
# join fields using two spaces, like column -t would |
||||
output_line = ' '.join(output_fields); |
||||
# collect line for later |
||||
sortable_lines.append(output_line) |
||||
else: |
||||
# this line is non-sortable |
||||
# sort collected sortable lines |
||||
if ignore_case!=0: |
||||
sortable_lines.sort(key=lambda x: str.lower(locale.strxfrm(x))) |
||||
else: |
||||
sortable_lines.sort(key=lambda x: locale.strxfrm(x)) |
||||
# append sortable lines to the final output |
||||
output_lines.extend(sortable_lines) |
||||
sortable_lines = [] |
||||
# append non-sortable line to the final output |
||||
output_lines.append(input_line) |
||||
# maybe we had sortable lines pending, so append them to the final output |
||||
if ignore_case!=0: |
||||
sortable_lines.sort(key=lambda x: str.lower(locale.strxfrm(x))) |
||||
else: |
||||
sortable_lines.sort(key=lambda x: locale.strxfrm(x)) |
||||
output_lines.extend(sortable_lines) |
||||
|
||||
# run through output lines and print them, except rightmost whitespace |
||||
|
||||
for output_line in output_lines: |
||||
print output_line.rstrip() |
Loading…
Reference in new issue