六、【s3c2440移植u-boot-2016-11】 优化

(一)mtd分区、时钟优化

1、修改include/configs/smdk2440.h

diff -urN u-boot-2016.11/include/configs/smdk2440.h u-boot-2016.11_s3c2440/include/configs/smdk2440.h
--- u-boot-2016.11/include/configs/smdk2440.h   2018-06-16 13:14:39.906908304 +0800
+++ u-boot-2016.11_s3c2440/include/configs/smdk2440.h   2018-06-16 13:18:11.188496279 +0800
@@ -114,6 +114,18 @@
 #define CONFIG_LZO
 #define CONFIG_LZMA

+#define CONFIG_BOOTARGS "console=ttySAC0,115200 noinitrd root=/dev/mtdblock3 init=/linuxrc"
+#define CONFIG_BOOTCOMMAND "nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0"
+#define CONFIG_RAMBOOTCOMMAND  "setenv bootargs noinitrd root=/dev/mtdblock3 " \
+                               "init=/linuxrc console=ttySAC0,115200;" \
+                               " nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0"
+
+#define CONFIG_NFSBOOTCOMMAND  "setenv bootargs console=ttySAC0,115200 root=/dev/nfs " \
+                               "nfsroot=$serverip:/home/book/nfs/nfsroot " \
+                               "ip=$ipaddr:$serverip:$gatewayip:$netmask::eth0:off init=/linuxrc; " \
+                               "nfs 30000000 $serverip:/home/book/nfs/kernel/uImage; bootm 30000000"
+
+
 /*-----------------------------------------------------------------------
  * Physical Memory Map
  */
@@ -139,11 +151,17 @@
 #define CONFIG_SYS_FLASH_BANKS_LIST     { CONFIG_SYS_FLASH_BASE }
 #define CONFIG_SYS_MAX_FLASH_SECT  (128)

-#define CONFIG_ENV_ADDR            (CONFIG_SYS_FLASH_BASE + 0x070000)
-#define CONFIG_ENV_IS_IN_FLASH
-#define CONFIG_ENV_SIZE            0x10000
-/* allow to overwrite serial and ethaddr */
-#define CONFIG_ENV_OVERWRITE
+#define CONFIG_ENV_IS_IN_NAND
+#define CONFIG_ENV_OFFSET      0x00040000
+#define CONFIG_ENV_SIZE        0x00020000
+
+#define CONFIG_CMD_MTDPARTS
+#define CONFIG_MTD_DEVICE
+#define MTDIDS_DEFAULT     "nand0=jz2440-0"  /* 哪一个设备 */
+#define MTDPARTS_DEFAULT   "mtdparts=jz2440-0:256k(u-boot),"   \
+                           "128k(params),"     \
+                           "2m(kernel),"   \
+                           "-(rootfs)"     \

 /*
  * Size of malloc() pool

2、修复之前存在时钟FCLK不是400MHZ的BUG,修改board/samsung/smdk2440/smdk2440.c

diff -urN u-boot-2016.11/board/samsung/smdk2440/smdk2440.c u-boot-2016.11_s3c2440/board/samsung/smdk2440/smdk2440.c
--- u-boot-2016.11/board/samsung/smdk2440/smdk2440.c    2018-06-16 13:14:39.906908304 +0800
+++ u-boot-2016.11_s3c2440/board/samsung/smdk2440/smdk2440.c    2018-06-16 13:17:40.605212280 +0800
@@ -58,11 +58,11 @@
    struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();

    /* to reduce PLL lock time, adjust the LOCKTIME register */
-   writel(0xFFFFFF, &clk_power->locktime);
+   //writel(0xFFFFFF, &clk_power->locktime);

    /* configure MPLL */
-   writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,
-          &clk_power->mpllcon);
+   //writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,
+   //       &clk_power->mpllcon);

    /* some delay between MPLL and UPLL */
    pll_delay(4000);

3、修改Kconfig

diff -urN u-boot-2016.11/Kconfig u-boot-2016.11_s3c2440/Kconfig
--- u-boot-2016.11/Kconfig  2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/Kconfig  2018-06-16 13:19:35.538650278 +0800
@@ -23,10 +23,18 @@
      any files with a filename matching localversion* in your
      object and source tree, in that order.  Your total string can
      be a maximum of 64 characters.
+config COMPILE_TOOLS
+   bool "arm-linux-"
+   default y
+   help
+     select the compile tools
+     if you select the arm-linux- then the TOOLS is arm-linux-gcc
+     if you don't select it or select gcc
+     the compile tool will be gcc

 config LOCALVERSION_AUTO
    bool "Automatically append version information to the version string"
-   default y
+   default n
    help
      This will try to automatically determine if the current tree is a
      release tree by looking for Git tags that belong to the current

4、修改Makefile

diff -urN u-boot-2016.11/Makefile u-boot-2016.11_s3c2440/Makefile
--- u-boot-2016.11/Makefile 2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/Makefile 2018-06-16 13:22:16.314998278 +0800
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 #

+CROSS_COMPILE=arm-linux-
 VERSION = 2016
 PATCHLEVEL = 11
 SUBLEVEL =

5、修改auto_run.sh

diff -urN u-boot-2016.11/auto_run.sh u-boot-2016.11_s3c2440/auto_run.sh
--- u-boot-2016.11/auto_run.sh  2018-06-14 20:16:17.101187155 +0800
+++ u-boot-2016.11_s3c2440/auto_run.sh  2018-06-16 13:20:33.983858278 +0800
@@ -6,4 +6,4 @@
 echo "Load Configuration File..."
 make smdk2440_defconfig
 echo "make..."
-make CROSS_COMPILE=arm-linux-
+make 

6、烧写u-boot.bin到Nor Flash上启动

book@ubuntu:~/u-boot-2016.11$ ./auto_run.sh 

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
现在时钟频率为FCLK=400MHz,修复了之前我移植期间考虑不周的BUG,也可以保存环境变量和已经有mtd分区,以后烧写u-boot和kernel可以分别用:

nand erase.part u-boot;nand write 30000000 u-boot
nand erase.part kernel;nand write 30000000 kernel

(二)优化u-boot网络下载文件

1、修改drivers/net/dm9000x.c,注释了宽带测速

diff -urN u-boot-2016.11/drivers/net/dm9000x.c u-boot-2016.11_s3c2440/drivers/net/dm9000x.c
--- u-boot-2016.11/drivers/net/dm9000x.c    2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/drivers/net/dm9000x.c    2018-06-16 14:39:42.975420781 +0800
@@ -363,6 +363,7 @@
    /* Enable TX/RX interrupt mask */
    DM9000_iow(DM9000_IMR, IMR_PAR);

+#if 0
    i = 0;
    while (!(dm9000_phy_read(1) & 0x20)) {  /* autonegation complete bit */
        udelay(1000);
@@ -394,6 +395,8 @@
        break;
    }
    printf("mode\n");
+#endif
+
    return 0;
 }

@@ -428,7 +431,7 @@
    while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
        !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) {
        if (get_timer(0) >= tmo) {
-           printf("transmission timeout\n");
+           debug("transmission timeout\n");
            break;
        }
    }

2、修改net/nfs.c

diff -urN u-boot-2016.11/net/nfs.c u-boot-2016.11_s3c2440/net/nfs.c
--- u-boot-2016.11/net/nfs.c    2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/net/nfs.c    2018-06-16 14:39:27.555714780 +0800
@@ -37,7 +37,7 @@
 #define HASHES_PER_LINE 65 /* Number of "loading" hashes per line  */
 #define NFS_RETRY_COUNT 30
 #ifndef CONFIG_NFS_TIMEOUT
-# define NFS_TIMEOUT 2000UL
+# define NFS_TIMEOUT 10000UL
 #else
 # define NFS_TIMEOUT CONFIG_NFS_TIMEOUT
 #endif
@@ -906,7 +906,7 @@
              net_boot_file_expected_size_in_blocks << 9);
        print_size(net_boot_file_expected_size_in_blocks << 9, "");
    }
-   debug("\nLoad address: 0x%lx\nLoading: *\b", load_addr);
+   printf("\nLoad address: 0x%lx\nLoading: *\b", load_addr);

    net_set_timeout_handler(nfs_timeout, nfs_timeout_handler);
    net_set_udp_handler(nfs_handler);

3、烧写u-boot.bin到Nor Flash启动

这里写图片描述
此优化可以减少网络下载等待时间,大家可以自己测试下是否缩短了等待下载时间

(三)修改u-boot支持nand write.yaffs2命令

1、测试nand write.yaff或nand write.yaffs2

这里写图片描述
可见我们移植的u-boot命令里面没有nand write.yaff或nand write.yaff2命令

2、修改cmd/nand.c

diff -urN u-boot-2016.11/cmd/nand.c u-boot-2016.11_s3c2440/cmd/nand.c
--- u-boot-2016.11/cmd/nand.c   2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/cmd/nand.c   2018-06-16 22:30:19.522035899 +0800
@@ -623,6 +623,16 @@
                        maxsize, (u_char *)addr,
                        WITH_DROP_FFS | WITH_WR_VERIFY);
 #endif
+#ifdef CONFIG_CMD_NAND_YAFFS
+               } else if (!strcmp(s, ".yaffs2")) {
+                   if (read) {
+                       printf("Unknown nand command suffix ¡®%s¡®.\n", s);
+                       return 1;
+                   }
+                   ret = nand_write_skip_bad(mtd, off, &rwsize,NULL,//ÕâÀï²ÎÊýºÍÀÏ°æ±ÈÒªÐÞ¸ÄÏÂ
+                               maxsize,(u_char *)addr,
+                               WITH_YAFFS_OOB);
+#endif
        } else if (!strcmp(s, ".oob")) {
            /* out-of-band data */
            mtd_oob_ops_t ops = {
@@ -798,6 +808,11 @@
    "    'addr', skipping bad blocks and dropping any pages at the end\n"
    "    of eraseblocks that contain only 0xFF\n"
 #endif
+#ifdef CONFIG_CMD_NAND_YAFFS
+          "nand write.yaffs2 - addr off|partition size\n"
+          "    write ¡®size¡® bytes starting at offset ¡®off¡® with yaffs format\n"
+          "    from memory address ¡®addr¡®, skipping bad blocks.\n"
+#endif
    "nand erase[.spread] [clean] off size - erase 'size' bytes "
    "from offset 'off'\n"
    "    With '.spread', erase enough for given file size, otherwise,\n"

3、修改include/nand.h

diff -urN u-boot-2016.11/include/nand.h u-boot-2016.11_s3c2440/include/nand.h
--- u-boot-2016.11/include/nand.h   2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/include/nand.h   2018-06-16 22:30:38.798035899 +0800
@@ -27,6 +27,11 @@
 #endif
 #endif

+#ifdef CONFIG_CMD_NAND_YAFFS
+#define WITH_YAFFS_OOB    (1 << 0)
+#define WITH_DROP_FFS   (1 << 0)
+#endif
+
 extern void nand_init(void);

 #include <linux/compat.h>

4、修改drivers/mtd/nand/nand_util.c

diff -urN u-boot-2016.11/drivers/mtd/nand/nand_util.c u-boot-2016.11_s3c2440/drivers/mtd/nand/nand_util.c
--- u-boot-2016.11/drivers/mtd/nand/nand_util.c 2016-11-15 00:27:11.000000000 +0800
+++ u-boot-2016.11_s3c2440/drivers/mtd/nand/nand_util.c 2018-06-16 22:31:15.710035899 +0800
@@ -581,7 +581,28 @@
    if (actual)
        *actual = 0;

-   blocksize = mtd->erasesize;
+#ifdef CONFIG_CMD_NAND_YAFFS
+   if (flags & WITH_YAFFS_OOB)
+   {
+       if (flags & ~WITH_YAFFS_OOB)
+           return -EINVAL;
+
+       int pages;
+       pages = mtd->erasesize / mtd->writesize;
+       blocksize = (pages * mtd->oobsize) + mtd->erasesize;
+       if (*length % (mtd->writesize + mtd->oobsize))
+       {
+           printf ("Attempt to write incomplete page"
+                   " in yaffs mode\n");
+           return -EINVAL;
+       }
+   }
+   else
+#endif
+   {
+       blocksize = mtd->erasesize;
+   }
+

    /*
     * nand_write() handles unaligned, partial page writes.
@@ -649,24 +670,53 @@
            write_size = left_to_write;
        else
            write_size = blocksize - block_offset;
-
-       truncated_write_size = write_size;
+#ifdef CONFIG_CMD_NAND_YAFFS
+       if (flags & WITH_YAFFS_OOB)
+       {
+          int page, pages;
+          size_t pagesize = mtd->writesize;
+          size_t pagesize_oob = pagesize + mtd->oobsize;
+          struct mtd_oob_ops ops;
+
+          ops.len = pagesize;
+          ops.ooblen = mtd->oobsize;
+          ops.mode = MTD_OPS_RAW;    //ÕâÀïÒª¸ÄΪRAW
+          ops.ooboffs = 0;
+
+          pages = write_size / pagesize_oob;
+          for (page = 0; page < pages; page++)
+          {
+               WATCHDOG_RESET();
+
+               ops.datbuf = p_buffer;
+               ops.oobbuf = ops.datbuf + pagesize;
+
+               rval = mtd->_write_oob(mtd, offset, &ops);
+               if (rval != 0)
+                   break;
+
+               offset += pagesize;
+               p_buffer += pagesize_oob;
+          }
+       }
+       else
+#endif
+       {
+           truncated_write_size = write_size;
 #ifdef CONFIG_CMD_NAND_TRIMFFS
-       if (flags & WITH_DROP_FFS)
-           truncated_write_size = drop_ffs(mtd, p_buffer,
-                   &write_size);
+           if (flags & WITH_DROP_FFS)
+               truncated_write_size = drop_ffs(mtd, p_buffer,
+                       &write_size);
 #endif
+           rval = nand_write(mtd, offset, &truncated_write_size,
+                               p_buffer);

-       rval = nand_write(mtd, offset, &truncated_write_size,
-               p_buffer);
-
-       if ((flags & WITH_WR_VERIFY) && !rval)
-           rval = nand_verify(mtd, offset,
-               truncated_write_size, p_buffer);
-
-       offset += write_size;
-       p_buffer += write_size;
-
+           if ((flags & WITH_WR_VERIFY) && !rval)
+               rval = nand_verify(mtd, offset,
+                   truncated_write_size, p_buffer);
+           offset += write_size;
+           p_buffer += write_size;
+       }
        if (rval != 0) {
            printf("NAND write to offset %llx failed %d\n",
                offset, rval);

5、修改include/configs/smdk2440.h

diff -urN u-boot-2016.11/include/configs/smdk2440.h u-boot-2016.11_s3c2440/include/configs/smdk2440.h
--- u-boot-2016.11/include/configs/smdk2440.h   2018-06-16 14:37:31.997964781 +0800
+++ u-boot-2016.11_s3c2440/include/configs/smdk2440.h   2018-06-16 22:30:06.282035899 +0800
@@ -155,6 +155,7 @@
 #define CONFIG_ENV_OFFSET      0x00040000
 #define CONFIG_ENV_SIZE        0x00020000

+#define CONFIG_CMD_NAND_YAFFS
 #define CONFIG_CMD_MTDPARTS
 #define CONFIG_MTD_DEVICE
 #define MTDIDS_DEFAULT     "nand0=jz2440-0"  /* 是哪一个设备¸ */

6、修改scripts/config_whitelist.txt

diff -urN u-boot-2016.11/scripts/config_whitelist.txt u-boot-2016.11_s3c2440/scripts/config_whitelist.txt
--- u-boot-2016.11/scripts/config_whitelist.txt 2018-06-16 13:14:39.926918304 +0800
+++ u-boot-2016.11_s3c2440/scripts/config_whitelist.txt 2018-06-16 22:31:57.646035899 +0800
@@ -611,6 +611,7 @@
 CONFIG_CMD_NAND_LOCK_UNLOCK
 CONFIG_CMD_NAND_TORTURE
 CONFIG_CMD_NAND_TRIMFFS
+CONFIG_CMD_NAND_YAFFS
 CONFIG_CMD_ONENAND
 CONFIG_CMD_OTP
 CONFIG_CMD_PART

7、烧写u-boot.bin到Nor Flash上启动

book@ubuntu:~/u-boot-2016.11$ ./auto_run.sh 

这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/david_linux/article/details/80712581