diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 2 | ||||
-rw-r--r-- | common/bbu.c | 37 | ||||
-rw-r--r-- | common/block.c | 4 | ||||
-rw-r--r-- | common/blspec.c | 4 | ||||
-rw-r--r-- | common/bootm.c | 150 | ||||
-rw-r--r-- | common/console_common.c | 10 | ||||
-rw-r--r-- | common/efi/guid.c | 2 | ||||
-rw-r--r-- | common/efi/payload/Makefile | 1 | ||||
-rw-r--r-- | common/efi/payload/fdt.c | 43 | ||||
-rw-r--r-- | common/efi/payload/image.c | 14 | ||||
-rw-r--r-- | common/elf.c | 13 | ||||
-rw-r--r-- | common/envfs-core.c | 3 | ||||
-rw-r--r-- | common/environment.c | 11 | ||||
-rw-r--r-- | common/fastboot.c | 8 | ||||
-rw-r--r-- | common/file-list.c | 7 | ||||
-rw-r--r-- | common/firmware.c | 5 | ||||
-rw-r--r-- | common/imx-bbu-nand-fcb.c | 267 | ||||
-rw-r--r-- | common/misc.c | 8 | ||||
-rw-r--r-- | common/module.lds.S | 2 | ||||
-rw-r--r-- | common/ubiformat.c | 2 | ||||
-rw-r--r-- | common/uimage.c | 4 |
21 files changed, 406 insertions, 191 deletions
diff --git a/common/Kconfig b/common/Kconfig index 43dd92b08a..350e6aeea7 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -78,7 +78,7 @@ config ARCH_DMA_ADDR_T_64BIT config BAREBOX_UPDATE_IMX_NAND_FCB bool - depends on ARCH_IMX6 || ARCH_IMX28 + depends on ARCH_IMX7 || ARCH_IMX6 || ARCH_IMX28 depends on BAREBOX_UPDATE depends on MTD_WRITE depends on NAND_MXS diff --git a/common/bbu.c b/common/bbu.c index d243ac89dd..3ec17216cb 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -24,43 +24,42 @@ static LIST_HEAD(bbu_image_handlers); -static void append_bbu_entry(struct bbu_handler *handler, struct file_list *files) +static void append_bbu_entry(const char *_name, + const char *devicefile, + struct file_list *files) { char *name; - name = basprintf("bbu-%s", handler->name); + name = basprintf("bbu-%s", _name); - if (file_list_add_entry(files, name, handler->devicefile, 0)) + if (file_list_add_entry(files, name, devicefile, 0)) pr_warn("duplicate partition name %s\n", name); free(name); } -static bool bbu_handler_is_available(struct bbu_handler *handler) -{ - struct stat s; - int ret; - - device_detect_by_name(devpath_to_name(handler->devicefile)); - - ret = stat(handler->devicefile, &s); - if (ret) - return false; - - return true; -} - void bbu_append_handlers_to_file_list(struct file_list *files) { struct bbu_handler *handler; list_for_each_entry(handler, &bbu_image_handlers, list) { - if (bbu_handler_is_available(handler)) { - append_bbu_entry(handler, files); + const char *cdevname; + struct stat s; + char *devpath; + + cdevname = devpath_to_name(handler->devicefile); + device_detect_by_name(cdevname); + + devpath = basprintf("/dev/%s", cdevname); + + if (stat(devpath, &s) == 0) { + append_bbu_entry(handler->name, devpath, files); } else { pr_info("Skipping unavailable handler bbu-%s\n", handler->name); } + + free(devpath); } } diff --git a/common/block.c b/common/block.c index 19bb81df2c..7f28b56419 100644 --- a/common/block.c +++ b/common/block.c @@ -361,12 +361,12 @@ static struct cdev_operations block_ops = { .discard_range = block_op_discard_range, }; -struct block_device *cdev_get_block_device(struct cdev *cdev) +struct block_device *cdev_get_block_device(const struct cdev *cdev) { if (!cdev || cdev->ops != &block_ops) return NULL; - return container_of(cdev, struct block_device, cdev); + return cdev->priv; } int blockdevice_register(struct block_device *blk) diff --git a/common/blspec.c b/common/blspec.c index d391f690ad..9ae7b49a77 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -677,9 +677,7 @@ static int blspec_scan_cdev(struct bootentries *bootentries, struct cdev *cdev) found += ret; } - rootpath = cdev_get_mount_path(cdev); - if (!rootpath) - rootpath = cdev_mount_default(cdev, NULL); + rootpath = cdev_mount(cdev); if (!IS_ERR(rootpath)) { ret = blspec_scan_directory(bootentries, rootpath); if (ret > 0) diff --git a/common/bootm.c b/common/bootm.c index 2f02c156e5..fb1ed36a26 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -519,18 +519,77 @@ static int bootm_open_os_uimage(struct image_data *data) return 0; } +static int bootm_open_fit(struct image_data *data) +{ + struct fit_handle *fit; + static const char *kernel_img = "kernel"; + int ret; + + if (!IS_ENABLED(CONFIG_FITIMAGE)) + return 0; + + fit = fit_open(data->os_file, data->verbose, data->verify); + if (IS_ERR(fit)) { + pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit); + return PTR_ERR(fit); + } + + data->os_fit = fit; + + data->fit_config = fit_open_configuration(data->os_fit, + data->os_part); + if (IS_ERR(data->fit_config)) { + pr_err("Cannot open FIT image configuration '%s'\n", + data->os_part ? data->os_part : "default"); + return PTR_ERR(data->fit_config); + } + + ret = fit_open_image(data->os_fit, data->fit_config, kernel_img, + &data->fit_kernel, &data->fit_kernel_size); + if (ret) + return ret; + if (data->os_address == UIMAGE_SOME_ADDRESS) { + ret = fit_get_image_address(data->os_fit, + data->fit_config, + kernel_img, + "load", &data->os_address); + if (!ret) + pr_info("Load address from FIT '%s': 0x%lx\n", + kernel_img, data->os_address); + /* Note: Error case uses default value. */ + } + if (data->os_entry == UIMAGE_SOME_ADDRESS) { + unsigned long entry; + ret = fit_get_image_address(data->os_fit, + data->fit_config, + kernel_img, + "entry", &entry); + if (!ret) { + data->os_entry = entry - data->os_address; + pr_info("Entry address from FIT '%s': 0x%lx\n", + kernel_img, entry); + } + /* Note: Error case uses default value. */ + } + + return 0; +} + static int bootm_open_elf(struct image_data *data) { + struct elf_image *elf; + if (!IS_ENABLED(CONFIG_ELF)) return -ENOSYS; - data->elf = elf_open(data->os_file); - if (IS_ERR(data->elf)) - return PTR_ERR(data->elf); + elf = elf_open(data->os_file); + if (IS_ERR(elf)) + return PTR_ERR(elf); - pr_info("Entry Point: %08llx\n", data->elf->entry); + pr_info("Entry Point: %08llx\n", elf->entry); - data->os_address = data->elf->entry; + data->os_address = elf->entry; + data->elf = elf; return 0; } @@ -633,74 +692,25 @@ int bootm_boot(struct bootm_data *bootm_data) } } - if (IS_ENABLED(CONFIG_FITIMAGE) && os_type == filetype_oftree) { - struct fit_handle *fit; - static const char *kernel_img = "kernel"; - - fit = fit_open(data->os_file, data->verbose, data->verify); - if (IS_ERR(fit)) { - pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit); - ret = PTR_ERR(fit); - goto err_out; - } - - data->os_fit = fit; - - data->fit_config = fit_open_configuration(data->os_fit, - data->os_part); - if (IS_ERR(data->fit_config)) { - pr_err("Cannot open FIT image configuration '%s'\n", - data->os_part ? data->os_part : "default"); - ret = PTR_ERR(data->fit_config); - goto err_out; - } - - ret = fit_open_image(data->os_fit, data->fit_config, kernel_img, - &data->fit_kernel, &data->fit_kernel_size); - if (ret) - goto err_out; - if (data->os_address == UIMAGE_SOME_ADDRESS) { - ret = fit_get_image_address(data->os_fit, - data->fit_config, - kernel_img, - "load", &data->os_address); - if (!ret) - pr_info("Load address from FIT '%s': 0x%lx\n", - kernel_img, data->os_address); - /* Note: Error case uses default value. */ - } - if (data->os_entry == UIMAGE_SOME_ADDRESS) { - unsigned long entry; - ret = fit_get_image_address(data->os_fit, - data->fit_config, - kernel_img, - "entry", &entry); - if (!ret) { - data->os_entry = entry - data->os_address; - pr_info("Entry address from FIT '%s': 0x%lx\n", - kernel_img, entry); - } - /* Note: Error case uses default value. */ - } - } - - if (os_type == filetype_uimage) { + switch (os_type) { + case filetype_oftree: + ret = bootm_open_fit(data); + break; + case filetype_uimage: ret = bootm_open_os_uimage(data); - if (ret) { - pr_err("Loading OS image failed with: %s\n", - strerror(-ret)); - goto err_out; - } + break; + case filetype_elf: + ret = bootm_open_elf(data); + break; + default: + ret = 0; + break; } - if (os_type == filetype_elf) { - ret = bootm_open_elf(data); - if (ret) { - pr_err("Loading ELF image failed with: %s\n", - strerror(-ret)); - data->elf = NULL; - goto err_out; - } + if (ret) { + pr_err("Loading %s image failed with: %pe\n", + file_type_to_short_string(os_type), ERR_PTR(ret)); + goto err_out; } if (bootm_data->appendroot) { diff --git a/common/console_common.c b/common/console_common.c index 7bef74c543..ca1dad0f15 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -68,7 +68,7 @@ void log_clean(unsigned int limit) } } -static void print_colored_log_level(const int level) +static void print_colored_log_level(unsigned int ch, const int level) { if (!console_allow_color()) return; @@ -77,7 +77,7 @@ static void print_colored_log_level(const int level) if (!colored_log_level[level]) return; - puts(colored_log_level[level]); + console_puts(ch, colored_log_level[level]); } static void pr_puts(int level, const char *str) @@ -112,8 +112,8 @@ nolog: if (level > barebox_loglevel) return; - print_colored_log_level(level); - puts(str); + print_colored_log_level(CONSOLE_STDERR, level); + console_puts(CONSOLE_STDERR, str); } int pr_print(int level, const char *fmt, ...) @@ -217,7 +217,7 @@ void log_print(unsigned flags, unsigned levels) if (!(flags & (BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))) - print_colored_log_level(log->level); + print_colored_log_level(CONSOLE_STDOUT, log->level); if (flags & BAREBOX_LOG_PRINT_RAW) printf("<%i>", log->level); diff --git a/common/efi/guid.c b/common/efi/guid.c index f16c597a20..ca16f4520f 100644 --- a/common/efi/guid.c +++ b/common/efi/guid.c @@ -11,8 +11,10 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID; efi_guid_t efi_null_guid = EFI_NULL_GUID; efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID; +efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID; efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID; efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID; +efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID; #define EFI_GUID_STRING(guid, short, long) do { \ if (!efi_guidcmp(guid, *g)) \ diff --git a/common/efi/payload/Makefile b/common/efi/payload/Makefile index bcbdda335f..eeed046b00 100644 --- a/common/efi/payload/Makefile +++ b/common/efi/payload/Makefile @@ -2,5 +2,6 @@ obj-y += init.o obj-y += image.o +obj-$(CONFIG_OFTREE) += fdt.o bbenv-y += env-efi obj-$(CONFIG_CMD_IOMEM) += iomem.o diff --git a/common/efi/payload/fdt.c b/common/efi/payload/fdt.c new file mode 100644 index 0000000000..dbbc93fb7d --- /dev/null +++ b/common/efi/payload/fdt.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt(fmt) "efi-fdt: " fmt + +#include <common.h> +#include <init.h> +#include <libfile.h> +#include <efi/efi-payload.h> +#include <efi/efi-device.h> + +static int efi_fdt_probe(void) +{ + efi_config_table_t *ect; + + for_each_efi_config_table(ect) { + struct fdt_header *oftree; + u32 magic, size; + int ret; + + if (efi_guidcmp(ect->guid, EFI_DEVICE_TREE_GUID)) + continue; + + oftree = (void *)ect->table; + magic = be32_to_cpu(oftree->magic); + + if (magic != FDT_MAGIC) { + pr_err("table has invalid magic 0x%08x\n", magic); + return -EILSEQ; + } + + size = be32_to_cpu(oftree->totalsize); + ret = write_file("/efi.dtb", oftree, size); + if (ret) { + pr_err("error saving /efi.dtb: %pe\n", ERR_PTR(ret)); + return ret; + } + + return 0; + } + + return 0; +} +late_initcall(efi_fdt_probe); diff --git a/common/efi/payload/image.c b/common/efi/payload/image.c index e63da9ddf0..8e39098ae8 100644 --- a/common/efi/payload/image.c +++ b/common/efi/payload/image.c @@ -133,9 +133,11 @@ static int efi_execute_image(const char *file) pr_debug("Linux kernel detected. Adding bootargs."); options = linux_bootargs_get(); pr_err("add linux options '%s'\n", options); - loaded_image->load_options = xstrdup_char_to_wchar(options); - loaded_image->load_options_size = - (strlen(options) + 1) * sizeof(wchar_t); + if (options) { + loaded_image->load_options = xstrdup_char_to_wchar(options); + loaded_image->load_options_size = + (strlen(options) + 1) * sizeof(wchar_t); + } shutdown_barebox(); } @@ -227,8 +229,10 @@ static int do_bootm_efi(struct image_data *data) } options = linux_bootargs_get(); - boot_header->cmd_line_ptr = (uint64_t)options; - boot_header->cmdline_size = strlen(options); + if (options) { + boot_header->cmd_line_ptr = (uint64_t)options; + boot_header->cmdline_size = strlen(options); + } boot_header->code32_start = (uint64_t)loaded_image->image_base + (image_header->setup_sects+1) * 512; diff --git a/common/elf.c b/common/elf.c index f10fb77953..eec62cad61 100644 --- a/common/elf.c +++ b/common/elf.c @@ -109,7 +109,7 @@ static int load_elf_to_memory(struct elf_image *elf) if (elf->filename) { fd = open(elf->filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); return -errno; } } @@ -133,8 +133,7 @@ static int load_elf_to_memory(struct elf_image *elf) } if (read_full(fd, dst, p_filesz) < 0) { - pr_err("could not read elf segment: %s\n", - errno_str()); + pr_err("could not read elf segment: %m\n"); close(fd); return -errno; } @@ -256,13 +255,13 @@ static struct elf_image *elf_check_init(const char *filename) /* First pass is to read elf header only */ fd = open(filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); ret = -errno; goto err_free_elf; } if (read_full(fd, &hdr, sizeof(hdr)) < 0) { - pr_err("could not read elf header: %s\n", errno_str()); + pr_err("could not read elf header: %m\n"); close(fd); ret = -errno; goto err_free_elf; @@ -290,13 +289,13 @@ static struct elf_image *elf_check_init(const char *filename) */ fd = open(filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); ret = -errno; goto err_free_hdr_buf; } if (read_full(fd, elf->hdr_buf, hdr_size) < 0) { - pr_err("could not read elf program headers: %s\n", errno_str()); + pr_err("could not read elf program headers: %m\n"); ret = -errno; close(fd); goto err_free_hdr_buf; diff --git a/common/envfs-core.c b/common/envfs-core.c index 0984d53873..20b3e647d3 100644 --- a/common/envfs-core.c +++ b/common/envfs-core.c @@ -24,7 +24,6 @@ #include <environment.h> #include <libfile.h> #else -# define errno_str(x) ("void") #define pr_info(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) #define pr_warn(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) #endif @@ -151,7 +150,7 @@ int envfs_load_data(struct envfs_super *super, void *buf, size_t size, fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644); free(str); if (fd < 0) { - printf("Open %s\n", errno_str()); + printf("Open %m\n"); ret = fd; goto out; } diff --git a/common/environment.c b/common/environment.c index 0d31f5b4f7..e8c487c1a2 100644 --- a/common/environment.c +++ b/common/environment.c @@ -27,7 +27,6 @@ #include <globalvar.h> #include <libfile.h> #else -# define errno_str(x) ("void") #define EXPORT_SYMBOL(x) #endif @@ -297,7 +296,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (envfd < 0) { - printf("could not open %s: %s\n", filename, errno_str()); + printf("could not open %s: %m\n", filename); ret = -errno; goto out1; } @@ -306,7 +305,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not unprotect %s: %s\n", filename, errno_str()); + printf("could not unprotect %s: %m\n", filename); goto out; } @@ -314,7 +313,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not erase %s: %s\n", filename, errno_str()); + printf("could not erase %s: %m\n", filename); goto out; } @@ -337,7 +336,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not protect %s: %s\n", filename, errno_str()); + printf("could not protect %s: %m\n", filename); goto out; } @@ -385,7 +384,7 @@ int envfs_load(const char *filename, const char *dir, unsigned flags) envfd = open(filename, O_RDONLY); if (envfd < 0) { - printf("environment load %s: %s\n", filename, errno_str()); + printf("environment load %s: %m\n", filename); if (errno == ENOENT) printf("Maybe you have to create the partition.\n"); return -1; diff --git a/common/fastboot.c b/common/fastboot.c index 72e6ba3c40..ae7f132444 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -95,6 +95,14 @@ static int fastboot_add_partition_variables(struct fastboot *fb, } if (ret) { + if (fentry->flags & FILE_LIST_FLAG_OPTIONAL) { + pr_info("skipping unavailable optional partition %s for fastboot gadget\n", + fentry->filename); + ret = 0; + type = "unavailable"; + goto out; + } + if (fentry->flags & FILE_LIST_FLAG_CREATE) { ret = 0; type = "file"; diff --git a/common/file-list.c b/common/file-list.c index 11db7c6e44..1dc7cd8266 100644 --- a/common/file-list.c +++ b/common/file-list.c @@ -88,6 +88,9 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con case 'u': flags |= FILE_LIST_FLAG_UBI; break; + case 'o': + flags |= FILE_LIST_FLAG_OPTIONAL; + break; default: pr_err("Unknown flag '%c'\n", *partstr); return -EINVAL; @@ -113,7 +116,7 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con static const char *flags_to_str(int flags) { - static char str[sizeof "srcu"]; + static char str[sizeof "srcuo"]; char *s = str;; if (flags & FILE_LIST_FLAG_SAFE) @@ -124,6 +127,8 @@ static const char *flags_to_str(int flags) *s++ = 'c'; if (flags & FILE_LIST_FLAG_UBI) *s++ = 'u'; + if (flags & FILE_LIST_FLAG_OPTIONAL) + *s++ = 'o'; *s = '\0'; diff --git a/common/firmware.c b/common/firmware.c index b87d7da38f..e4ad6ac867 100644 --- a/common/firmware.c +++ b/common/firmware.c @@ -272,8 +272,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) firmwarefd = open(firmware, O_RDONLY); if (firmwarefd < 0) { - printf("could not open %s: %s\n", firmware, - errno_str()); + printf("could not open %s: %m\n", firmware); ret = firmwarefd; goto out; } @@ -282,7 +281,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) devicefd = open(dst, O_WRONLY); if (devicefd < 0) { - printf("could not open %s: %s\n", dst, errno_str()); + printf("could not open %s: %m\n", dst); ret = devicefd; goto out; } diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c index bde0b227f8..63c81e4ed6 100644 --- a/common/imx-bbu-nand-fcb.c +++ b/common/imx-bbu-nand-fcb.c @@ -27,16 +27,16 @@ #include <mtd/mtd-peb.h> #include <soc/imx/imx-nand-bcb.h> -#ifdef CONFIG_ARCH_IMX6 -#include <mach/imx6.h> +#ifdef CONFIG_ARCH_IMX28 static inline int fcb_is_bch_encoded(void) { - return cpu_is_mx6ul() || cpu_is_mx6ull(); + return 0; } #else +#include <mach/imx6.h> static inline int fcb_is_bch_encoded(void) { - return 0; + return cpu_is_mx6ul() || cpu_is_mx6ull(); } #endif @@ -45,6 +45,8 @@ struct imx_nand_fcb_bbu_handler { void (*fcb_create)(struct imx_nand_fcb_bbu_handler *imx_handler, struct fcb_block *fcb, struct mtd_info *mtd); + int (*fcb_read)(struct mtd_info *mtd, int block, struct fcb_block **retfcb); + int (*fcb_write)(struct mtd_info *mtd, int block, struct fcb_block *fcb); enum filetype filetype; }; @@ -123,7 +125,7 @@ static void encode_bch_ecc(void *buf, struct fcb_block *fcb, int eccbits) free_bch(bch); } -static struct fcb_block *read_fcb_bch(void *rawpage, int eccbits) +static struct fcb_block *fcb_decode_bch(void *rawpage, int eccbits) { int i, j, ret, errbit, m = 13; int blocksize = 128; @@ -227,7 +229,7 @@ static uint32_t calc_chksum(void *buf, size_t size) return ~chksum; } -static struct fcb_block *read_fcb_hamming_13_8(void *rawpage) +static struct fcb_block *fcb_decode_hamming_13_8(void *rawpage) { int i; int bitflips = 0, bit_to_flip; @@ -367,7 +369,7 @@ static ssize_t raw_write_page(struct mtd_info *mtd, void *buf, loff_t offset) return ret; } -static int read_fcb(struct mtd_info *mtd, int num, struct fcb_block **retfcb) +static int fcb_read_hamming_13_8(struct mtd_info *mtd, int block, struct fcb_block **retfcb) { int ret; struct fcb_block *fcb; @@ -377,19 +379,71 @@ static int read_fcb(struct mtd_info *mtd, int num, struct fcb_block **retfcb) rawpage = xmalloc(mtd->writesize + mtd->oobsize); - ret = raw_read_page(mtd, rawpage, mtd->erasesize * num); + ret = raw_read_page(mtd, rawpage, mtd->erasesize * block); if (ret) { - pr_err("Cannot read block %d\n", num); + pr_err("Cannot read block %d\n", block); goto err; } - if (fcb_is_bch_encoded()) - fcb = read_fcb_bch(rawpage, 40); - else - fcb = read_fcb_hamming_13_8(rawpage); + fcb = fcb_decode_hamming_13_8(rawpage); + if (IS_ERR(fcb)) { + pr_err("Cannot decode fcb on block %d\n", block); + ret = PTR_ERR(fcb); + goto err; + } + + *retfcb = fcb; + ret = 0; +err: + free(rawpage); + + return ret; +} + +static int fcb_write_hamming_13_8(struct mtd_info *mtd, int block, struct fcb_block *fcb) +{ + void *fcb_raw_page = xzalloc(mtd->writesize + mtd->oobsize); + int ret; + + memcpy(fcb_raw_page + 12, fcb, sizeof(struct fcb_block)); + + /* + * Set the first and second byte of OOB data to 0xFF, not 0x00. These + * bytes are used as the Manufacturers Bad Block Marker (MBBM). Since + * the FCB is mostly written to the first page in a block, a scan for + * factory bad blocks will detect these blocks as bad, e.g. when + * function nand_scan_bbt() is executed to build a new bad block table. + */ + memset(fcb_raw_page + mtd->writesize, 0xFF, 2); + + encode_hamming_13_8(fcb_raw_page + 12, fcb_raw_page + 12 + 512, 512); + + ret = raw_write_page(mtd, fcb_raw_page, block * mtd->erasesize); + + free(fcb_raw_page); + return ret; +} + +static int fcb_read_bch(struct mtd_info *mtd, int block, struct fcb_block **retfcb) +{ + int ret; + struct fcb_block *fcb; + void *rawpage; + + *retfcb = NULL; + + rawpage = xmalloc(mtd->writesize + mtd->oobsize); + + ret = raw_read_page(mtd, rawpage, mtd->erasesize * block); + if (ret) { + pr_err("Cannot read block %d\n", block); + goto err; + } + + fcb = fcb_decode_bch(rawpage, 40); if (IS_ERR(fcb)) { - pr_err("Cannot read fcb on block %d\n", num); + pr_err("Cannot decode fcb on block %d\n", block); ret = PTR_ERR(fcb); goto err; } @@ -402,6 +456,31 @@ err: return ret; } +static int fcb_write_bch(struct mtd_info *mtd, int block, struct fcb_block *fcb) +{ + void *fcb_raw_page = xzalloc(mtd->writesize + mtd->oobsize); + int ret; + + /* 40 bit BCH, for i.MX6UL(L) */ + encode_bch_ecc(fcb_raw_page + 32, fcb, 40); + + /* + * Set the first and second byte of OOB data to 0xFF, not 0x00. These + * bytes are used as the Manufacturers Bad Block Marker (MBBM). Since + * the FCB is mostly written to the first page in a block, a scan for + * factory bad blocks will detect these blocks as bad, e.g. when + * function nand_scan_bbt() is executed to build a new bad block table. + */ + memset(fcb_raw_page + mtd->writesize, 0xFF, 2); + + ret = raw_write_page(mtd, fcb_raw_page, block * mtd->erasesize); + + free(fcb_raw_page); + + return ret; +} + + static int fcb_create(struct imx_nand_fcb_bbu_handler *imx_handler, struct fcb_block *fcb, struct mtd_info *mtd) { @@ -438,6 +517,9 @@ static int fcb_create(struct imx_nand_fcb_bbu_handler *imx_handler, imx_handler->fcb_create(imx_handler, fcb, mtd); + fcb->DISBBM = 0; + fcb->disbbm_search = 0; + fcb->Checksum = calc_chksum((void *)fcb + 4, sizeof(*fcb) - 4); return 0; @@ -651,7 +733,7 @@ static void imx28_dbbt_create(struct dbbt_block *dbbt, int num_bad_blocks) * imx_bbu_write_fcb - Write FCB and DBBT raw data to the device * @mtd: The mtd Nand device * @block: The block to write to - * @fcb_raw_page: The raw FCB data + * @fcb: FCB * @dbbt_data_page: The DBBT data * * This function writes the FCB/DBBT data to the block given in @block @@ -660,7 +742,8 @@ static void imx28_dbbt_create(struct dbbt_block *dbbt, int num_bad_blocks) * * return: 0 on success or a negative error code otherwise. */ -static int imx_bbu_write_fcb(struct mtd_info *mtd, int block, void *fcb_raw_page, +static int imx_bbu_write_fcb(struct imx_nand_fcb_bbu_handler *imx_handler, + struct mtd_info *mtd, int block, struct fcb_block *fcb, void *dbbt_data_page) { struct dbbt_block *dbbt; @@ -682,7 +765,7 @@ again: if (ret) return ret; - ret = raw_write_page(mtd, fcb_raw_page, block * mtd->erasesize); + ret = imx_handler->fcb_write(mtd, block, fcb); if (ret) { pr_err("Writing FCB on block %d failed with %s\n", block, strerror(-ret)); @@ -843,13 +926,14 @@ out: * * return: 0 if the FCB/DBBT are valid, a negative error code otherwise */ -static int fcb_dbbt_check(struct mtd_info *mtd, int num, struct fcb_block *fcb) +static int fcb_dbbt_check(struct imx_nand_fcb_bbu_handler *imx_handler, + struct mtd_info *mtd, int num, struct fcb_block *fcb) { int ret; struct fcb_block *f; int pages_per_block = mtd->erasesize / mtd->writesize; - ret = read_fcb(mtd, num, &f); + ret = imx_handler->fcb_read(mtd, num, &f); if (ret) return ret; @@ -885,11 +969,11 @@ out: * * return: 0 for success or a negative error code otherwise. */ -static int imx_bbu_write_fcbs_dbbts(struct mtd_info *mtd, struct fcb_block *fcb) +static int imx_bbu_write_fcbs_dbbts(struct imx_nand_fcb_bbu_handler *imx_handler, + struct mtd_info *mtd, struct fcb_block *fcb) { void *dbbt = NULL; int i, ret, valid = 0; - void *fcb_raw_page; /* * The DBBT search start page is configurable in the FCB block. @@ -899,28 +983,8 @@ static int imx_bbu_write_fcbs_dbbts(struct mtd_info *mtd, struct fcb_block *fcb) if (fcb->DBBTSearchAreaStartAddress != 1) return -EINVAL; - fcb_raw_page = xzalloc(mtd->writesize + mtd->oobsize); - - if (fcb_is_bch_encoded()) { - /* 40 bit BCH, for i.MX6UL(L) */ - encode_bch_ecc(fcb_raw_page + 32, fcb, 40); - } else { - memcpy(fcb_raw_page + 12, fcb, sizeof(struct fcb_block)); - encode_hamming_13_8(fcb_raw_page + 12, - fcb_raw_page + 12 + 512, 512); - } - dbbt = dbbt_data_create(mtd); - /* - * Set the first and second byte of OOB data to 0xFF, not 0x00. These - * bytes are used as the Manufacturers Bad Block Marker (MBBM). Since - * the FCB is mostly written to the first page in a block, a scan for - * factory bad blocks will detect these blocks as bad, e.g. when - * function nand_scan_bbt() is executed to build a new bad block table. - */ - memset(fcb_raw_page + mtd->writesize, 0xFF, 2); - pr_info("Writing FCBs/DBBTs with primary/secondary Firmwares at pages %d/%d\n", fcb->Firmware1_startingPage, fcb->Firmware2_startingPage); @@ -928,7 +992,7 @@ static int imx_bbu_write_fcbs_dbbts(struct mtd_info *mtd, struct fcb_block *fcb) if (mtd_peb_is_bad(mtd, i)) continue; - if (!fcb_dbbt_check(mtd, i, fcb)) { + if (!fcb_dbbt_check(imx_handler, mtd, i, fcb)) { valid++; pr_info("FCB/DBBT on block %d still valid\n", i); continue; @@ -936,14 +1000,13 @@ static int imx_bbu_write_fcbs_dbbts(struct mtd_info *mtd, struct fcb_block *fcb) pr_info("Writing FCB/DBBT on block %d\n", i); - ret = imx_bbu_write_fcb(mtd, i, fcb_raw_page, dbbt); + ret = imx_bbu_write_fcb(imx_handler, mtd, i, fcb, dbbt); if (ret) pr_err("Writing FCB/DBBT %d failed with: %s\n", i, strerror(-ret)); else valid++; } - free(fcb_raw_page); free(dbbt); if (!valid) @@ -1183,7 +1246,7 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat } for (i = 0; i < 4; i++) { - read_fcb(mtd, i, &fcb); + imx_handler->fcb_read(mtd, i, &fcb); if (fcb) break; } @@ -1326,7 +1389,7 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat * just written as primary firmware. From now on the new * firmware will be booted. */ - ret = imx_bbu_write_fcbs_dbbts(mtd, fcb); + ret = imx_bbu_write_fcbs_dbbts(imx_handler, mtd, fcb); if (ret < 0) goto out; @@ -1347,7 +1410,7 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat */ if (ret > 0) { pr_info("New bad blocks detected, writing FCBs/DBBTs again\n"); - ret = imx_bbu_write_fcbs_dbbts(mtd, fcb); + ret = imx_bbu_write_fcbs_dbbts(imx_handler, mtd, fcb); if (ret < 0) goto out; } @@ -1380,6 +1443,14 @@ int imx6_bbu_nand_register_handler(const char *name, unsigned long flags) imx_handler->fcb_create = imx6_fcb_create; imx_handler->filetype = filetype_arm_barebox; + if (fcb_is_bch_encoded()) { + imx_handler->fcb_read = fcb_read_bch; + imx_handler->fcb_write = fcb_write_bch; + } else { + imx_handler->fcb_read = fcb_read_hamming_13_8; + imx_handler->fcb_write = fcb_write_hamming_13_8; + } + handler = &imx_handler->handler; handler->devicefile = "nand0.barebox"; handler->name = name; @@ -1393,9 +1464,6 @@ int imx6_bbu_nand_register_handler(const char *name, unsigned long flags) return ret; } -#ifdef CONFIG_ARCH_IMX28 -#include <mach/imx28-regs.h> - #define GPMI_TIMING0 0x00000070 #define GPMI_TIMING0_ADDRESS_SETUP_MASK (0xff << 16) #define GPMI_TIMING0_ADDRESS_SETUP_OFFSET 16 @@ -1413,18 +1481,31 @@ int imx6_bbu_nand_register_handler(const char *name, unsigned long flags) #define BCH_FLASHLAYOUT0_NBLOCKS_OFFSET 24 #define BCH_FLASHLAYOUT0_META_SIZE_MASK (0xff << 16) #define BCH_FLASHLAYOUT0_META_SIZE_OFFSET 16 -#define BCH_FLASHLAYOUT0_ECC0_MASK (0xf << 12) -#define BCH_FLASHLAYOUT0_ECC0_OFFSET 12 -#define BCH_FLASHLAYOUT0_DATA0_SIZE_MASK 0xfff +#define MX28_BCH_FLASHLAYOUT0_ECC0_MASK (0xf << 12) +#define MX28_BCH_FLASHLAYOUT0_ECC0_OFFSET 12 +#define BCH_FLASHLAYOUT0_ECC0_MASK (0x1f << 11) +#define BCH_FLASHLAYOUT0_ECC0_OFFSET 11 +#define BCH_FLASHLAYOUT0_GF13_0_GF14_1_MASK BIT(10) +#define BCH_FLASHLAYOUT0_GF13_0_GF14_1_OFFSET 10 +#define BCH_FLASHLAYOUT0_DATA0_SIZE_MASK 0x3ff #define BCH_FLASHLAYOUT0_DATA0_SIZE_OFFSET 0 +#define MX28_BCH_FLASHLAYOUT0_DATA0_SIZE_MASK 0xfff #define BCH_FLASH0LAYOUT1 0x00000090 #define BCH_FLASHLAYOUT1_PAGE_SIZE_MASK (0xffff << 16) #define BCH_FLASHLAYOUT1_PAGE_SIZE_OFFSET 16 -#define BCH_FLASHLAYOUT1_ECCN_MASK (0xf << 12) -#define BCH_FLASHLAYOUT1_ECCN_OFFSET 12 -#define BCH_FLASHLAYOUT1_DATAN_SIZE_MASK 0xfff +#define BCH_FLASHLAYOUT1_ECCN_MASK (0x1f << 11) +#define BCH_FLASHLAYOUT1_ECCN_OFFSET 11 +#define MX28_BCH_FLASHLAYOUT1_ECCN_MASK (0xf << 12) +#define MX28_BCH_FLASHLAYOUT1_ECCN_OFFSET 12 +#define BCH_FLASHLAYOUT1_GF13_0_GF14_1_MASK BIT(10) +#define BCH_FLASHLAYOUT1_GF13_0_GF14_1_OFFSET 10 #define BCH_FLASHLAYOUT1_DATAN_SIZE_OFFSET 0 +#define BCH_FLASHLAYOUT1_DATAN_SIZE_MASK 0x3ff +#define MX28_BCH_FLASHLAYOUT1_DATAN_SIZE_MASK 0xfff + +#ifdef CONFIG_ARCH_IMX28 +#include <mach/imx28-regs.h> static void imx28_fcb_create(struct imx_nand_fcb_bbu_handler *imx_handler, struct fcb_block *fcb, struct mtd_info *mtd) @@ -1454,6 +1535,8 @@ int imx28_bbu_nand_register_handler(const char *name, unsigned long flags) imx_handler = xzalloc(sizeof(*imx_handler)); imx_handler->fcb_create = imx28_fcb_create; + imx_handler->fcb_read = fcb_read_hamming_13_8; + imx_handler->fcb_write = fcb_write_hamming_13_8; imx_handler->filetype = filetype_mxs_bootstream; @@ -1470,3 +1553,75 @@ int imx28_bbu_nand_register_handler(const char *name, unsigned long flags) return ret; } #endif + +#ifdef CONFIG_ARCH_IMX7 +#include <mach/imx7-regs.h> + +static void imx7_fcb_create(struct imx_nand_fcb_bbu_handler *imx_handler, + struct fcb_block *fcb, struct mtd_info *mtd) +{ + void __iomem *bch_regs = IOMEM(MX7_BCH_BASE); + u32 fl0, fl1; + + /* Also hardcoded in kobs-ng */ + fcb->DataSetup = 10; + fcb->DataHold = 7; + fcb->AddressSetup = 15; + fcb->DSAMPLE_TIME = 6; + + fl0 = readl(bch_regs + BCH_FLASH0LAYOUT0); + fcb->MetadataBytes = BF_VAL(fl0, BCH_FLASHLAYOUT0_META_SIZE); + fcb->NumEccBlocksPerPage = BF_VAL(fl0, BCH_FLASHLAYOUT0_NBLOCKS); + + fl1 = readl(bch_regs + BCH_FLASH0LAYOUT1); + fcb->EccBlock0Size = 4 * BF_VAL(fl1, BCH_FLASHLAYOUT0_DATA0_SIZE); + fcb->EccBlock0EccType = BF_VAL(fl1, BCH_FLASHLAYOUT0_ECC0); + fcb->EccBlockNSize = 4 * BF_VAL(fl1, BCH_FLASHLAYOUT1_DATAN_SIZE); + fcb->EccBlockNEccType = BF_VAL(fl1, BCH_FLASHLAYOUT1_ECCN); + fcb->BCHType = BF_VAL(fl1, BCH_FLASHLAYOUT1_GF13_0_GF14_1); +} + +static int imx7_fcb_read(struct mtd_info *mtd, int block, struct fcb_block **retfcb) +{ + struct fcb_block *fcb = xzalloc(mtd->writesize); + int ret; + + ret = mxs_nand_read_fcb_bch62(block, fcb, sizeof(*fcb)); + if (ret) + free(fcb); + else + *retfcb = fcb; + + return ret; +} + +static int imx7_fcb_write(struct mtd_info *mtd, int block, struct fcb_block *fcb) +{ + return mxs_nand_write_fcb_bch62(block, fcb, sizeof(*fcb)); +} + +int imx7_bbu_nand_register_handler(const char *name, unsigned long flags) +{ + struct imx_nand_fcb_bbu_handler *imx_handler; + struct bbu_handler *handler; + int ret; + + imx_handler = xzalloc(sizeof(*imx_handler)); + imx_handler->fcb_create = imx7_fcb_create; + imx_handler->fcb_read = imx7_fcb_read; + imx_handler->fcb_write = imx7_fcb_write; + imx_handler->filetype = filetype_arm_barebox; + + handler = &imx_handler->handler; + handler->devicefile = "nand0.barebox"; + handler->name = name; + handler->flags = flags | BBU_HANDLER_CAN_REFRESH; + handler->handler = imx_bbu_nand_update; + + ret = bbu_register_handler(handler); + if (ret) + free(handler); + + return ret; +} +#endif diff --git a/common/misc.c b/common/misc.c index e0e32f47c5..400c1fb48f 100644 --- a/common/misc.c +++ b/common/misc.c @@ -105,16 +105,10 @@ const char *strerror(int errnum) } EXPORT_SYMBOL(strerror); -const char *errno_str(void) -{ - return strerror(errno); -} -EXPORT_SYMBOL(errno_str); - void perror(const char *s) { #ifdef CONFIG_ERRNO_MESSAGES - printf("%s: %s\n", s, errno_str()); + printf("%s: %m\n", s); #else printf("%s returned with %d\n", s, errno); #endif diff --git a/common/module.lds.S b/common/module.lds.S index 76f3b6d1bb..b2d685670b 100644 --- a/common/module.lds.S +++ b/common/module.lds.S @@ -15,7 +15,7 @@ * */ -#include <asm-generic/barebox.lds.h> +#include <asm/barebox.lds.h> SECTIONS { diff --git a/common/ubiformat.c b/common/ubiformat.c index e10ce31ce6..1edfc5b2a3 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -444,7 +444,7 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, } if (!args->quiet && !args->verbose) - printf("\n"); + printf("\rubiformat: formatted all eraseblocks -- 100 %% complete\n"); if (!novtbl) { if (eb1 == -1 || eb2 == -1) { diff --git a/common/uimage.c b/common/uimage.c index 42e9d9023f..72c37b7d15 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -98,7 +98,7 @@ struct uimage_handle *uimage_open(const char *filename) fd = open(filename, O_RDONLY); if (fd < 0) { - printf("could not open: %s\n", errno_str()); + printf("could not open: %m\n"); free(copy); return NULL; } @@ -109,7 +109,7 @@ struct uimage_handle *uimage_open(const char *filename) handle->copy = copy; if (read(fd, header, sizeof(*header)) < 0) { - printf("could not read: %s\n", errno_str()); + printf("could not read: %m\n"); goto err_out; } |