]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/zfs.c
3 * ZFS filesystem porting to Uboot by
4 * Jorgen Lundman <lundman at lundman.net>
7 * made from existing GRUB Sources by Sun, GNU and others.
9 * SPDX-License-Identifier: GPL-2.0+
17 #include <linux/ctype.h>
18 #include <asm/byteorder.h>
19 #include <zfs_common.h>
20 #include <linux/stat.h>
23 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
27 #if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
28 #error DOS or EFI partition support must be selected
31 #define DOS_PART_MAGIC_OFFSET 0x1fe
32 #define DOS_FS_TYPE_OFFSET 0x36
33 #define DOS_FS32_TYPE_OFFSET 0x52
35 static int do_zfs_load(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
37 char *filename
= NULL
;
41 disk_partition_t info
;
42 struct blk_desc
*dev_desc
;
46 struct zfs_file zfile
;
53 addr
= simple_strtoul(argv
[3], NULL
, 16);
54 filename
= getenv("bootfile");
57 addr_str
= getenv("loadaddr");
59 addr
= simple_strtoul(addr_str
, NULL
, 16);
61 addr
= CONFIG_SYS_LOAD_ADDR
;
71 count
= simple_strtoul(argv
[5], NULL
, 16);
75 return cmd_usage(cmdtp
);
79 puts("** No boot file defined **\n");
83 part
= blk_get_device_part_str(argv
[1], argv
[2], &dev_desc
, &info
, 1);
87 dev
= dev_desc
->devnum
;
88 printf("Loading file \"%s\" from %s device %d%c%c\n",
89 filename
, argv
[1], dev
,
90 part
? ':' : ' ', part
? part
+ '0' : ' ');
92 zfs_set_blk_dev(dev_desc
, &info
);
93 vdev
.part_length
= info
.size
;
95 memset(&zfile
, 0, sizeof(zfile
));
97 if (zfs_open(&zfile
, filename
)) {
98 printf("** File not found %s **\n", filename
);
102 if ((count
< zfile
.size
) && (count
!= 0))
103 zfile
.size
= (uint64_t)count
;
105 if (zfs_read(&zfile
, (char *)addr
, zfile
.size
) != zfile
.size
) {
106 printf("** Unable to read \"%s\" from %s %d:%d **\n",
107 filename
, argv
[1], dev
, part
);
114 /* Loading ok, update default load address */
117 printf("%llu bytes read\n", zfile
.size
);
118 setenv_hex("filesize", zfile
.size
);
124 int zfs_print(const char *entry
, const struct zfs_dirhook_info
*data
)
127 data
->dir
? "<DIR> " : " ",
129 return 0; /* 0 continue, 1 stop */
134 static int do_zfs_ls(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
136 const char *filename
= "/";
138 struct blk_desc
*dev_desc
;
139 disk_partition_t info
;
140 struct device_s vdev
;
143 return cmd_usage(cmdtp
);
148 part
= blk_get_device_part_str(argv
[1], argv
[2], &dev_desc
, &info
, 1);
152 zfs_set_blk_dev(dev_desc
, &info
);
153 vdev
.part_length
= info
.size
;
155 zfs_ls(&vdev
, filename
,
162 U_BOOT_CMD(zfsls
, 4, 1, do_zfs_ls
,
163 "list files in a directory (default /)",
164 "<interface> <dev[:part]> [directory]\n"
165 " - list files from 'dev' on 'interface' in a '/DATASET/@/$dir/'");
167 U_BOOT_CMD(zfsload
, 6, 0, do_zfs_load
,
168 "load binary file from a ZFS filesystem",
169 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
170 " - load binary file '/DATASET/@/$dir/$file' from 'dev' on 'interface'\n"
171 " to address 'addr' from ZFS filesystem");