From: SangHee Kim Date: Tue, 20 Apr 2010 01:52:43 +0000 (+0900) Subject: recovery: code clean up X-Git-Tag: JD12_20100423~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b5ea05fa4d6cd9f0f400c00e744b5773ff6b631;p=kernel%2Fu-boot.git recovery: code clean up --- diff --git a/include/configs/s5pc1xx_universal.h b/include/configs/s5pc1xx_universal.h index 7ccdd23..7db3b45 100644 --- a/include/configs/s5pc1xx_universal.h +++ b/include/configs/s5pc1xx_universal.h @@ -339,6 +339,7 @@ #define CONFIG_ONENAND_START_PAGE 4 /* IPL + RECOVERY + U-BOOT */ +#define CONFIG_RECOVERY_UBOOT_BLOCK 1 #define CONFIG_RECOVERY_BOOT_BLOCKS 4 #define CONFIG_ENV_IS_IN_ONENAND 1 diff --git a/recovery/Makefile b/recovery/Makefile index f073c33..c931f47 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -31,7 +31,6 @@ OBJS := $(addprefix $(obj),$(OBJS)) LIBS = drivers/onenand/libonenand.a LIBS := $(addprefix $(recoveryobj),$(LIBS)) -# .PHONY : $(LIBS) $(TIMESTAMP_FILE) $(VERSION_FILE) LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).a LIBBOARD := $(addprefix $(recoveryobj),$(LIBBOARD)) diff --git a/recovery/board/samsung/universal/universal.c b/recovery/board/samsung/universal/universal.c index 5c268fc..f84e926 100644 --- a/recovery/board/samsung/universal/universal.c +++ b/recovery/board/samsung/universal/universal.c @@ -1,189 +1,177 @@ -/* - * (C) Copyright 2010 Samsung Electronics - * - * 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 -#include -#include -#include -#include -#include -#include -#include "../../../onenand.h" - -typedef int (init_fnc_t) (void); - -DECLARE_GLOBAL_DATA_PTR; - -static struct s5pc110_gpio *s5pc110_gpio; - -static void sdelay(unsigned long usec) -{ - ulong kv; - - do { - kv = 0x100000; - while (kv-- > 0) { - } - usec--; - } while(usec); -} - -static int check_keypad(void) -{ - unsigned int condition = 0; - unsigned int reg, value; - unsigned int col_num, row_num; - unsigned int col_mask; - unsigned int col_mask_shift; - unsigned int row_state[4] = {0, 0, 0, 0}; - unsigned int i; - - /* board is limo universal */ - - row_num = 2; - col_num = 3; - - for (i = 0; i < sizeof(row_state)/sizeof(int); i++) { - row_state[i] = 0; - } - - for (i = 0; i < row_num; i++) { - /* Set GPH3[3:0] to KP_ROW[3:0] */ - gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3); - gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP); - } - - for (i = 0; i < col_num; i++) - /* Set GPH2[3:0] to KP_COL[3:0] */ - gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3); - - reg = S5PC110_KEYPAD_BASE; - col_mask = S5PC110_KEYIFCOLEN_MASK; - col_mask_shift = 8; - - /* KEYIFCOL reg clear */ - writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); - - /* key_scan */ - for (i = 0; i < col_num; i++) { - value = col_mask; - value &= ~(1 << i) << col_mask_shift; - - writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET); - sdelay(1000); - - value = readl(reg + S5PC1XX_KEYIFROW_OFFSET); - row_state[i] = ~value & ((1 << row_num) - 1); - } - - /* KEYIFCOL reg clear */ - writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); - - /* check volume up/down */ - if ((row_state[1] & 0x3) == 0x3) { - condition = 1; - } - - return condition; -} - -static int check_block(void) -{ - struct onenand_op *onenand_ops = onenand_get_interface(); - struct mtd_info *mtd = onenand_ops->mtd; - struct onenand_chip *this = mtd->priv; - int i; - int page_to_check = 4; - int ret, retlen = 0; - ulong blocksize = 1 << this->erase_shift; - ulong pagesize = 1 << this->page_shift; - u_char *down_ram_addr = (unsigned char *)CONFIG_SYS_DOWN_ADDR; - ulong uboot_start_addr = CONFIG_RECOVERY_BOOTSTART_BLOCK << this->erase_shift; - u_char verify_buf[0x10]; - - onenand_ops->read(uboot_start_addr, blocksize, &retlen, down_ram_addr, 0); - if (retlen != blocksize) - { - return 1; - } - - memset(verify_buf, 0xFF, sizeof(verify_buf)); - - for (i = 0; i < page_to_check; i++) { - ret = memcmp(down_ram_addr + pagesize*i, verify_buf, sizeof(verify_buf)); - if (ret) - { - break; - } - } - - if (i == page_to_check) { - return 1; - } - - return 0; -} - -int board_check_condition(void) -{ - if (check_keypad()) { - return 1; - } - - if (check_block()) { - return 1; - } - - return 0; -} - -int board_load_uboot(unsigned char *buf) -{ - struct mtd_info *mtd = &onenand_mtd; - struct onenand_chip *this = mtd->priv; - int offset; - size_t size; - size_t ret; - - offset = CONFIG_RECOVERY_BOOTSTART_BLOCK << this->erase_shift; - size = CONFIG_SYS_MONITOR_LEN; - - mtd->read(mtd, offset, size, &ret, buf); - - if (size != ret) { - return -1; - } - - return 0; -} - -int board_update_uboot(void) -{ - return 0; -} - -void board_recovery_init(void) -{ - /* Set Initial global variables */ - s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE; -} - +/* + * (C) Copyright 2010 Samsung Electronics + * + * 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 +#include +#include +#include +#include +#include +#include +#include "../../../onenand.h" + +typedef int (init_fnc_t) (void); + +DECLARE_GLOBAL_DATA_PTR; + +static struct s5pc110_gpio *s5pc110_gpio; + +static void sdelay(unsigned long usec) +{ + ulong kv; + + do { + kv = 0x100000; + while (kv) + kv--; + usec--; + } while (usec); +} + +static int check_keypad(void) +{ + unsigned int condition = 0; + unsigned int reg, value; + unsigned int col_num, row_num; + unsigned int col_mask; + unsigned int col_mask_shift; + unsigned int row_state[4] = {0, 0, 0, 0}; + unsigned int i; + + /* board is limo universal */ + + row_num = 2; + col_num = 3; + + for (i = 0; i < sizeof(row_state)/sizeof(int); i++) + row_state[i] = 0; + + for (i = 0; i < row_num; i++) { + /* Set GPH3[3:0] to KP_ROW[3:0] */ + gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3); + gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP); + } + + for (i = 0; i < col_num; i++) + /* Set GPH2[3:0] to KP_COL[3:0] */ + gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3); + + reg = S5PC110_KEYPAD_BASE; + col_mask = S5PC110_KEYIFCOLEN_MASK; + col_mask_shift = 8; + + /* KEYIFCOL reg clear */ + writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); + + /* key_scan */ + for (i = 0; i < col_num; i++) { + value = col_mask; + value &= ~(1 << i) << col_mask_shift; + + writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET); + sdelay(1000); + + value = readl(reg + S5PC1XX_KEYIFROW_OFFSET); + row_state[i] = ~value & ((1 << row_num) - 1); + } + + /* KEYIFCOL reg clear */ + writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); + + /* check volume up/down */ + if ((row_state[1] & 0x3) == 0x3) + condition = 1; + + return condition; +} + +static int check_block(void) +{ + struct onenand_op *onenand_ops = onenand_get_interface(); + struct mtd_info *mtd = onenand_ops->mtd; + struct onenand_chip *this = mtd->priv; + int i; + int page_to_check = 4; + int ret, retlen = 0; + ulong blocksize = 1 << this->erase_shift; + ulong pagesize = 1 << this->page_shift; + u_char *down_ram_addr; + ulong uboot_addr; + u_char verify_buf[0x10]; + + down_ram_addr = (unsigned char *)CONFIG_SYS_DOWN_ADDR; + uboot_addr = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift; + + onenand_ops->read(uboot_addr, blocksize, &retlen, down_ram_addr, 0); + if (retlen != blocksize) + return 1; + + memset(verify_buf, 0xFF, sizeof(verify_buf)); + + for (i = 0; i < page_to_check; i++) { + ret = memcmp(down_ram_addr + pagesize*i, verify_buf, + sizeof(verify_buf)); + if (ret) + break; + } + + if (i == page_to_check) + return 1; + + return 0; +} + +int board_check_condition(void) +{ + if (check_keypad()) + return 1; + + if (check_block()) + return 1; + + return 0; +} + +int board_load_uboot(unsigned char *buf) +{ + struct mtd_info *mtd = &onenand_mtd; + struct onenand_chip *this = mtd->priv; + int offset; + size_t size; + size_t ret; + + offset = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift; + size = CONFIG_SYS_MONITOR_LEN; + + mtd->read(mtd, offset, size, &ret, buf); + + if (size != ret) + return -1; + + return 0; +} + +void board_recovery_init(void) +{ + /* Set Initial global variables */ + s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE; +} diff --git a/recovery/common.h b/recovery/common.h index 6364d0f..b6960f7 100644 --- a/recovery/common.h +++ b/recovery/common.h @@ -14,7 +14,6 @@ extern int board_check_condition(void); extern int board_load_uboot(unsigned char *buf); -extern int board_update_uboot(void); extern void board_recovery_init(void); #endif diff --git a/recovery/drivers/onenand/onenand_base.c b/recovery/drivers/onenand/onenand_base.c index f045da4..f62e5d1 100644 --- a/recovery/drivers/onenand/onenand_base.c +++ b/recovery/drivers/onenand/onenand_base.c @@ -20,7 +20,6 @@ */ #include -//#include #include #include #include @@ -32,8 +31,8 @@ #ifdef printk #undef printk #endif -#define printk(...) do{} while(0) -#define puts(...) do{} while(0) +#define printk(...) do {} while (0) +#define puts(...) do {} while (0) extern void *memcpy32(void *dst, const void *src, int len); diff --git a/recovery/onenand.c b/recovery/onenand.c index 55b31c5..9f70e02 100644 --- a/recovery/onenand.c +++ b/recovery/onenand.c @@ -35,12 +35,12 @@ #ifdef printk #undef printk #endif -#define printk(...) do{} while(0) -#define puts(...) do{} while(0) +#define printk(...) do {} while (0) +#define puts(...) do {} while (0) #ifdef printf #undef printf #endif -#define printf(...) do{} while(0) +#define printf(...) do {} while (0) struct mtd_info onenand_mtd; struct onenand_chip onenand_chip; @@ -52,47 +52,6 @@ static struct mtd_info *mtd = &onenand_mtd; static loff_t next_ofs; static loff_t skip_ofs; -static inline int str2long(char *p, ulong *num) -{ - char *endptr; - - *num = simple_strtoul(p, &endptr, 16); - return (*p != '\0' && *endptr == '\0') ? 1 : 0; -} -#if 0 -static int arg_off_size(int argc, char *argv[], ulong *off, ssize_t *size) -{ - if (argc >= 1) { - if (!(str2long(argv[0], off))) { - printf("'%s' is not a number\n", argv[0]); - return -1; - } - } else { - *off = 0; - } - - if (argc >= 2) { - if (!(str2long(argv[1], (ulong *)size))) { - printf("'%s' is not a number\n", argv[1]); - return -1; - } - } else { - *size = mtd->size - *off; - } - - if ((*off + *size) > mtd->size) { - printf("total chip size (0x%llx) exceeded!\n", mtd->size); - return -1; - } -#if 0 - if (*size == mtd->size) - puts("whole chip\n"); - else - printf("offset 0x%lx, size 0x%x\n", *off, *size); -#endif - return 0; -} -#endif static int onenand_block_read(loff_t from, ssize_t len, ssize_t *retlen, u_char *buf, int oob) { @@ -111,7 +70,7 @@ static int onenand_block_read(loff_t from, ssize_t len, ret = mtd->block_isbad(mtd, ofs); if (ret) { - printk("Bad blocks %d at 0x%x\n", + printf("Bad blocks %d at 0x%x\n", (u32)(ofs >> this->erase_shift), (u32)ofs); ofs += blocksize; /* FIXME need to check how to handle the 'len' */ @@ -130,7 +89,7 @@ static int onenand_block_read(loff_t from, ssize_t len, ops.retlen = 0; ret = mtd->read_oob(mtd, ofs, &ops); if (ret) { - printk("Read failed 0x%x, %d\n", (u32)ofs, ret); + printf("Read failed 0x%x, %d\n", (u32)ofs, ret); ofs += thislen; continue; } @@ -171,7 +130,7 @@ static int onenand_block_write(loff_t to, ssize_t len, ret = mtd->block_isbad(mtd, ofs); if (ret) { - printk("Bad blocks %d at 0x%x\n", + printf("Bad blocks %d at 0x%x\n", (u32)(ofs >> this->erase_shift), (u32)ofs); skip_ofs += blocksize; goto next; @@ -182,7 +141,7 @@ static int onenand_block_write(loff_t to, ssize_t len, ops.retlen = 0; ret = mtd->write_oob(mtd, ofs, &ops); if (ret) { - printk("Write failed 0x%x, %d", (u32)ofs, ret); + printf("Write failed 0x%x, %d", (u32)ofs, ret); skip_ofs += thislen; goto next; } @@ -230,68 +189,13 @@ static int onenand_block_erase(u32 start, u32 size, int force) return 0; } -#if 0 -static int onenand_dump(struct mtd_info *mtd, ulong off, int only_oob) -{ - int i; - u_char *datbuf, *oobbuf, *p; - struct mtd_oob_ops ops; - loff_t addr; - - datbuf = malloc(mtd->writesize + mtd->oobsize); - oobbuf = malloc(mtd->oobsize); - if (!datbuf || !oobbuf) { - puts("No memory for page buffer\n"); - return 1; - } - off &= ~(mtd->writesize - 1); - addr = (loff_t) off; - memset(&ops, 0, sizeof(ops)); - ops.datbuf = datbuf; - ops.oobbuf = oobbuf; /* must exist, but oob data will be appended to ops.datbuf */ - ops.len = mtd->writesize; - ops.ooblen = mtd->oobsize; - ops.retlen = 0; - i = mtd->read_oob(mtd, addr, &ops); - if (i < 0) { - printf("Error (%d) reading page %08lx\n", i, off); - free(datbuf); - free(oobbuf); - return 1; - } - printf("Page %08lx dump:\n", off); - i = mtd->writesize >> 4; - p = datbuf; - - while (i--) { - if (!only_oob) - printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" - " %02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], - p[15]); - p += 16; - } - puts("OOB:\n"); - p = oobbuf; - i = mtd->oobsize >> 3; - while (i--) { - printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - p += 8; - } - free(datbuf); - free(oobbuf); - return 0; -} -#endif void onenand_set_interface(struct onenand_op *onenand) { onenand->read = onenand_block_read; onenand->write = onenand_block_write; onenand->erase = onenand_block_erase; - + onenand->mtd = &onenand_mtd; onenand->this = &onenand_chip; } @@ -314,22 +218,6 @@ void onenand_init(void) onenand_scan(&onenand_mtd, 1); -#if 0 - if (onenand_chip.device_id & DEVICE_IS_FLEXONENAND) - puts("Flex-"); - puts("OneNAND: "); - print_size(onenand_chip.chipsize, "\n"); -#endif - -#if 0 - /* - * Add MTD device so that we can reference it later - * via the mtdcore infrastructure (e.g. ubi). - */ - onenand_mtd.name = dev_name; - add_mtd_device(&onenand_mtd); -#else onenand_set_interface(&onenand_ops); -#endif } diff --git a/recovery/onenand.h b/recovery/onenand.h index e629cce..503e8da 100644 --- a/recovery/onenand.h +++ b/recovery/onenand.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ - + #ifndef _ONENAND_H #define _ONENAND_H diff --git a/recovery/recovery.c b/recovery/recovery.c index 7c56132..1e8c842 100644 --- a/recovery/recovery.c +++ b/recovery/recovery.c @@ -29,7 +29,7 @@ typedef int (init_fnc_t)(void); -void normal_boot(void) +static void normal_boot(void) { uchar *buf; @@ -40,11 +40,11 @@ void normal_boot(void) ((init_fnc_t *)CONFIG_SYS_BOOT_ADDR)(); } -void recovery_boot(void) +static void recovery_boot(void) { /* usb download and write image */ do_usbd_down(); - + /* reboot */ reset_cpu(0); } @@ -52,25 +52,25 @@ void recovery_boot(void) void start_recovery_boot(void) { /* armboot_start is defined in the board-specific linker script */ - mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN, + mem_malloc_init(_armboot_start - CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN); onenand_init(); board_recovery_init(); - - if (board_check_condition()) { + + if (board_check_condition()) recovery_boot(); - } else { + else normal_boot(); - } + /* NOTREACHED - no way out of command loop except booting */ } /* * origin at lib_arm/eabi_compat.c to support EABI */ -int raise (int signum) +int raise(int signum) { return 0; }