recovery: code clean up
authorSangHee Kim <sh0130.kim@samsung.com>
Tue, 20 Apr 2010 01:52:43 +0000 (10:52 +0900)
committerSangHee Kim <sh0130.kim@samsung.com>
Tue, 20 Apr 2010 01:52:43 +0000 (10:52 +0900)
include/configs/s5pc1xx_universal.h
recovery/Makefile
recovery/board/samsung/universal/universal.c
recovery/common.h
recovery/drivers/onenand/onenand_base.c
recovery/onenand.c
recovery/onenand.h
recovery/recovery.c

index 7ccdd23..7db3b45 100644 (file)
 #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
index f073c33..c931f47 100644 (file)
@@ -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))
index 5c268fc..f84e926 100644 (file)
-/*\r
- * (C) Copyright 2010 Samsung Electronics\r
- *\r
- * See file CREDITS for list of people who contributed to this\r
- * project.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License as\r
- * published by the Free Software Foundation; either version 2 of\r
- * the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,\r
- * MA 02111-1307 USA\r
- */\r
-\r
-#include <common.h>\r
-#include <linux/mtd/compat.h>\r
-#include <linux/mtd/mtd.h>\r
-#include <linux/mtd/onenand.h>\r
-#include <asm/io.h>\r
-#include <asm/arch/gpio.h>\r
-#include <asm/arch/keypad.h>\r
-#include "../../../onenand.h"\r
-\r
-typedef int (init_fnc_t) (void);\r
-\r
-DECLARE_GLOBAL_DATA_PTR;\r
-\r
-static struct s5pc110_gpio *s5pc110_gpio;\r
-\r
-static void sdelay(unsigned long usec)\r
-{\r
-       ulong kv;\r
-\r
-       do {\r
-               kv = 0x100000;\r
-               while (kv-- > 0) {\r
-               }\r
-               usec--;\r
-       } while(usec);\r
-}\r
-\r
-static int check_keypad(void)\r
-{\r
-       unsigned int condition = 0;\r
-       unsigned int reg, value;\r
-       unsigned int col_num, row_num;\r
-       unsigned int col_mask;\r
-       unsigned int col_mask_shift;\r
-       unsigned int row_state[4] = {0, 0, 0, 0};\r
-       unsigned int i;\r
-\r
-       /* board is limo universal */\r
-\r
-       row_num = 2;\r
-       col_num = 3;\r
-\r
-       for (i = 0; i < sizeof(row_state)/sizeof(int); i++) {\r
-               row_state[i] = 0;\r
-       }\r
-       \r
-       for (i = 0; i < row_num; i++) {\r
-               /* Set GPH3[3:0] to KP_ROW[3:0] */\r
-               gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);\r
-               gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);\r
-       }\r
-\r
-       for (i = 0; i < col_num; i++)\r
-               /* Set GPH2[3:0] to KP_COL[3:0] */\r
-               gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);\r
-\r
-       reg = S5PC110_KEYPAD_BASE;\r
-       col_mask = S5PC110_KEYIFCOLEN_MASK;\r
-       col_mask_shift = 8;\r
-\r
-       /* KEYIFCOL reg clear */\r
-       writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);\r
-\r
-       /* key_scan */\r
-       for (i = 0; i < col_num; i++) {\r
-               value = col_mask;\r
-               value &= ~(1 << i) << col_mask_shift;\r
-\r
-               writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);\r
-               sdelay(1000);\r
-\r
-               value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);\r
-               row_state[i] = ~value & ((1 << row_num) - 1);\r
-       }\r
-\r
-       /* KEYIFCOL reg clear */\r
-       writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);\r
-\r
-       /* check volume up/down */\r
-       if ((row_state[1] & 0x3) == 0x3) {\r
-               condition = 1;\r
-       }\r
-\r
-       return condition;\r
-}\r
-\r
-static int check_block(void)\r
-{\r
-       struct onenand_op *onenand_ops = onenand_get_interface();\r
-       struct mtd_info *mtd = onenand_ops->mtd;\r
-       struct onenand_chip *this = mtd->priv;\r
-       int i;\r
-       int page_to_check = 4;\r
-       int ret, retlen = 0;\r
-       ulong blocksize = 1 << this->erase_shift;\r
-       ulong pagesize = 1 << this->page_shift;\r
-       u_char *down_ram_addr = (unsigned char *)CONFIG_SYS_DOWN_ADDR;\r
-       ulong uboot_start_addr = CONFIG_RECOVERY_BOOTSTART_BLOCK << this->erase_shift;\r
-       u_char verify_buf[0x10];\r
-\r
-       onenand_ops->read(uboot_start_addr, blocksize, &retlen, down_ram_addr, 0);\r
-       if (retlen != blocksize)\r
-       {\r
-               return 1;\r
-       }\r
-\r
-       memset(verify_buf, 0xFF, sizeof(verify_buf));\r
-\r
-       for (i = 0; i < page_to_check; i++) {\r
-               ret = memcmp(down_ram_addr + pagesize*i, verify_buf, sizeof(verify_buf));\r
-               if (ret)\r
-               {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if (i == page_to_check) {\r
-               return 1;\r
-       }\r
-       \r
-       return 0;\r
-}\r
-\r
-int board_check_condition(void)\r
-{\r
-       if (check_keypad()) {\r
-               return 1;\r
-       }\r
-       \r
-       if (check_block()) {\r
-               return 1;\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int board_load_uboot(unsigned char *buf)\r
-{\r
-       struct mtd_info *mtd = &onenand_mtd;\r
-       struct onenand_chip *this = mtd->priv;\r
-       int offset;\r
-       size_t size;\r
-       size_t ret;\r
-\r
-       offset = CONFIG_RECOVERY_BOOTSTART_BLOCK << this->erase_shift;\r
-       size = CONFIG_SYS_MONITOR_LEN;\r
-\r
-       mtd->read(mtd, offset, size, &ret, buf);\r
-\r
-       if (size != ret) {\r
-               return -1;\r
-       }\r
-               \r
-       return 0;\r
-}\r
-\r
-int board_update_uboot(void)\r
-{\r
-       return 0;\r
-}\r
-\r
-void board_recovery_init(void)\r
-{\r
-       /* Set Initial global variables */\r
-       s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;\r
-}\r
-\r
+/*
+ * (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 <common.h>
+#include <linux/mtd/compat.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/onenand.h>
+#include <asm/io.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/keypad.h>
+#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;
+}
index 6364d0f..b6960f7 100644 (file)
@@ -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
index f045da4..f62e5d1 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 #include <common.h>
-//#include <compiler.h>
 #include <linux/mtd/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
@@ -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);
 
index 55b31c5..9f70e02 100644 (file)
 #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
 }
 
index e629cce..503e8da 100644 (file)
@@ -17,7 +17,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
  */
+
 #ifndef _ONENAND_H
 #define _ONENAND_H
 
index 7c56132..1e8c842 100644 (file)
@@ -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;
 }