yaffs linux 3.11 編譯時報錯 implicit declaration of function 'create_proc_entry'

近想起來還有一塊mini2440的開發板很久沒有使用了,所以想移植一個基於linux3.10的linux系統,但是在移植yaffs2文件系統的時候出現了一些問題,我將其記錄下來給其他同學解決同樣的問題提供幫助。

1. 首先通過git下載yaffs2代碼。然後進入yaffs2文件夾中執行patch-ker.sh,給linux源代碼打上patch。

$ git clone git://www.aleph1.co.uk/yaffs2
$ cd yaffs2/
$ ./patch-ker.sh c m /work/src/linux3.10.17/

2. 然後在linux的源代碼fs中多了一個yaffs2的文件夾,到此yaffs2文件系統就已經添加到linux3.10中了。在Linux內核源代碼根目錄運行:make menuconfig,移動上下按鍵進行配置:

File Systems
	---> Miscellaneous filesystems
		---> [*]YAFFS2 file system support
並按空格選中它,這樣我們就在內核中添加了yaffs2文件系統的支持,按“Exit”退出內核配置。

3. 編譯linux源代碼。

$ make
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
  CALL    scripts/checksyscalls.sh
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTLD  scripts/mod/modpost
  CHK     include/generated/compile.h
  CC      fs/yaffs2/yaffs_ecc.o
  CC      fs/yaffs2/yaffs_vfs.o
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_proc_debug_write':
fs/yaffs2/yaffs_vfs.c:3304: warning: comparison of distinct pointer types lacks a cast
fs/yaffs2/yaffs_vfs.c: In function 'init_yaffs_fs':
fs/yaffs2/yaffs_vfs.c:3398: error: implicit declaration of function 'create_proc_entry'
fs/yaffs2/yaffs_vfs.c:3399: warning: assignment makes pointer from integer without a cast
fs/yaffs2/yaffs_vfs.c:3402: error: dereferencing pointer to incomplete type
fs/yaffs2/yaffs_vfs.c:3403: error: dereferencing pointer to incomplete type
fs/yaffs2/yaffs_vfs.c:3404: error: dereferencing pointer to incomplete type
make[2]: *** [fs/yaffs2/yaffs_vfs.o] Error 1
make[1]: *** [fs/yaffs2] Error 2
make: *** [fs] Error 2

編譯fs/yaffs2/yaffs_vfs.c時出現錯誤,function 'create_proc_entry'沒有申明。Google之後才知道原來這個接口在linux-3.10被刪除了,應該使用proc_create代替。

4. 修改fs/yaffs2/yaffs_vfs.c

@@ -3384,12 +3384,6 @@ static struct file_system_to_install fs_to_install[] = {
        {NULL, 0}
 };
 
+static const struct file_operations yaffs_fops = {
+        .owner = THIS_MODULE,
+        .read = yaffs_proc_read,
+        .write = yaffs_proc_write,
+};
+
 static int __init init_yaffs_fs(void)
 {
        int error = 0;
@@ -3401,9 +3395,9 @@ static int __init init_yaffs_fs(void)
        mutex_init(&yaffs_context_lock);
 
        /* Install the proc_fs entries */
+       my_proc_entry = proc_create("yaffs",
+                                         S_IRUGO | S_IFREG, YPROC_ROOT, &yaffs_fops);
+#if 0
-       my_proc_entry = create_proc_entry("yaffs",
-                                         S_IRUGO | S_IFREG, YPROC_ROOT);
-
        if (my_proc_entry) {
                my_proc_entry->write_proc = yaffs_proc_write;
                my_proc_entry->read_proc = yaffs_proc_read;
@@ -3411,7 +3405,7 @@ static int __init init_yaffs_fs(void)
        } else {
                return -ENOMEM;
         }
+#endif
-
        /* Now add the file system entries */
 
        fsinst = fs_to_install;

我粘貼一下我修改後的代碼:

//add by jxm.begin
static const struct file_operations yaffs_fops = {
        .owner = THIS_MODULE,
        .read = yaffs_proc_read,
        .write = yaffs_proc_write,
};
//add by jxm.end


static int __init init_yaffs_fs(void)
{
    int error = 0;
    struct file_system_to_install *fsinst;

    yaffs_trace(YAFFS_TRACE_ALWAYS,
        "yaffs built " __DATE__ " " __TIME__ " Installing.");

    mutex_init(&yaffs_context_lock);

    //add by jxm
        my_proc_entry = proc_create("yaffs",S_IRUGO | S_IFREG, YPROC_ROOT, &yaffs_fops);
    /* Install the proc_fs entries */
      //add by jxm begin
      #if 0(使用這個來註釋)
    my_proc_entry = create_proc_entry("yaffs",
                      S_IRUGO | S_IFREG, YPROC_ROOT);

    if (my_proc_entry) {
        my_proc_entry->write_proc = yaffs_proc_write;
        my_proc_entry->read_proc = yaffs_proc_read;
        my_proc_entry->data = NULL;
    } else {
        return -ENOMEM;
        }
     #endif
     //add by jxm.end


    /* Now add the file system entries */

    fsinst = fs_to_install;

    while (fsinst->fst && !error) {
        error = register_filesystem(fsinst->fst);
        if (!error)
            fsinst->installed = 1;
        fsinst++;
    }

    /* Any errors? uninstall  */
    if (error) {
        fsinst = fs_to_install;

        while (fsinst->fst) {
            if (fsinst->installed) {
                unregister_filesystem(fsinst->fst);
                fsinst->installed = 0;
            }
            fsinst++;
        }
    }

    return error;
}

5. 修改之後保存,然後再編譯就可以成功了。

$ make zImage
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
  CALL    scripts/checksyscalls.sh
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTLD  scripts/mod/modpost
  CHK     include/generated/compile.h
  CC      fs/yaffs2/yaffs_vfs.o
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_proc_debug_write':
fs/yaffs2/yaffs_vfs.c:3304: warning: comparison of distinct pointer types lacks a cast
fs/yaffs2/yaffs_vfs.c: At top level:
fs/yaffs2/yaffs_vfs.c:3389: warning: initialization from incompatible pointer type
fs/yaffs2/yaffs_vfs.c:3390: warning: initialization from incompatible pointer type
  CC      fs/yaffs2/yaffs_guts.o
  CC      fs/yaffs2/yaffs_checkptrw.o
  CC      fs/yaffs2/yaffs_packedtags1.o
  CC      fs/yaffs2/yaffs_packedtags2.o
  CC      fs/yaffs2/yaffs_nand.o
  CC      fs/yaffs2/yaffs_tagscompat.o
  CC      fs/yaffs2/yaffs_tagsmarshall.o
  CC      fs/yaffs2/yaffs_mtdif.o
  CC      fs/yaffs2/yaffs_nameval.o
  CC      fs/yaffs2/yaffs_attribs.o
  CC      fs/yaffs2/yaffs_allocator.o
  CC      fs/yaffs2/yaffs_yaffs1.o
  CC      fs/yaffs2/yaffs_yaffs2.o
  CC      fs/yaffs2/yaffs_bitmap.o
  CC      fs/yaffs2/yaffs_summary.o
  CC      fs/yaffs2/yaffs_verify.o
  LD      fs/yaffs2/yaffs.o
  LD      fs/yaffs2/built-in.o
  LD      fs/built-in.o
  LINK    vmlinux
  LD      vmlinux.o
  MODPOST vmlinux.o
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  LD      init/built-in.o
  KSYM    .tmp_kallsyms1.o
  KSYM    .tmp_kallsyms2.o
  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map
  OBJCOPY arch/arm/boot/Image
  Kernel: arch/arm/boot/Image is ready
  GZIP    arch/arm/boot/compressed/piggy.gzip
  AS      arch/arm/boot/compressed/piggy.gzip.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章