From b06750501f5c0eef7fef094f13d2f2e313c60b79 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 11 Feb 2016 13:23:25 -0700 Subject: dm: core: Add uclass_first_device_err() to return a valid device A common pattern is to call uclass_first_device() and then check if it actually returns a device. Add a new function which does this, returning an error if there are no devices in that uclass. Signed-off-by: Simon Glass --- include/dm/uclass.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dm/uclass.h b/include/dm/uclass.h index bfbd27a..fd368b6 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -200,18 +200,29 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, * * @id: Uclass ID to look up * @devp: Returns pointer to the first device in that uclass, or NULL if none - * @return 0 if OK (found or not found), -1 on error + * @return 0 if OK (found or not found), other -ve on error */ int uclass_first_device(enum uclass_id id, struct udevice **devp); /** + * uclass_first_device_err() - Get the first device in a uclass + * + * The device returned is probed if necessary, and ready for use + * + * @id: Uclass ID to look up + * @devp: Returns pointer to the first device in that uclass, or NULL if none + * @return 0 if found, -ENODEV if not found, other -ve on error + */ +int uclass_first_device_err(enum uclass_id id, struct udevice **devp); + +/** * uclass_next_device() - Get the next device in a uclass * * The device returned is probed if necessary, and ready for use * * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the same uclass, or NULL if none - * @return 0 if OK (found or not found), -1 on error + * @return 0 if OK (found or not found), other -ve on error */ int uclass_next_device(struct udevice **devp); -- cgit v1.1 From b391d743363247bf502fb0b5ca098246ea5a1512 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 8 Mar 2016 18:19:10 +0900 Subject: debug_uart: output CR along with LF The serial output from the debug UART carries on going far to the right in the console. Signed-off-by: Masahiro Yamada Reviewed-by: Stefan Roese Reviewed-by: Simon Glass --- include/debug_uart.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/debug_uart.h b/include/debug_uart.h index 5d5349b..0d640b9 100644 --- a/include/debug_uart.h +++ b/include/debug_uart.h @@ -117,13 +117,15 @@ void printhex8(uint value); #define DEBUG_UART_FUNCS \ void printch(int ch) \ { \ + if (ch == '\n') \ + _debug_uart_putc('\r'); \ _debug_uart_putc(ch); \ } \ \ void printascii(const char *str) \ { \ while (*str) \ - _debug_uart_putc(*str++); \ + printch(*str++); \ } \ \ static inline void printhex1(uint digit) \ -- cgit v1.1 From 4101f6879256720b30df712089a3df18565f9203 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:34 -0700 Subject: dm: Drop the block_dev_desc_t typedef Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long and causes 80-column violations, rename it to struct blk_desc. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/common.h | 2 +- include/ext4fs.h | 6 +-- include/fat.h | 4 +- include/ide.h | 6 +-- include/mmc.h | 2 +- include/part.h | 130 ++++++++++++++++++++++++--------------------- include/reiserfs.h | 2 +- include/sandboxblockdev.h | 2 +- include/sandboxfs.h | 2 +- include/sata.h | 2 +- include/spl.h | 10 ++-- include/systemace.h | 2 +- include/ubifs_uboot.h | 2 +- include/usb.h | 2 +- include/usb_mass_storage.h | 2 +- include/zfs_common.h | 4 +- 16 files changed, 94 insertions(+), 86 deletions(-) (limited to 'include') diff --git a/include/common.h b/include/common.h index 1563d64..1317f9b 100644 --- a/include/common.h +++ b/include/common.h @@ -813,7 +813,7 @@ void gzwrite_progress_finish(int retcode, * for files under 4GiB */ int gzwrite(unsigned char *src, int len, - struct block_dev_desc *dev, + struct blk_desc *dev, unsigned long szwritebuf, u64 startoffs, u64 szexpected); diff --git a/include/ext4fs.h b/include/ext4fs.h index 6888adc..cc765ae 100644 --- a/include/ext4fs.h +++ b/include/ext4fs.h @@ -110,7 +110,7 @@ struct ext_filesystem { /* Journal Related */ /* Block Device Descriptor */ - block_dev_desc_t *dev_desc; + struct blk_desc *dev_desc; }; extern struct ext2_data *ext4fs_root; @@ -141,9 +141,9 @@ int ext4fs_exists(const char *filename); int ext4fs_size(const char *filename, loff_t *size); void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); -void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); +void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); long int read_allocated_block(struct ext2_inode *inode, int fileblock); -int ext4fs_probe(block_dev_desc_t *fs_dev_desc, +int ext4fs_probe(struct blk_desc *fs_dev_desc, disk_partition_t *fs_partition); int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); diff --git a/include/fat.h b/include/fat.h index 3038bd7..9d053e6 100644 --- a/include/fat.h +++ b/include/fat.h @@ -203,8 +203,8 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer, loff_t maxsize, loff_t *actread); int file_fat_read(const char *filename, void *buffer, int maxsize); const char *file_getfsname(int idx); -int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); -int fat_register_device(block_dev_desc_t *dev_desc, int part_no); +int fat_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); +int fat_register_device(struct blk_desc *dev_desc, int part_no); int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite); diff --git a/include/ide.h b/include/ide.h index f9357be..2407393 100644 --- a/include/ide.h +++ b/include/ide.h @@ -41,10 +41,10 @@ typedef ulong lbaint_t; */ void ide_init(void); -typedef struct block_dev_desc block_dev_desc_t; -ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt, +struct blk_desc; +ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer); -ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt, +ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); #ifdef CONFIG_IDE_PREINIT diff --git a/include/mmc.h b/include/mmc.h index d652c14..cdb56e7 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -376,7 +376,7 @@ struct mmc { u64 capacity_gp[4]; u64 enh_user_start; u64 enh_user_size; - block_dev_desc_t block_dev; + struct blk_desc block_dev; char op_cond_pending; /* 1 if we are waiting on an op_cond command */ char init_in_progress; /* 1 if we have done mmc_start_init() */ char preinit; /* start init as early as possible */ diff --git a/include/part.h b/include/part.h index dc23949..d1e9d0f 100644 --- a/include/part.h +++ b/include/part.h @@ -10,7 +10,7 @@ #include #include -struct block_dev_desc { +struct blk_desc { int if_type; /* type of the interface */ int dev; /* device number */ unsigned char part_type; /* partition type */ @@ -28,23 +28,23 @@ struct block_dev_desc { char vendor [40+1]; /* IDE model, SCSI Vendor */ char product[20+1]; /* IDE Serial no, SCSI product */ char revision[8+1]; /* firmware revision */ - unsigned long (*block_read)(block_dev_desc_t *block_dev, + unsigned long (*block_read)(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, void *buffer); - unsigned long (*block_write)(block_dev_desc_t *block_dev, + unsigned long (*block_write)(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, const void *buffer); - unsigned long (*block_erase)(block_dev_desc_t *block_dev, + unsigned long (*block_erase)(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); void *priv; /* driver private struct pointer */ }; -#define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz)) -#define PAD_TO_BLOCKSIZE(size, block_dev_desc) \ - (PAD_SIZE(size, block_dev_desc->blksz)) +#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) +#define PAD_TO_BLOCKSIZE(size, blk_desc) \ + (PAD_SIZE(size, blk_desc->blksz)) #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \ ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \ ((x & 0xffff0000) ? 16 : 0)) @@ -101,52 +101,53 @@ typedef struct disk_partition { /* Misc _get_dev functions */ #ifdef CONFIG_PARTITIONS -block_dev_desc_t *get_dev(const char *ifname, int dev); -block_dev_desc_t* ide_get_dev(int dev); -block_dev_desc_t* sata_get_dev(int dev); -block_dev_desc_t* scsi_get_dev(int dev); -block_dev_desc_t* usb_stor_get_dev(int dev); -block_dev_desc_t* mmc_get_dev(int dev); +struct blk_desc *get_dev(const char *ifname, int dev); +struct blk_desc *ide_get_dev(int dev); +struct blk_desc *sata_get_dev(int dev); +struct blk_desc *scsi_get_dev(int dev); +struct blk_desc *usb_stor_get_dev(int dev); +struct blk_desc *mmc_get_dev(int dev); int mmc_select_hwpart(int dev_num, int hwpart); -block_dev_desc_t* systemace_get_dev(int dev); -block_dev_desc_t* mg_disk_get_dev(int dev); -block_dev_desc_t *host_get_dev(int dev); -int host_get_dev_err(int dev, block_dev_desc_t **blk_devp); +struct blk_desc *systemace_get_dev(int dev); +struct blk_desc *mg_disk_get_dev(int dev); +struct blk_desc *host_get_dev(int dev); +int host_get_dev_err(int dev, struct blk_desc **blk_devp); /* disk/part.c */ -int get_partition_info (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); -void print_part (block_dev_desc_t *dev_desc); -void init_part (block_dev_desc_t *dev_desc); -void dev_print(block_dev_desc_t *dev_desc); +int get_partition_info(struct blk_desc *dev_desc, int part, + disk_partition_t *info); +void print_part(struct blk_desc *dev_desc); +void init_part(struct blk_desc *dev_desc); +void dev_print(struct blk_desc *dev_desc); int get_device(const char *ifname, const char *dev_str, - block_dev_desc_t **dev_desc); + struct blk_desc **dev_desc); int get_device_and_partition(const char *ifname, const char *dev_part_str, - block_dev_desc_t **dev_desc, + struct blk_desc **dev_desc, disk_partition_t *info, int allow_whole_dev); #else -static inline block_dev_desc_t *get_dev(const char *ifname, int dev) +static inline struct blk_desc *get_dev(const char *ifname, int dev) { return NULL; } -static inline block_dev_desc_t* ide_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t* sata_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t* scsi_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t* usb_stor_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t* mmc_get_dev(int dev) { return NULL; } +static inline struct blk_desc *ide_get_dev(int dev) { return NULL; } +static inline struct blk_desc *sata_get_dev(int dev) { return NULL; } +static inline struct blk_desc *scsi_get_dev(int dev) { return NULL; } +static inline struct blk_desc *usb_stor_get_dev(int dev) { return NULL; } +static inline struct blk_desc *mmc_get_dev(int dev) { return NULL; } static inline int mmc_select_hwpart(int dev_num, int hwpart) { return -1; } -static inline block_dev_desc_t* systemace_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t* mg_disk_get_dev(int dev) { return NULL; } -static inline block_dev_desc_t *host_get_dev(int dev) { return NULL; } +static inline struct blk_desc *systemace_get_dev(int dev) { return NULL; } +static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; } +static inline struct blk_desc *host_get_dev(int dev) { return NULL; } -static inline int get_partition_info (block_dev_desc_t * dev_desc, int part, - disk_partition_t *info) { return -1; } -static inline void print_part (block_dev_desc_t *dev_desc) {} -static inline void init_part (block_dev_desc_t *dev_desc) {} -static inline void dev_print(block_dev_desc_t *dev_desc) {} +static inline int get_partition_info(struct blk_desc *dev_desc, int part, + disk_partition_t *info) { return -1; } +static inline void print_part(struct blk_desc *dev_desc) {} +static inline void init_part(struct blk_desc *dev_desc) {} +static inline void dev_print(struct blk_desc *dev_desc) {} static inline int get_device(const char *ifname, const char *dev_str, - block_dev_desc_t **dev_desc) + struct blk_desc **dev_desc) { return -1; } static inline int get_device_and_partition(const char *ifname, const char *dev_part_str, - block_dev_desc_t **dev_desc, + struct blk_desc **dev_desc, disk_partition_t *info, int allow_whole_dev) { *dev_desc = NULL; return -1; } @@ -154,36 +155,41 @@ static inline int get_device_and_partition(const char *ifname, #ifdef CONFIG_MAC_PARTITION /* disk/part_mac.c */ -int get_partition_info_mac (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); -void print_part_mac (block_dev_desc_t *dev_desc); -int test_part_mac (block_dev_desc_t *dev_desc); +int get_partition_info_mac(struct blk_desc *dev_desc, int part, + disk_partition_t *info); +void print_part_mac(struct blk_desc *dev_desc); +int test_part_mac(struct blk_desc *dev_desc); #endif #ifdef CONFIG_DOS_PARTITION /* disk/part_dos.c */ -int get_partition_info_dos (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); -void print_part_dos (block_dev_desc_t *dev_desc); -int test_part_dos (block_dev_desc_t *dev_desc); +int get_partition_info_dos(struct blk_desc *dev_desc, int part, + disk_partition_t *info); +void print_part_dos(struct blk_desc *dev_desc); +int test_part_dos(struct blk_desc *dev_desc); #endif #ifdef CONFIG_ISO_PARTITION /* disk/part_iso.c */ -int get_partition_info_iso (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); -void print_part_iso (block_dev_desc_t *dev_desc); -int test_part_iso (block_dev_desc_t *dev_desc); +int get_partition_info_iso(struct blk_desc *dev_desc, int part, + disk_partition_t *info); +void print_part_iso(struct blk_desc *dev_desc); +int test_part_iso(struct blk_desc *dev_desc); #endif #ifdef CONFIG_AMIGA_PARTITION /* disk/part_amiga.c */ -int get_partition_info_amiga (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); -void print_part_amiga (block_dev_desc_t *dev_desc); -int test_part_amiga (block_dev_desc_t *dev_desc); +int get_partition_info_amiga(struct blk_desc *dev_desc, int part, + disk_partition_t *info); +void print_part_amiga(struct blk_desc *dev_desc); +int test_part_amiga(struct blk_desc *dev_desc); #endif #ifdef CONFIG_EFI_PARTITION #include /* disk/part_efi.c */ -int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partition_t *info); +int get_partition_info_efi(struct blk_desc *dev_desc, int part, + disk_partition_t *info); /** * get_partition_info_efi_by_name() - Find the specified GPT partition table entry * @@ -193,10 +199,10 @@ int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partitio * * @return - '0' on match, '-1' on no match, otherwise error */ -int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc, +int get_partition_info_efi_by_name(struct blk_desc *dev_desc, const char *name, disk_partition_t *info); -void print_part_efi (block_dev_desc_t *dev_desc); -int test_part_efi (block_dev_desc_t *dev_desc); +void print_part_efi(struct blk_desc *dev_desc); +int test_part_efi(struct blk_desc *dev_desc); /** * write_gpt_table() - Write the GUID Partition Table to disk @@ -207,7 +213,7 @@ int test_part_efi (block_dev_desc_t *dev_desc); * * @return - zero on success, otherwise error */ -int write_gpt_table(block_dev_desc_t *dev_desc, +int write_gpt_table(struct blk_desc *dev_desc, gpt_header *gpt_h, gpt_entry *gpt_e); /** @@ -233,7 +239,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e, * * @return - error on str_guid conversion error */ -int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h, +int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, char *str_guid, int parts_count); /** @@ -246,7 +252,7 @@ int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h, * * @return zero on success */ -int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid, +int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, disk_partition_t *partitions, const int parts_count); /** @@ -257,7 +263,7 @@ int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid, * * @return - '0' on success, otherwise error */ -int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf); +int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf); /** * write_mbr_and_gpt_partitions() - write MBR, Primary GPT and Backup GPT @@ -267,7 +273,7 @@ int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf); * * @return - '0' on success, otherwise error */ -int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf); +int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf); /** * gpt_verify_headers() - Function to read and CRC32 check of the GPT's header @@ -281,7 +287,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf); * * @return - '0' on success, otherwise error */ -int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head, +int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, gpt_entry **gpt_pte); /** @@ -300,7 +306,7 @@ int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head, * * @return - '0' on success, otherwise error */ -int gpt_verify_partitions(block_dev_desc_t *dev_desc, +int gpt_verify_partitions(struct blk_desc *dev_desc, disk_partition_t *partitions, int parts, gpt_header *gpt_head, gpt_entry **gpt_pte); #endif diff --git a/include/reiserfs.h b/include/reiserfs.h index 2d14d48..ffe4e46 100644 --- a/include/reiserfs.h +++ b/include/reiserfs.h @@ -63,7 +63,7 @@ typedef enum } reiserfs_error_t; -extern void reiserfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); +void reiserfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); extern int reiserfs_ls (char *dirname); extern int reiserfs_open (char *filename); extern int reiserfs_read (char *buf, unsigned len); diff --git a/include/sandboxblockdev.h b/include/sandboxblockdev.h index 627787a..59f9519 100644 --- a/include/sandboxblockdev.h +++ b/include/sandboxblockdev.h @@ -8,7 +8,7 @@ #define __SANDBOX_BLOCK_DEV__ struct host_block_dev { - block_dev_desc_t blk_dev; + struct blk_desc blk_dev; char *filename; int fd; }; diff --git a/include/sandboxfs.h b/include/sandboxfs.h index 4c7745d..6e6e3c6 100644 --- a/include/sandboxfs.h +++ b/include/sandboxfs.h @@ -18,7 +18,7 @@ #ifndef __SANDBOX_FS__ #define __SANDBOX_FS__ -int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); +int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer, loff_t maxsize, loff_t *actread); diff --git a/include/sata.h b/include/sata.h index fa61da8..b35359a 100644 --- a/include/sata.h +++ b/include/sata.h @@ -14,6 +14,6 @@ int sata_stop(void); int __sata_stop(void); int sata_port_status(int dev, int port); -extern block_dev_desc_t sata_dev_desc[]; +extern struct blk_desc sata_dev_desc[]; #endif diff --git a/include/spl.h b/include/spl.h index 92cdc04..c62887a 100644 --- a/include/spl.h +++ b/include/spl.h @@ -72,14 +72,16 @@ int spl_usb_load_image(void); int spl_sata_load_image(void); /* SPL FAT image functions */ -int spl_load_image_fat(block_dev_desc_t *block_dev, int partition, const char *filename); -int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition); +int spl_load_image_fat(struct blk_desc *block_dev, int partition, + const char *filename); +int spl_load_image_fat_os(struct blk_desc *block_dev, int partition); void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image); /* SPL EXT image functions */ -int spl_load_image_ext(block_dev_desc_t *block_dev, int partition, const char *filename); -int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition); +int spl_load_image_ext(struct blk_desc *block_dev, int partition, + const char *filename); +int spl_load_image_ext_os(struct blk_desc *block_dev, int partition); /** * spl_init() - Set up device tree and driver model in SPL if enabled diff --git a/include/systemace.h b/include/systemace.h index 3f342d5..3b6ec7d 100644 --- a/include/systemace.h +++ b/include/systemace.h @@ -11,7 +11,7 @@ # include -block_dev_desc_t * systemace_get_dev(int dev); +struct blk_desc *systemace_get_dev(int dev); #endif /* CONFIG_SYSTEMACE */ #endif /* __SYSTEMACE_H */ diff --git a/include/ubifs_uboot.h b/include/ubifs_uboot.h index dab433a..d86da27 100644 --- a/include/ubifs_uboot.h +++ b/include/ubifs_uboot.h @@ -21,7 +21,7 @@ void uboot_ubifs_umount(void); int ubifs_is_mounted(void); int ubifs_load(char *filename, u32 addr, u32 size); -int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); +int ubifs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); int ubifs_ls(const char *dir_name); int ubifs_exists(const char *filename); int ubifs_size(const char *filename, loff_t *size); diff --git a/include/usb.h b/include/usb.h index 0b410b6..c2fa684 100644 --- a/include/usb.h +++ b/include/usb.h @@ -228,7 +228,7 @@ int board_usb_cleanup(int index, enum usb_init_type init); #ifdef CONFIG_USB_STORAGE #define USB_MAX_STOR_DEV 7 -block_dev_desc_t *usb_stor_get_dev(int index); +struct blk_desc *usb_stor_get_dev(int index); int usb_stor_scan(int mode); int usb_stor_info(void); diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index 5804b70..8229f62 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -23,7 +23,7 @@ struct ums { unsigned int start_sector; unsigned int num_sectors; const char *name; - block_dev_desc_t block_dev; + struct blk_desc block_dev; }; int fsg_init(struct ums *ums_devs, int count); diff --git a/include/zfs_common.h b/include/zfs_common.h index 3bd575e..bca3dff 100644 --- a/include/zfs_common.h +++ b/include/zfs_common.h @@ -63,7 +63,7 @@ enum zfs_errors { struct zfs_filesystem { /* Block Device Descriptor */ - block_dev_desc_t *dev_desc; + struct blk_desc *dev_desc; }; struct device_s { @@ -98,7 +98,7 @@ int zfs_close(zfs_file_t); int zfs_ls(device_t dev, const char *path, int (*hook) (const char *, const struct zfs_dirhook_info *)); int zfs_devread(int sector, int byte_offset, int byte_len, char *buf); -void zfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); +void zfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); void zfs_unmount(struct zfs_data *data); int lzjb_decompress(void *, void *, uint32_t, uint32_t); #endif -- cgit v1.1 From 481922f14a4801bd5abfb90705ebcaf76bd90df8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:38 -0700 Subject: dm: part: Drop the common.h header We should not include in header files. Each C file should include it if needed. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/part.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index d1e9d0f..140c9b6 100644 --- a/include/part.h +++ b/include/part.h @@ -8,7 +8,6 @@ #define _PART_H #include -#include struct blk_desc { int if_type; /* type of the interface */ -- cgit v1.1 From 1a73661bc7a7ad2d741f7d7519872ca18231598c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:39 -0700 Subject: dm: Add a new header for block devices At present block devices are tied up with partitions. But not all block devices have partitions within them. They are in fact separate concepts. Create a separate blk.h header file for block devices. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/blk.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/ide.h | 12 ++-------- include/part.h | 49 +--------------------------------------- 3 files changed, 74 insertions(+), 58 deletions(-) create mode 100644 include/blk.h (limited to 'include') diff --git a/include/blk.h b/include/blk.h new file mode 100644 index 0000000..1e8334c --- /dev/null +++ b/include/blk.h @@ -0,0 +1,71 @@ +/* + * (C) Copyright 2000-2004 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef BLK_H +#define BLK_H + +#ifdef CONFIG_SYS_64BIT_LBA +typedef uint64_t lbaint_t; +#define LBAFlength "ll" +#else +typedef ulong lbaint_t; +#define LBAFlength "l" +#endif +#define LBAF "%" LBAFlength "x" +#define LBAFU "%" LBAFlength "u" + +/* Interface types: */ +#define IF_TYPE_UNKNOWN 0 +#define IF_TYPE_IDE 1 +#define IF_TYPE_SCSI 2 +#define IF_TYPE_ATAPI 3 +#define IF_TYPE_USB 4 +#define IF_TYPE_DOC 5 +#define IF_TYPE_MMC 6 +#define IF_TYPE_SD 7 +#define IF_TYPE_SATA 8 +#define IF_TYPE_HOST 9 +#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */ + +struct blk_desc { + int if_type; /* type of the interface */ + int dev; /* device number */ + unsigned char part_type; /* partition type */ + unsigned char target; /* target SCSI ID */ + unsigned char lun; /* target LUN */ + unsigned char hwpart; /* HW partition, e.g. for eMMC */ + unsigned char type; /* device type */ + unsigned char removable; /* removable device */ +#ifdef CONFIG_LBA48 + /* device can use 48bit addr (ATA/ATAPI v7) */ + unsigned char lba48; +#endif + lbaint_t lba; /* number of blocks */ + unsigned long blksz; /* block size */ + int log2blksz; /* for convenience: log2(blksz) */ + char vendor[40+1]; /* IDE model, SCSI Vendor */ + char product[20+1]; /* IDE Serial no, SCSI product */ + char revision[8+1]; /* firmware revision */ + unsigned long (*block_read)(struct blk_desc *block_dev, + lbaint_t start, + lbaint_t blkcnt, + void *buffer); + unsigned long (*block_write)(struct blk_desc *block_dev, + lbaint_t start, + lbaint_t blkcnt, + const void *buffer); + unsigned long (*block_erase)(struct blk_desc *block_dev, + lbaint_t start, + lbaint_t blkcnt); + void *priv; /* driver private struct pointer */ +}; + +#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) +#define PAD_TO_BLOCKSIZE(size, blk_desc) \ + (PAD_SIZE(size, blk_desc->blksz)) + +#endif diff --git a/include/ide.h b/include/ide.h index 2407393..a4e65cf 100644 --- a/include/ide.h +++ b/include/ide.h @@ -8,6 +8,8 @@ #ifndef _IDE_H #define _IDE_H +#include + #define IDE_BUS(dev) (dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS)) #define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)]) @@ -26,16 +28,6 @@ extern ulong ide_bus_offset[]; void ide_led(uchar led, uchar status); #endif /* CONFIG_IDE_LED */ -#ifdef CONFIG_SYS_64BIT_LBA -typedef uint64_t lbaint_t; -#define LBAFlength "ll" -#else -typedef ulong lbaint_t; -#define LBAFlength "l" -#endif -#define LBAF "%" LBAFlength "x" -#define LBAFU "%" LBAFlength "u" - /* * Function Prototypes */ diff --git a/include/part.h b/include/part.h index 140c9b6..2599998 100644 --- a/include/part.h +++ b/include/part.h @@ -7,61 +7,14 @@ #ifndef _PART_H #define _PART_H +#include #include -struct blk_desc { - int if_type; /* type of the interface */ - int dev; /* device number */ - unsigned char part_type; /* partition type */ - unsigned char target; /* target SCSI ID */ - unsigned char lun; /* target LUN */ - unsigned char hwpart; /* HW partition, e.g. for eMMC */ - unsigned char type; /* device type */ - unsigned char removable; /* removable device */ -#ifdef CONFIG_LBA48 - unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */ -#endif - lbaint_t lba; /* number of blocks */ - unsigned long blksz; /* block size */ - int log2blksz; /* for convenience: log2(blksz) */ - char vendor [40+1]; /* IDE model, SCSI Vendor */ - char product[20+1]; /* IDE Serial no, SCSI product */ - char revision[8+1]; /* firmware revision */ - unsigned long (*block_read)(struct blk_desc *block_dev, - lbaint_t start, - lbaint_t blkcnt, - void *buffer); - unsigned long (*block_write)(struct blk_desc *block_dev, - lbaint_t start, - lbaint_t blkcnt, - const void *buffer); - unsigned long (*block_erase)(struct blk_desc *block_dev, - lbaint_t start, - lbaint_t blkcnt); - void *priv; /* driver private struct pointer */ -}; - -#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) -#define PAD_TO_BLOCKSIZE(size, blk_desc) \ - (PAD_SIZE(size, blk_desc->blksz)) #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \ ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \ ((x & 0xffff0000) ? 16 : 0)) #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1)) -/* Interface types: */ -#define IF_TYPE_UNKNOWN 0 -#define IF_TYPE_IDE 1 -#define IF_TYPE_SCSI 2 -#define IF_TYPE_ATAPI 3 -#define IF_TYPE_USB 4 -#define IF_TYPE_DOC 5 -#define IF_TYPE_MMC 6 -#define IF_TYPE_SD 7 -#define IF_TYPE_SATA 8 -#define IF_TYPE_HOST 9 -#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */ - /* Part types */ #define PART_TYPE_UNKNOWN 0x00 #define PART_TYPE_MAC 0x01 -- cgit v1.1 From 5ec4f1a5f35dc71881f88c84176c568308133640 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:40 -0700 Subject: dm: blk: Convert interface type to an enum Since these are sequentially numbered it makes sense to use an enum. It avoids having to maintain the maximum value, and provides a type we can use if it is useful. In fact the maximum value is not used. Rename it to COUNT, since MAX suggests it is the maximum valid value, but it is not. Signed-off-by: Simon Glass Tested-by: Stephen Warren --- include/blk.h | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/blk.h b/include/blk.h index 1e8334c..fd54520 100644 --- a/include/blk.h +++ b/include/blk.h @@ -19,20 +19,23 @@ typedef ulong lbaint_t; #define LBAFU "%" LBAFlength "u" /* Interface types: */ -#define IF_TYPE_UNKNOWN 0 -#define IF_TYPE_IDE 1 -#define IF_TYPE_SCSI 2 -#define IF_TYPE_ATAPI 3 -#define IF_TYPE_USB 4 -#define IF_TYPE_DOC 5 -#define IF_TYPE_MMC 6 -#define IF_TYPE_SD 7 -#define IF_TYPE_SATA 8 -#define IF_TYPE_HOST 9 -#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */ +enum if_type { + IF_TYPE_UNKNOWN = 0, + IF_TYPE_IDE, + IF_TYPE_SCSI, + IF_TYPE_ATAPI, + IF_TYPE_USB, + IF_TYPE_DOC, + IF_TYPE_MMC, + IF_TYPE_SD, + IF_TYPE_SATA, + IF_TYPE_HOST, + + IF_TYPE_COUNT, /* Number of interface types */ +}; struct blk_desc { - int if_type; /* type of the interface */ + enum if_type if_type; /* type of the interface */ int dev; /* device number */ unsigned char part_type; /* partition type */ unsigned char target; /* target SCSI ID */ -- cgit v1.1 From fb1b7be9538dab7ce69208045cc3b80c6eb57f3b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:41 -0700 Subject: dm: blk: Add comments to a few functions The block interface is not well documented in the code. Pick two important functions and add comments. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/part.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/part.h b/include/part.h index 2599998..4e70d8d 100644 --- a/include/part.h +++ b/include/part.h @@ -53,12 +53,42 @@ typedef struct disk_partition { /* Misc _get_dev functions */ #ifdef CONFIG_PARTITIONS +/** + * get_dev() - get a pointer to a block device given its type and number + * + * Each interface allocates its own devices and typically struct blk_desc is + * contained with the interface's data structure. There is no global + * numbering for block devices, so the interface name must be provided. + * + * @ifname: Interface name (e.g. "ide", "scsi") + * @dev: Device number (0 for first device on that interface, 1 for + * second, etc. + * @return pointer to the block device, or NULL if not available, or an + * error occurred. + */ struct blk_desc *get_dev(const char *ifname, int dev); struct blk_desc *ide_get_dev(int dev); struct blk_desc *sata_get_dev(int dev); struct blk_desc *scsi_get_dev(int dev); struct blk_desc *usb_stor_get_dev(int dev); struct blk_desc *mmc_get_dev(int dev); + +/** + * mmc_select_hwpart() - Select the MMC hardware partiion on an MMC device + * + * MMC devices can support partitioning at the hardware level. This is quite + * separate from the normal idea of software-based partitions. MMC hardware + * partitions must be explicitly selected. Once selected only the region of + * the device covered by that partition is accessible. + * + * The MMC standard provides for two boot partitions (numbered 1 and 2), + * rpmb (3), and up to 4 addition general-purpose partitions (4-7). + * + * @dev_num: Block device number (struct blk_desc->dev value) + * @hwpart: Hardware partition number to select. 0 means the raw device, + * 1 is the first partition, 2 is the second, etc. + * @return 0 if OK, other value for an error + */ int mmc_select_hwpart(int dev_num, int hwpart); struct blk_desc *systemace_get_dev(int dev); struct blk_desc *mg_disk_get_dev(int dev); -- cgit v1.1 From db1d9e78e6f0ea51a698f18abe4cebc5ff39b691 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:42 -0700 Subject: dm: blk: Rename get_dev() to blk_get_dev() The current name is too generic. Add a 'blk_' prefix to aid searching and make its purpose clearer. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/part.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index 4e70d8d..ddc4422 100644 --- a/include/part.h +++ b/include/part.h @@ -54,7 +54,7 @@ typedef struct disk_partition { /* Misc _get_dev functions */ #ifdef CONFIG_PARTITIONS /** - * get_dev() - get a pointer to a block device given its type and number + * blk_get_dev() - get a pointer to a block device given its type and number * * Each interface allocates its own devices and typically struct blk_desc is * contained with the interface's data structure. There is no global @@ -66,7 +66,7 @@ typedef struct disk_partition { * @return pointer to the block device, or NULL if not available, or an * error occurred. */ -struct blk_desc *get_dev(const char *ifname, int dev); +struct blk_desc *blk_get_dev(const char *ifname, int dev); struct blk_desc *ide_get_dev(int dev); struct blk_desc *sata_get_dev(int dev); struct blk_desc *scsi_get_dev(int dev); @@ -107,7 +107,7 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str, struct blk_desc **dev_desc, disk_partition_t *info, int allow_whole_dev); #else -static inline struct blk_desc *get_dev(const char *ifname, int dev) +static inline struct blk_desc *blk_get_dev(const char *ifname, int dev) { return NULL; } static inline struct blk_desc *ide_get_dev(int dev) { return NULL; } static inline struct blk_desc *sata_get_dev(int dev) { return NULL; } -- cgit v1.1 From ebac37cfbfb32ea44704fe032fadd5cf334824b7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:43 -0700 Subject: dm: blk: Rename get_device() to blk_get_device_by_str() The current name is too generic. The function returns a block device based on a provided string. Rename it to aid searching and make its purpose clearer. Also add a few comments. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/part.h | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index ddc4422..6ca87d0 100644 --- a/include/part.h +++ b/include/part.h @@ -101,8 +101,34 @@ int get_partition_info(struct blk_desc *dev_desc, int part, void print_part(struct blk_desc *dev_desc); void init_part(struct blk_desc *dev_desc); void dev_print(struct blk_desc *dev_desc); -int get_device(const char *ifname, const char *dev_str, - struct blk_desc **dev_desc); + +/** + * blk_get_device_by_str() - Get a block device given its interface/hw partition + * + * Each interface allocates its own devices and typically struct blk_desc is + * contained with the interface's data structure. There is no global + * numbering for block devices, so the interface name must be provided. + * + * The hardware parition is not related to the normal software partitioning + * of a device - each hardware partition is effectively a separately + * accessible block device. When a hardware parition is selected on MMC the + * other hardware partitions become inaccessible. The same block device is + * used to access all hardware partitions, but its capacity may change when a + * different hardware partition is selected. + * + * When a hardware partition number is given, the block device switches to + * that hardware partition. + * + * @ifname: Interface name (e.g. "ide", "scsi") + * @dev_str: Device and optional hw partition. This can either be a string + * containing the device number (e.g. "2") or the device number + * and hardware partition number (e.g. "2.4") for devices that + * support it (currently only MMC). + * @dev_desc: Returns a pointer to the block device on success + * @return block device number (local to the interface), or -1 on error + */ +int blk_get_device_by_str(const char *ifname, const char *dev_str, + struct blk_desc **dev_desc); int get_device_and_partition(const char *ifname, const char *dev_part_str, struct blk_desc **dev_desc, disk_partition_t *info, int allow_whole_dev); @@ -124,8 +150,8 @@ static inline int get_partition_info(struct blk_desc *dev_desc, int part, static inline void print_part(struct blk_desc *dev_desc) {} static inline void init_part(struct blk_desc *dev_desc) {} static inline void dev_print(struct blk_desc *dev_desc) {} -static inline int get_device(const char *ifname, const char *dev_str, - struct blk_desc **dev_desc) +static inline int blk_get_device_by_str(const char *ifname, const char *dev_str, + struct blk_desc **dev_desc) { return -1; } static inline int get_device_and_partition(const char *ifname, const char *dev_part_str, -- cgit v1.1 From e35929e4a1ffe861f2f45e107986568c56c4f077 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:44 -0700 Subject: dm: blk: Rename get_device_and_partition() Rename this function to blk_get_device_part_str(). This is a better name because it makes it clear that the function returns a block device and parses a string. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/part.h | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index 6ca87d0..6197101 100644 --- a/include/part.h +++ b/include/part.h @@ -129,9 +129,43 @@ void dev_print(struct blk_desc *dev_desc); */ int blk_get_device_by_str(const char *ifname, const char *dev_str, struct blk_desc **dev_desc); -int get_device_and_partition(const char *ifname, const char *dev_part_str, - struct blk_desc **dev_desc, - disk_partition_t *info, int allow_whole_dev); + +/** + * blk_get_device_part_str() - Get a block device and partition + * + * This calls blk_get_device_by_str() to look up a device. It also looks up + * a partition and returns information about it. + * + * @dev_part_str is in the format: + * .: where is the device number, + * is the optional hardware partition number and + * is the partition number + * + * If ifname is "hostfs" then this function returns the sandbox host block + * device. + * + * If ifname is ubi, then this function returns 0, with @info set to a + * special UBI device. + * + * If @dev_part_str is NULL or empty or "-", then this function looks up + * the "bootdevice" environment variable and uses that string instead. + * + * If the partition string is empty then the first partition is used. If the + * partition string is "auto" then the first bootable partition is used. + * + * @ifname: Interface name (e.g. "ide", "scsi") + * @dev_part_str: Device and partition string + * @dev_desc: Returns a pointer to the block device on success + * @info: Returns partition information + * @allow_whole_dev: true to allow the user to select partition 0 + * (which means the whole device), false to require a valid + * partition number >= 1 + * @return partition number, or -1 on error + * + */ +int blk_get_device_part_str(const char *ifname, const char *dev_part_str, + struct blk_desc **dev_desc, + disk_partition_t *info, int allow_whole_dev); #else static inline struct blk_desc *blk_get_dev(const char *ifname, int dev) { return NULL; } @@ -153,7 +187,7 @@ static inline void dev_print(struct blk_desc *dev_desc) {} static inline int blk_get_device_by_str(const char *ifname, const char *dev_str, struct blk_desc **dev_desc) { return -1; } -static inline int get_device_and_partition(const char *ifname, +static inline int blk_get_device_part_str(const char *ifname, const char *dev_part_str, struct blk_desc **dev_desc, disk_partition_t *info, -- cgit v1.1 From 14142811f4c2d4da28e86ccb2375487f8dff02cb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:46 -0700 Subject: dm: sandbox: Enable all partition types It is useful to have sandbox build as much code as possible to avoid having to build every board to detect build errors. Also we may add tests for some more partition types at some point. Enable all partition types in sandbox. Signed-off-by: Simon Glass Reviewed-by: Tom Rini Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/configs/sandbox.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 4bffd8d..786bb11 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -53,8 +53,11 @@ #define CONFIG_CMD_GPT #define CONFIG_PARTITION_UUIDS -#define CONFIG_EFI_PARTITION +#define CONFIG_AMIGA_PARTITION #define CONFIG_DOS_PARTITION +#define CONFIG_EFI_PARTITION +#define CONFIG_ISO_PARTITION +#define CONFIG_MAC_PARTITION /* * Size of malloc() pool, before and after relocation -- cgit v1.1 From 96e5b03c8ab749b6547f6a3ceb4d4b9f274211aa Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:47 -0700 Subject: dm: part: Convert partition API use to linker lists We can use linker lists instead of explicitly declaring each function. This makes the code shorter by avoiding switch() statements and lots of header file declarations. While this does clean up the code it introduces a few code issues with SPL. SPL never needs to print partition information since this all happens from commands. SPL mostly doesn't need to obtain information about a partition either, except in a few cases. Add these cases so that the code will be dropped from each partition driver when not needed. This avoids code bloat. I think this is still a win, since it is not a bad thing to be explicit about which features are used in SPL. But others may like to weigh in. Signed-off-by: Simon Glass Reviewed-by: Tom Rini Tested-by: Stephen Warren --- include/part.h | 79 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index 6197101..544b056 100644 --- a/include/part.h +++ b/include/part.h @@ -195,43 +195,62 @@ static inline int blk_get_device_part_str(const char *ifname, { *dev_desc = NULL; return -1; } #endif -#ifdef CONFIG_MAC_PARTITION -/* disk/part_mac.c */ -int get_partition_info_mac(struct blk_desc *dev_desc, int part, - disk_partition_t *info); -void print_part_mac(struct blk_desc *dev_desc); -int test_part_mac(struct blk_desc *dev_desc); +/* + * We don't support printing partition information in SPL and only support + * getting partition information in a few cases. + */ +#ifdef CONFIG_SPL_BUILD +# define part_print_ptr(x) NULL +# if defined(CONFIG_SPL_EXT_SUPPORT) || \ + defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION) +# define part_get_info_ptr(x) x +# else +# define part_get_info_ptr(x) NULL +# endif +#else +#define part_print_ptr(x) x +#define part_get_info_ptr(x) x #endif -#ifdef CONFIG_DOS_PARTITION -/* disk/part_dos.c */ -int get_partition_info_dos(struct blk_desc *dev_desc, int part, - disk_partition_t *info); -void print_part_dos(struct blk_desc *dev_desc); -int test_part_dos(struct blk_desc *dev_desc); -#endif -#ifdef CONFIG_ISO_PARTITION -/* disk/part_iso.c */ -int get_partition_info_iso(struct blk_desc *dev_desc, int part, - disk_partition_t *info); -void print_part_iso(struct blk_desc *dev_desc); -int test_part_iso(struct blk_desc *dev_desc); -#endif +struct part_driver { + const char *name; + int part_type; -#ifdef CONFIG_AMIGA_PARTITION -/* disk/part_amiga.c */ -int get_partition_info_amiga(struct blk_desc *dev_desc, int part, - disk_partition_t *info); -void print_part_amiga(struct blk_desc *dev_desc); -int test_part_amiga(struct blk_desc *dev_desc); -#endif + /** + * get_info() - Get information about a partition + * + * @dev_desc: Block device descriptor + * @part: Partition number (1 = first) + * @info: Returns partition information + */ + int (*get_info)(struct blk_desc *dev_desc, int part, + disk_partition_t *info); + + /** + * print() - Print partition information + * + * @dev_desc: Block device descriptor + */ + void (*print)(struct blk_desc *dev_desc); + + /** + * test() - Test if a device contains this partition type + * + * @dev_desc: Block device descriptor + * @return 0 if the block device appears to contain this partition + * type, -ve if not + */ + int (*test)(struct blk_desc *dev_desc); +}; + +/* Declare a new U-Boot partition 'driver' */ +#define U_BOOT_PART_TYPE(__name) \ + ll_entry_declare(struct part_driver, __name, part_driver) #ifdef CONFIG_EFI_PARTITION #include /* disk/part_efi.c */ -int get_partition_info_efi(struct blk_desc *dev_desc, int part, - disk_partition_t *info); /** * get_partition_info_efi_by_name() - Find the specified GPT partition table entry * @@ -243,8 +262,6 @@ int get_partition_info_efi(struct blk_desc *dev_desc, int part, */ int get_partition_info_efi_by_name(struct blk_desc *dev_desc, const char *name, disk_partition_t *info); -void print_part_efi(struct blk_desc *dev_desc); -int test_part_efi(struct blk_desc *dev_desc); /** * write_gpt_table() - Write the GUID Partition Table to disk -- cgit v1.1 From 3e8bd469504f5d5a8800a2ea46d664dde701105b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:48 -0700 Subject: dm: part: Rename some partition functions Rename three partition functions so that they start with part_. This makes it clear what they relate to. Signed-off-by: Simon Glass Tested-by: Stephen Warren --- include/part.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/part.h b/include/part.h index 544b056..6d8f520 100644 --- a/include/part.h +++ b/include/part.h @@ -96,10 +96,9 @@ struct blk_desc *host_get_dev(int dev); int host_get_dev_err(int dev, struct blk_desc **blk_devp); /* disk/part.c */ -int get_partition_info(struct blk_desc *dev_desc, int part, - disk_partition_t *info); -void print_part(struct blk_desc *dev_desc); -void init_part(struct blk_desc *dev_desc); +int part_get_info(struct blk_desc *dev_desc, int part, disk_partition_t *info); +void part_print(struct blk_desc *dev_desc); +void part_init(struct blk_desc *dev_desc); void dev_print(struct blk_desc *dev_desc); /** @@ -179,10 +178,10 @@ static inline struct blk_desc *systemace_get_dev(int dev) { return NULL; } static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; } static inline struct blk_desc *host_get_dev(int dev) { return NULL; } -static inline int get_partition_info(struct blk_desc *dev_desc, int part, - disk_partition_t *info) { return -1; } -static inline void print_part(struct blk_desc *dev_desc) {} -static inline void init_part(struct blk_desc *dev_desc) {} +static inline int part_get_info(struct blk_desc *dev_desc, int part, + disk_partition_t *info) { return -1; } +static inline void part_print(struct blk_desc *dev_desc) {} +static inline void part_init(struct blk_desc *dev_desc) {} static inline void dev_print(struct blk_desc *dev_desc) {} static inline int blk_get_device_by_str(const char *ifname, const char *dev_str, struct blk_desc **dev_desc) @@ -252,7 +251,7 @@ struct part_driver { #include /* disk/part_efi.c */ /** - * get_partition_info_efi_by_name() - Find the specified GPT partition table entry + * part_get_info_efi_by_name() - Find the specified GPT partition table entry * * @param dev_desc - block device descriptor * @param gpt_name - the specified table entry name @@ -260,8 +259,8 @@ struct part_driver { * * @return - '0' on match, '-1' on no match, otherwise error */ -int get_partition_info_efi_by_name(struct blk_desc *dev_desc, - const char *name, disk_partition_t *info); +int part_get_info_efi_by_name(struct blk_desc *dev_desc, + const char *name, disk_partition_t *info); /** * write_gpt_table() - Write the GUID Partition Table to disk -- cgit v1.1 From 782b97805e9f59cc2b4d3aa67a8a03248e8cd722 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:50 -0700 Subject: dm: sandbox: Enable cbfs and cramfs Enable these two filesystems to provide better build coverage in sandbox. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/configs/sandbox.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 786bb11..f73d040 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -44,6 +44,9 @@ #define CONFIG_CMD_FAT #define CONFIG_CMD_EXT4 #define CONFIG_CMD_EXT4_WRITE +#define CONFIG_CMD_CBFS +#define CONFIG_CMD_CRAMFS +#define CONFIG_CRAMFS_CMDLINE #define CONFIG_CMD_PART #define CONFIG_DOS_PARTITION #define CONFIG_HOST_MAX_DEVICES 4 -- cgit v1.1 From bcce53d048de7f41078d25e39aa2f26d752d3658 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:51 -0700 Subject: dm: block: Rename device number member dev to devnum This is a device number, and we want to use 'dev' to mean a driver model device. Rename the member. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/blk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/blk.h b/include/blk.h index fd54520..9c54842 100644 --- a/include/blk.h +++ b/include/blk.h @@ -36,7 +36,7 @@ enum if_type { struct blk_desc { enum if_type if_type; /* type of the interface */ - int dev; /* device number */ + int devnum; /* device number */ unsigned char part_type; /* partition type */ unsigned char target; /* target SCSI ID */ unsigned char lun; /* target LUN */ -- cgit v1.1 From 2a981dc2c62c500110aad297fa70503aec36e689 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:52 -0700 Subject: dm: block: Adjust device calls to go through helpers function To ease conversion to driver model, add helper functions which deal with calling each block device method. With driver model we can reimplement these functions with the same arguments. Use inline functions to avoid increasing code size on some boards. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/blk.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include') diff --git a/include/blk.h b/include/blk.h index 9c54842..7b2e5e2 100644 --- a/include/blk.h +++ b/include/blk.h @@ -71,4 +71,33 @@ struct blk_desc { #define PAD_TO_BLOCKSIZE(size, blk_desc) \ (PAD_SIZE(size, blk_desc->blksz)) +/* + * These functions should take struct udevice instead of struct blk_desc, + * but this is convenient for migration to driver model. Add a 'd' prefix + * to the function operations, so that blk_read(), etc. can be reserved for + * functions with the correct arguments. + */ +static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt, void *buffer) +{ + /* + * We could check if block_read is NULL and return -ENOSYS. But this + * bloats the code slightly (cause some board to fail to build), and + * it would be an error to try an operation that does not exist. + */ + return block_dev->block_read(block_dev, start, blkcnt, buffer); +} + +static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer) +{ + return block_dev->block_write(block_dev, start, blkcnt, buffer); +} + +static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt) +{ + return block_dev->block_erase(block_dev, start, blkcnt); +} + #endif -- cgit v1.1 From 09d71aac7b530f03ec29cc9d5787047460a629ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:55 -0700 Subject: dm: blk: Add a block-device uclass Add a uclass for block devices. These provide block-oriented data access, supporting reading, writing and erasing of whole blocks. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Stephen Warren --- include/blk.h | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + 2 files changed, 146 insertions(+) (limited to 'include') diff --git a/include/blk.h b/include/blk.h index 7b2e5e2..e83c144 100644 --- a/include/blk.h +++ b/include/blk.h @@ -34,7 +34,15 @@ enum if_type { IF_TYPE_COUNT, /* Number of interface types */ }; +/* + * With driver model (CONFIG_BLK) this is uclass platform data, accessible + * with dev_get_uclass_platdata(dev) + */ struct blk_desc { + /* + * TODO: With driver model we should be able to use the parent + * device's uclass instead. + */ enum if_type if_type; /* type of the interface */ int devnum; /* device number */ unsigned char part_type; /* partition type */ @@ -53,6 +61,9 @@ struct blk_desc { char vendor[40+1]; /* IDE model, SCSI Vendor */ char product[20+1]; /* IDE Serial no, SCSI product */ char revision[8+1]; /* firmware revision */ +#ifdef CONFIG_BLK + struct udevice *bdev; +#else unsigned long (*block_read)(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, @@ -65,12 +76,145 @@ struct blk_desc { lbaint_t start, lbaint_t blkcnt); void *priv; /* driver private struct pointer */ +#endif }; #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) #define PAD_TO_BLOCKSIZE(size, blk_desc) \ (PAD_SIZE(size, blk_desc->blksz)) +#ifdef CONFIG_BLK +struct udevice; + +/* Operations on block devices */ +struct blk_ops { + /** + * read() - read from a block device + * + * @dev: Device to read from + * @start: Start block number to read (0=first) + * @blkcnt: Number of blocks to read + * @buffer: Destination buffer for data read + * @return number of blocks read, or -ve error number (see the + * IS_ERR_VALUE() macro + */ + unsigned long (*read)(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer); + + /** + * write() - write to a block device + * + * @dev: Device to write to + * @start: Start block number to write (0=first) + * @blkcnt: Number of blocks to write + * @buffer: Source buffer for data to write + * @return number of blocks written, or -ve error number (see the + * IS_ERR_VALUE() macro + */ + unsigned long (*write)(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer); + + /** + * erase() - erase a section of a block device + * + * @dev: Device to (partially) erase + * @start: Start block number to erase (0=first) + * @blkcnt: Number of blocks to erase + * @return number of blocks erased, or -ve error number (see the + * IS_ERR_VALUE() macro + */ + unsigned long (*erase)(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt); +}; + +#define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops) + +/* + * These functions should take struct udevice instead of struct blk_desc, + * but this is convenient for migration to driver model. Add a 'd' prefix + * to the function operations, so that blk_read(), etc. can be reserved for + * functions with the correct arguments. + */ +unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt, void *buffer); +unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer); +unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, + lbaint_t blkcnt); + +/** + * blk_get_device() - Find and probe a block device ready for use + * + * @if_type: Interface type (enum if_type_t) + * @devnum: Device number (specific to each interface type) + * @devp: the device, if found + * @return - if found, -ENODEV if no device found, or other -ve error value + */ +int blk_get_device(int if_type, int devnum, struct udevice **devp); + +/** + * blk_first_device() - Find the first device for a given interface + * + * The device is probed ready for use + * + * @devnum: Device number (specific to each interface type) + * @devp: the device, if found + * @return 0 if found, -ENODEV if no device, or other -ve error value + */ +int blk_first_device(int if_type, struct udevice **devp); + +/** + * blk_next_device() - Find the next device for a given interface + * + * This can be called repeatedly after blk_first_device() to iterate through + * all devices of the given interface type. + * + * The device is probed ready for use + * + * @devp: On entry, the previous device returned. On exit, the next + * device, if found + * @return 0 if found, -ENODEV if no device, or other -ve error value + */ +int blk_next_device(struct udevice **devp); + +/** + * blk_create_device() - Create a new block device + * + * @parent: Parent of the new device + * @drv_name: Driver name to use for the block device + * @name: Name for the device + * @if_type: Interface type (enum if_type_t) + * @devnum: Device number, specific to the interface type + * @blksz: Block size of the device in bytes (typically 512) + * @size: Total size of the device in bytes + * @devp: the new device (which has not been probed) + */ +int blk_create_device(struct udevice *parent, const char *drv_name, + const char *name, int if_type, int devnum, int blksz, + lbaint_t size, struct udevice **devp); + +/** + * blk_prepare_device() - Prepare a block device for use + * + * This reads partition information from the device if supported. + * + * @dev: Device to prepare + * @return 0 if ok, -ve on error + */ +int blk_prepare_device(struct udevice *dev); + +/** + * blk_unbind_all() - Unbind all device of the given interface type + * + * The devices are removed and then unbound. + * + * @if_type: Interface type to unbind + * @return 0 if OK, -ve on error + */ +int blk_unbind_all(int if_type); + +#else +#include /* * These functions should take struct udevice instead of struct blk_desc, * but this is convenient for migration to driver model. Add a 'd' prefix @@ -99,5 +243,6 @@ static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start, { return block_dev->block_erase(block_dev, start, blkcnt); } +#endif /* !CONFIG_BLK */ #endif diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 3bea308..37c4176 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -26,6 +26,7 @@ enum uclass_id { /* U-Boot uclasses start here - in alphabetical order */ UCLASS_ADC, /* Analog-to-digital converter */ + UCLASS_BLK, /* Block device */ UCLASS_CLK, /* Clock source, e.g. used by peripherals */ UCLASS_CPU, /* CPU, typically part of an SoC */ UCLASS_CROS_EC, /* Chrome OS EC */ -- cgit v1.1 From 40fd050890e08eb6d064aaf074cf3a8b75d1251e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:25:57 -0700 Subject: dm: sandbox: Add driver-model block-device support for sandbox Update the host driver to support driver model for block devices. A future commit will remove the old code, but for now it is useful to be able to use it both with and without CONFIG_BLK. Signed-off-by: Simon Glass Tested-by: Stephen Warren --- include/sandboxblockdev.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/sandboxblockdev.h b/include/sandboxblockdev.h index 59f9519..5174f45 100644 --- a/include/sandboxblockdev.h +++ b/include/sandboxblockdev.h @@ -8,7 +8,9 @@ #define __SANDBOX_BLOCK_DEV__ struct host_block_dev { +#ifndef CONFIG_BLK struct blk_desc blk_dev; +#endif char *filename; int fd; }; -- cgit v1.1 From eea1d148f3c653b23e96a2f842c3760b4cbbaa51 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 29 Feb 2016 15:26:05 -0700 Subject: Drop CONFIG_CRAMFS_CMDLINE This option doesn't do anything. Drop it. Signed-off-by: Simon Glass Suggested-by: Bin Meng --- include/configs/UCP1020.h | 1 - include/configs/km/keymile-common.h | 1 - include/configs/sandbox.h | 1 - 3 files changed, 3 deletions(-) (limited to 'include') diff --git a/include/configs/UCP1020.h b/include/configs/UCP1020.h index 2354009..c21af1c 100644 --- a/include/configs/UCP1020.h +++ b/include/configs/UCP1020.h @@ -495,7 +495,6 @@ #define CONFIG_CMD_REGINFO #define CONFIG_CMD_ERRATA #define CONFIG_CMD_CRAMFS -#define CONFIG_CRAMFS_CMDLINE /* * USB diff --git a/include/configs/km/keymile-common.h b/include/configs/km/keymile-common.h index 91b29b3..5edc8f6 100644 --- a/include/configs/km/keymile-common.h +++ b/include/configs/km/keymile-common.h @@ -83,7 +83,6 @@ #define CONFIG_MTD_CONCAT #define CONFIG_CMD_CRAMFS -#define CONFIG_CRAMFS_CMDLINE #ifndef CONFIG_KM_DEF_ENV_BOOTPARAMS #define CONFIG_KM_DEF_ENV_BOOTPARAMS \ diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index f73d040..b7090c8 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -46,7 +46,6 @@ #define CONFIG_CMD_EXT4_WRITE #define CONFIG_CMD_CBFS #define CONFIG_CMD_CRAMFS -#define CONFIG_CRAMFS_CMDLINE #define CONFIG_CMD_PART #define CONFIG_DOS_PARTITION #define CONFIG_HOST_MAX_DEVICES 4 -- cgit v1.1