Skip to contentSkip to conversation

Addition of btrfs file-system in u-boot

PATCH Superseded Adnan Ali 2 participants 4 messages Mar 13, 2013 – Mar 14, 2013

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Adnan Ali

author
#0 lore raw

PATCH v6 1/1 Addition of btrfs file-system in u-boot

Adnan Ali (1):
Introduced btrfs file-system with btrload command

 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1355 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   40 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1944 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v6 1/1 Introduced btrfs file-system with btrload command

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v6:     patch re-formated.
v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1355 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   40 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1944 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h
Makefile +1 -0
index 55bd55c..b3da594 100644
@@ -257,6 +257,7 @@ endif
 LIBS-$(CONFIG_OF_EMBED) += dts/libdts.o
 LIBS-y += arch/$(ARCH)/lib/lib$(ARCH).o
 LIBS-y += fs/libfs.o \
+        fs/btrfs/libbtrfs.o \
 	fs/cbfs/libcbfs.o \
 	fs/cramfs/libcramfs.o \
 	fs/ext4/libext4fs.o \
common/Makefile +1 -0
index 719fc23..d1fae56 100644
@@ -73,6 +73,7 @@ COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
 COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
 COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
 COBJS-$(CONFIG_CMD_BOOTSTAGE) += cmd_bootstage.o
+COBJS-$(CONFIG_CMD_BTR) += cmd_btr.o
 COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o
 COBJS-$(CONFIG_CMD_CBFS) += cmd_cbfs.o
 COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o
common/cmd_btr.c new file +65 -0

65 lines not on this page · raw message

fs/btrfs/Makefile new file +51 -0

51 lines not on this page · raw message

fs/btrfs/btrfs.c new file +1355 -0

1,355 lines not on this page · raw message

fs/btrfs/crc32_c.c new file +40 -0
new file mode 100644
index 0000000..b97c98a
@@ -0,0 +1,40 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * 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.
+ *
+ */
+#include <linux/stat.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <common.h>
+#include <config.h>
+
+u32 crc32c_cal(u32 crc, const char *data, size_t length, u32 *crc32c_table)
+{
+	while (length--)
+		crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
+
+	return crc;
+}
+
+void crc32c_init(u32 *crc32c_table, u32 pol)
+{
+	int i, j;
+	u32 v;
+	const u32 poly = pol; /* Bit-reflected CRC32C polynomial */
+
+	for (i = 0; i < 256; i++) {
+		v = i;
+		for (j = 0; j < 8; j++)
+			v = (v >> 1) ^ ((v & 1) ? poly : 0);
+
+		crc32c_table[i] = v;
+	}
+}
fs/fs.c +10 -0
index 6f5063c..58b155c 100644
@@ -17,6 +17,7 @@
 #include <config.h>
 #include <common.h>
 #include <part.h>
+#include <btrfs.h>
 #include <ext4fs.h>
 #include <fat.h>
 #include <fs.h>
@@ -88,6 +89,15 @@ static struct fstype_info fstypes[] = {
 		.read = fs_read_sandbox,
 	},
 #endif
+#ifdef CONFIG_FS_BTR
+        {
+                .fstype = FS_TYPE_BTR,
+                .probe = btrfs_probe,
+                .close = btrfs_close,
+                .ls = btrfs_ls,
+                .read = btrfs_read_file,
+        },
+#endif
 	{
 		.fstype = FS_TYPE_ANY,
 		.probe = fs_probe_unsupported,
include/btrfs.h new file +416 -0

416 lines not on this page · raw message

include/config_fallbacks.h +4 -0
index bfb9680..28a0a66 100644
@@ -26,4 +26,8 @@
 #define CONFIG_EXT4_WRITE
 #endif
 
+#if defined(CONFIG_CMD_BTR) && !defined(CONFIG_FS_BTR)
+#define CONFIG_FS_BTR
+#endif
+
 #endif	/* __CONFIG_FALLBACKS_H */
include/fs.h +1 -0
index b6d69e5..a8b97ea 100644
@@ -22,6 +22,7 @@
 #define FS_TYPE_FAT	1
 #define FS_TYPE_EXT	2
 #define FS_TYPE_SANDBOX	3
+#define FS_TYPE_BTR	4
 
 /*
  * Tell the fs layer which block device an partition to use for future
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v6 1/1 Introduced btrfs file-system with btrload command

Hi Adnan,

Quoted 6 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

Quoted 7 lines
v6:     patch re-formated.
v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.

Sorry there are just a few more nits here, otherwise it looks fine to me.

Quoted 18 lines
---
 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1355 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   40 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1944 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h

[...]

Quoted 25 lines
fs/btrfs/btrfs.c new file +19 -0
new file mode 100644
index 0000000..19db3a3
@@ -0,0 +1,1355 @@
+/*
+ * (C) Copyright 2013 Codethink Limited
+ * Btrfs port to Uboot by
+ * Adnan Ali <[email protected]>
+
+ * btrfs.c -- readonly btrfs support for syslinux
+ * Some data structures are derivated from btrfs-tools-0.19 ctree.h
+ * Copyright 2009 Intel Corporation; author: alek.du at intel.com
+ *
+ * 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, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ */
+
+#include <common.h>
+#include <btrfs.h>

fs/btrfs/btrfs.c line 29

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+#include <command.h>
+#include <config.h>
+#include <fs.h>
+#include <linux/compiler.h>
+#include <linux/ctype.h>
+#include <linux/stat.h>
+#include <asm/byteorder.h>
+
+unsigned long btr_part_offset;
+static u16 build_crc_table=1;

Better as u8 I think, or just char (since I don't think we have our bool type yet). Also if you change it around to 'crc_table_built' then it can start as 0 (i.e. you don't need to assign it) and this avoid using the data section.

Note also that you have some lines ending with space, including this one.

fs/btrfs/btrfs.c line 1283

Quoted 12 lines
fs/btrfs/btrfs.c new file +12 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+       btrfs_block_dev_desc = rbdd;
+       part_info = info;
+       btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");

Here I think you need two tabs.

Quoted 52 lines
fs/btrfs/btrfs.c new file +52 -0
+
+          return -1;
+       }
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int len)
+{
+       int file_len=0;
+       int len_read;
+       struct com32_filedata filedata;
+       int handle;
+       if (offset != 0) {
+               debug("** Cannot support non-zero offset **\n");
+
+               return -1;
+       }
+
+       handle=btrfs_open_file(filename, &filedata);
+       if (handle < 0) {
+               debug("** File not found %s Invalid handle**\n", filename);
+
+               return -1;
+       }
+
+       /*file handle is valid get the size of the file*/
+       len = filedata.size;
+       if (len == 0)
+               len = file_len;
+
+       len_read = getfssec(&filedata, (char *)buf);
+       if (len_read != len) {
+               debug("** Unable to read file %s **\n", filename);
+
+               return -1;
+       }
+
+       return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+       struct btrfs_dirent *de;
+       struct _DIR_ *dir;

fs/btrfs/btrfs.c line 1345

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+
+       if(*dirname == '/' && *(dirname+1) == 0)
+               *dirname = '.';
+
+       dir = opendir(dirname);
+       if (dir == NULL)
+               return -1;
+
+       while ((de = readdir(dir)) != NULL)
+       ;

I think this ; should be intented

fs/btrfs/crc32_c.c

Quoted 15 lines
fs/btrfs/btrfs.c new file +10 -0
+
+       return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+}
fs/btrfs/crc32_c.c new file +0 -0
new file mode 100644
index 0000000..b97c98a

What do you think about moving this into lib/ ?

fs/btrfs/crc32_c.c line 11

Quoted 12 lines
fs/btrfs/crc32_c.c new file +11 -0
@@ -0,0 +1,40 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * 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.
+ *
+ */

Regards,
Simon

author
#3 lore raw

PATCH v6 1/1 Introduced btrfs file-system with btrload command

Hi

Quoted 9 lines · Simon Glass

Hi Adnan,

Quoted 6 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

Quoted 8 lines
Quoted 7 lines
v6:     patch re-formated.
v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.

Sorry there are just a few more nits here, otherwise it looks fine to me.

Thanks for reply, below are my comments

Quoted 51 lines
Quoted 19 lines
---
  Makefile                   |    1 +
  common/Makefile            |    1 +
  common/cmd_btr.c           |   65 +++
  fs/btrfs/Makefile          |   51 ++
  fs/btrfs/btrfs.c           | 1355 ++++++++++++++++++++++++++++++++++++++++++++
  fs/btrfs/crc32_c.c         |   40 ++
  fs/fs.c                    |   10 +
  include/btrfs.h            |  416 ++++++++++++++
  include/config_fallbacks.h |    4 +
  include/fs.h               |    1 +
  10 files changed, 1944 insertions(+)

create mode 100644 common/cmd_btr.c
create mode 100644 fs/btrfs/Makefile
create mode 100644 fs/btrfs/btrfs.c
create mode 100644 fs/btrfs/crc32_c.c
create mode 100644 include/btrfs.h

[...]

Quoted 31 lines
fs/btrfs/btrfs.c new file +25 -0
new file mode 100644
index 0000000..19db3a3
@@ -0,0 +1,1355 @@
+/*
+ * (C) Copyright 2013 Codethink Limited
+ * Btrfs port to Uboot by
+ * Adnan Ali <[email protected]>
+
+ * btrfs.c -- readonly btrfs support for syslinux
+ * Some data structures are derivated from btrfs-tools-0.19 ctree.h
+ * Copyright 2009 Intel Corporation; author: alek.du at intel.com
+ *
+ * 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, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ */
+
+#include <common.h>
+#include <btrfs.h>
+#include <command.h>
+#include <config.h>
+#include <fs.h>
+#include <linux/compiler.h>
+#include <linux/ctype.h>
+#include <linux/stat.h>
Quoted 8 lines

fs/btrfs/btrfs.c line 29

Quoted 4 lines
fs/btrfs/btrfs.c new file +4 -0
+#include <asm/byteorder.h>
+
+unsigned long btr_part_offset;
+static u16 build_crc_table=1;

Better as u8 I think, or just char (since I don't think we have our bool type yet). Also if you change it around to 'crc_table_built' then it can start as 0 (i.e. you don't need to assign it) and this avoid using the data section.

Ack (Even though that looks fine)

Quoted 2 lines

Note also that you have some lines ending with space, including this one.

Ack i will to remove spaces from top where variables are
declared before btrfs code is this fine with you.

Quoted 14 lines

fs/btrfs/btrfs.c line 1283

Quoted 13 lines
fs/btrfs/btrfs.c new file +12 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+       btrfs_block_dev_desc = rbdd;
+       part_info = info;
+       btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");

Here I think you need two tabs.

Ack

Quoted 56 lines
Quoted 56 lines
fs/btrfs/btrfs.c new file +55 -0
+
+          return -1;
+       }
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int len)
+{
+       int file_len=0;
+       int len_read;
+       struct com32_filedata filedata;
+       int handle;
+       if (offset != 0) {
+               debug("** Cannot support non-zero offset **\n");
+
+               return -1;
+       }
+
+       handle=btrfs_open_file(filename, &filedata);
+       if (handle < 0) {
+               debug("** File not found %s Invalid handle**\n", filename);
+
+               return -1;
+       }
+
+       /*file handle is valid get the size of the file*/
+       len = filedata.size;
+       if (len == 0)
+               len = file_len;
+
+       len_read = getfssec(&filedata, (char *)buf);
+       if (len_read != len) {
+               debug("** Unable to read file %s **\n", filename);
+
+               return -1;
+       }
+
+       return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+       struct btrfs_dirent *de;
+       struct _DIR_ *dir;
+
+       if(*dirname == '/' && *(dirname+1) == 0)
+               *dirname = '.';
Quoted 8 lines

fs/btrfs/btrfs.c line 1345

Quoted 7 lines
fs/btrfs/btrfs.c new file +7 -0
+
+       dir = opendir(dirname);
+       if (dir == NULL)
+               return -1;
+
+       while ((de = readdir(dir)) != NULL)
+       ;

I think this ; should be intented

Sure this is. I think you missed my comments in
previous mail where i mentioned that readdir() prints contents on media. It loops until the last item on media. This ; completes while loop format. I hope this answered your question.

Quoted 17 lines

fs/btrfs/crc32_c.c

Quoted 16 lines
fs/btrfs/btrfs.c new file +10 -0
+
+       return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+}
fs/btrfs/crc32_c.c new file +0 -0
new file mode 100644
index 0000000..b97c98a

What do you think about moving this into lib/ ?

I think i have to move it to lib/. Even though you told me to move it to fs/btrfs/ earlier mails. Ack

Going to send these changes in v7.

Quoted 15 lines

fs/btrfs/crc32_c.c line 11

Quoted 13 lines
fs/btrfs/crc32_c.c new file +11 -0
@@ -0,0 +1,40 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * 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.
+ *
+ */

Regards,
Simon