From 4972156c9ed72432489cfd6c5499cab9d41694f7 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Wed, 21 Aug 2019 14:42:35 +0200 Subject: startup: Fix typo in comment Fixes: 35266d7e583f ("startup: Factor out the autoboot counter...") Signed-off-by: Ladislav Michl Signed-off-by: Sascha Hauer --- common/startup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/startup.c b/common/startup.c index 88eeee5e3d..b5b86d1141 100644 --- a/common/startup.c +++ b/common/startup.c @@ -202,7 +202,7 @@ void set_autoboot_state(enum autoboot_state autoboot) * do_autoboot_countdown - print autoboot countdown to console * * This prints the autoboot countdown to the console and waits for input. This - * evaluates the global.autoboot_about_key to determine which keys are allowed + * evaluates the global.autoboot_abort_key to determine which keys are allowed * to interrupt booting and also global.autoboot_timeout to determine the timeout * for the counter. This function can be called multiple times, it is executed * only the first time. -- cgit v1.2.3 From b1d88eadaa7772f8f01a402dcdd7f70e8c36c166 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:05 +0200 Subject: ratp: fix use of %hu for printing int While each of path_size and data_size is 16 bit in size, their sum may exceed this. Also the type of the resulting expression is an int, thus change the format specifier accordingly. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- common/ratp/mw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/ratp/mw.c b/common/ratp/mw.c index 55e79bbaf0..772910b39d 100644 --- a/common/ratp/mw.c +++ b/common/ratp/mw.c @@ -125,7 +125,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int req_len, /* Validate buffer size */ if (buffer_size < (path_size + data_size)) { - pr_err("ignored: size mismatch (%d < %hu): path or data not be fully given\n", + pr_err("ignored: size mismatch (%d < %u): path or data not be fully given\n", req_len, path_size + data_size); ret = -EINVAL; goto out; -- cgit v1.2.3 From 985194f2f928b9af2bdf1f9addfbf78e8b5675f0 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:06 +0200 Subject: complete: remove unused variable instr_param serves no purpose in the function. Thus remove it. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- common/complete.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/complete.c b/common/complete.c index 2dab7d1dde..919e5abc6a 100644 --- a/common/complete.c +++ b/common/complete.c @@ -277,7 +277,6 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) struct device_d *dev; struct variable_d *var; struct env_context *c; - char *instr_param; int len; char end = '=', *pos, *dot; char *begin = ""; @@ -317,7 +316,6 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) devname = xstrndup(instr, dot - instr); - instr_param++; dev = get_device_by_name(devname); free(devname); -- cgit v1.2.3 From 285f24102166c052401467601f713b0158923249 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 08:32:37 +0200 Subject: ata: fix mismatched header guards The header checks for ATA_DISK_H, but defines a different ATA_DISK, which would lead to compilation errors when included multiple times. Fix this. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- include/ata_drive.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ata_drive.h b/include/ata_drive.h index 11685eef12..d61c6f11d4 100644 --- a/include/ata_drive.h +++ b/include/ata_drive.h @@ -14,7 +14,7 @@ */ #ifndef ATA_DISK_H -# define ATA_DISK +#define ATA_DISK_H #include @@ -197,4 +197,4 @@ struct device_d; * 0x400 data data 16 bit area with 1 kiB in size */ -#endif /* ATA_DISK */ +#endif /* ATA_DISK_H */ -- cgit v1.2.3 From 69a014f1ea9c80ce9f57aea597100be70a8ae0a8 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:07 +0200 Subject: i2c-mux-pca954x: remove use of uninitialized variable force isn't used except to print its uninitialized value in an error path. Drop it. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/i2c/muxes/i2c-mux-pca954x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index d397e803b1..bbc4870c3e 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -177,7 +177,7 @@ static int pca954x_probe(struct device_d *dev) { struct i2c_client *client = to_i2c_client(dev); struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - int num, force; + int num; struct pca954x *data; uintptr_t tmp; int ret = -ENODEV; @@ -220,8 +220,8 @@ static int pca954x_probe(struct device_d *dev) if (data->virt_adaps[num] == NULL) { ret = -ENODEV; dev_err(&client->dev, - "failed to register multiplexed adapter" - " %d as bus %d\n", num, force); + "failed to register multiplexed adapter%d\n", + num); goto virt_reg_failed; } } -- cgit v1.2.3 From 405c3fe243271d81150b805628234b2c10dbf732 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:08 +0200 Subject: net: phy: mv88e6xxx: remove duplicate member in struct initializer There's already an .ops member two lines later. Remove one. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/net/phy/mv88e6xxx/chip.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/phy/mv88e6xxx/chip.c b/drivers/net/phy/mv88e6xxx/chip.c index ac08b5ef54..9688dbd1be 100644 --- a/drivers/net/phy/mv88e6xxx/chip.c +++ b/drivers/net/phy/mv88e6xxx/chip.c @@ -572,7 +572,6 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .name = "Marvell 88E6352", .num_ports = 7, .port_base_addr = 0x10, - .ops = &mv88e6352_ops, .global2_addr = 0x1c, .ops = &mv88e6352_ops, }, -- cgit v1.2.3 From cb2f9447fef731a4e640e5032b47d1131adcb8ed Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:09 +0200 Subject: smc911x: fix inverted poll-for-ready The ! operator is applied wrongly to only smc91xx_reg_read's return value, when probably the intention was for it to apply to the whole expression. However, wait_on_timeout keeps looping while the condition is false, so dropping the ! is the right thing to do. Do the right thing. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/net/smc911x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c index 0d5dcb31ee..ea7cea5f1b 100644 --- a/drivers/net/smc911x.c +++ b/drivers/net/smc911x.c @@ -540,7 +540,7 @@ static int smc911x_probe(struct device_d *dev) * poll the READY bit in PMT_CTRL. Any other access to the device is * forbidden while this bit isn't set. Try for 100ms */ - ret = wait_on_timeout(100 * MSECOND, !smc911x_reg_read(priv, PMT_CTRL) & PMT_CTRL_READY); + ret = wait_on_timeout(100 * MSECOND, smc911x_reg_read(priv, PMT_CTRL) & PMT_CTRL_READY); if (!ret) { dev_err(dev, "Device not READY in 100ms aborting\n"); return -ENODEV; -- cgit v1.2.3 From 6b585df505e86f601250566a0931f12fe2c34979 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:10 +0200 Subject: nvme: use 64 bit types for timeouts even on 32 bit systems The SHUTDOWN_TIMEOUT value of 5e9 would already exceed the range of unsigned long on a 32-bit system. Fix this by using uint64_t for all time-holding variables. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/nvme/host/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e0984708b4..d2c2b6f306 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -94,7 +94,7 @@ EXPORT_SYMBOL_GPL(nvme_set_queue_count); static int nvme_wait_ready(struct nvme_ctrl *ctrl, u64 cap, bool enabled) { uint64_t start = get_time_ns(); - unsigned long timeout = + uint64_t timeout = ((NVME_CAP_TIMEOUT(cap) + 1) * HZ / 2); u32 csts, bit = enabled ? NVME_CSTS_RDY : 0; int ret; @@ -496,7 +496,7 @@ EXPORT_SYMBOL_GPL(nvme_enable_ctrl); int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl) { uint64_t start = get_time_ns(); - unsigned long timeout = SHUTDOWN_TIMEOUT; + uint64_t timeout = SHUTDOWN_TIMEOUT; u32 csts; int ret; -- cgit v1.2.3 From 5d822854af5720c7d3defbf9a5a0e13c6041d0eb Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:11 +0200 Subject: usb: gadget: fsl_udc: remove always-true null pointer checks struct fsl_ep's name member can never be NULL because it is a character array. Remove these superfluous null pointer checks. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/usb/gadget/fsl_udc.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/usb/gadget/fsl_udc.c b/drivers/usb/gadget/fsl_udc.c index a47ba20f46..a44c7abc01 100644 --- a/drivers/usb/gadget/fsl_udc.c +++ b/drivers/usb/gadget/fsl_udc.c @@ -1422,8 +1422,7 @@ static void udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe) { struct fsl_ep *ep = get_ep_by_pipe(udc, pipe); - if (ep->name) - nuke(ep, -ESHUTDOWN); + nuke(ep, -ESHUTDOWN); } /* Clear up all ep queues */ @@ -1914,12 +1913,6 @@ static void dtd_complete_irq(struct fsl_udc *udc) curr_ep = get_ep_by_pipe(udc, i); - /* If the ep is configured */ - if (curr_ep->name == NULL) { - WARNING("Invalid EP?"); - continue; - } - /* process the req queue until an uncomplete request */ list_for_each_entry_safe(curr_req, temp_req, &curr_ep->queue, queue) { -- cgit v1.2.3 From 3d78b283f252c6774842214c22efb930d3379f3a Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:12 +0200 Subject: commands: mmc_extcsd: describe missing bit The EXT_CSD_EXCEPTION_EVENTS_STATUS array entry is wrongly duplicated. Replace the index by the correct field at byte offset 58[1]. [1]: See http://webshop.atlantiksysteme.de/temp/FLEXXONeMMC4.5pSLCSPECV1.2.pdf Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- commands/mmc_extcsd.c | 11 +++++++++-- include/mci.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c index c27bb722ea..ad8e9ad19f 100644 --- a/commands/mmc_extcsd.c +++ b/commands/mmc_extcsd.c @@ -222,8 +222,8 @@ static struct extcsd_reg extcsd[] = { .access = ACC_R, .width = 2, }, - [EXT_CSD_EXCEPTION_EVENTS_STATUS] = { - .name = "EXT_CSD_EXCEPTION_EVENTS_STATUS", + [EXT_CSD_EXCEPTION_DYNCAP_NEEDED] = { + .name = "EXT_CSD_EXCEPTION_DYNCAP_NEEDED", .access = ACC_R, .width = 1, }, @@ -1833,6 +1833,13 @@ static int print_field(u8 *reg, int index) printf("\t[4] EXTENDED_SECURITY_FAILURE: %i\n", val); return 1; + case EXT_CSD_EXCEPTION_DYNCAP_NEEDED: + if (get_field_val(EXT_CSD_EXCEPTION_EVENTS_STATUS, 2, 0x1)) { + val = get_field_val(EXT_CSD_EXCEPTION_DYNCAP_NEEDED, 0, 0x1); + printf("\t[0] DYNCAP_NEEDED: %i\n", val); + } + return 1; + case EXT_CSD_EXCEPTION_EVENTS_CTRL: val = get_field_val(EXT_CSD_EXCEPTION_EVENTS_CTRL, 1, 0x1); printf("\t[1] DYNCAP_EVENT_EN: %i\n", val); diff --git a/include/mci.h b/include/mci.h index 072008ef9d..77625ea8e9 100644 --- a/include/mci.h +++ b/include/mci.h @@ -164,6 +164,7 @@ #define EXT_CSD_EXT_PARTITIONS_ATTRIBUTE 52 /* R/W, 2 bytes */ #define EXT_CSD_EXCEPTION_EVENTS_STATUS 54 /* RO, 2 bytes */ #define EXT_CSD_EXCEPTION_EVENTS_CTRL 56 /* R/W, 2 bytes */ +#define EXT_CSD_EXCEPTION_DYNCAP_NEEDED 58 /* RO, 1 byte */ #define EXT_CSD_CLASS_6_CTRL 59 /* R/W */ #define EXT_CSD_INI_TIMEOUT_EMU 60 /* RO */ #define EXT_CSD_DATA_SECTOR_SIZE 61 /* RO */ -- cgit v1.2.3 From 1a97b56180112cd64c6c37688cf2060d01c6402d Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:13 +0200 Subject: gui: png_lode: fix freeing of uninitialized pointer If either calloc or png_uncompress_init fails, free(png) will free the uninitialized png pointer. Avoid this and while at it postpone the img allocation till after the early exit. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- lib/gui/png_lode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/gui/png_lode.c b/lib/gui/png_lode.c index 477704d976..e30db0f853 100644 --- a/lib/gui/png_lode.c +++ b/lib/gui/png_lode.c @@ -46,15 +46,16 @@ struct image *png_open(char *inbuf, int insize) LodePNGState state; int ret; unsigned error; - struct image *img = calloc(1, sizeof(struct image)); - unsigned char *png; - - if (!img) - return ERR_PTR(-ENOMEM); + struct image *img; + unsigned char *png = NULL; ret = png_uncompress_init(); if (ret) - goto err; + return ERR_PTR(ret); + + img = calloc(1, sizeof(struct image)); + if (!img) + return ERR_PTR(-ENOMEM); lodepng_state_init(&state); -- cgit v1.2.3 From f32a61b9714f0da07c49d2ead8b10a79e1ddf9c0 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 07:51:14 +0200 Subject: fs: fat: fix use of wrong enumeration type disk_read returns a DRESULT, not enum filetype. Change the return value appropriately. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- fs/fat/ff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/fat/ff.c b/fs/fat/ff.c index ba4adfc133..4d30433e5f 100644 --- a/fs/fat/ff.c +++ b/fs/fat/ff.c @@ -1538,7 +1538,7 @@ static enum filetype check_fs ( /* 0:The FAT BR, 1:Valid BR but not an FAT, 2:No DWORD *bootsec ) { - enum filetype ret; + DRESULT ret; /* Load boot record */ ret = disk_read(fs, fs->win, sect, 1); -- cgit v1.2.3 From aba7cdb357e3d442359c29f7caefc49464bfd812 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 08:54:06 +0200 Subject: libfile: have write_full return a descriptive error code So far (p|)write_full has been returning -1 on error. Some callers of write_full like imx_bbu_write_device print out the function's return value on error, effectively rendering every printed error message to be due to EPERM. On the other hand, some callers like do_memcpy, use it correctly and use errno. Sidestep the issue by having the function return -errno on errors as well. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- lib/libfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libfile.c b/lib/libfile.c index b42753c2b5..f6c588d737 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -38,7 +38,7 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset) now = pwrite(fd, buf, size, offset); if (now == 0) { errno = ENOSPC; - return -1; + return -errno; } if (now < 0) return now; @@ -66,7 +66,7 @@ int write_full(int fd, const void *buf, size_t size) now = write(fd, buf, size); if (now == 0) { errno = ENOSPC; - return -1; + return -errno; } if (now < 0) return now; @@ -194,6 +194,7 @@ again: buf = calloc(read_size + 1, 1); if (!buf) { ret = -ENOMEM; + errno = ENOMEM; goto err_out; } -- cgit v1.2.3 From 3d0bbc226abd972df3123594959ec06582671e6a Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 08:54:07 +0200 Subject: ARM: i.MX: bbu: early exit when partition too small So far, writing a barebox image exceeding the partition size aborts with EPERM as truncate isn't implemented: ERROR: writing to /dev/flash-boot.barebox failed with Operation not permitted update failed ERROR: fastboot: update barebox: Operation not permitted This is unfortunate because by the time the truncation fails, erasing the partition had already occurred. Avoid this by checking prior to the pwrite_all whether the file to be written is big enough. This is valid here because barebox update wouldn't be called on a regular file. While at it, present callers with a more helpful ENOSPC error. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx-bbu-internal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c index a563b3bc29..946a3e9a77 100644 --- a/arch/arm/mach-imx/imx-bbu-internal.c +++ b/arch/arm/mach-imx/imx-bbu-internal.c @@ -87,6 +87,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler, const void *buf, int image_len) { int fd, ret, offset = 0; + struct stat st; fd = open(devicefile, O_RDWR | O_CREAT); if (fd < 0) @@ -101,6 +102,15 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler, if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD) offset += imx_handler->flash_header_offset; + ret = fstat(fd, &st); + if (ret) + goto err_close; + + if (image_len > st.st_size) { + ret = -ENOSPC; + goto err_close; + } + ret = imx_bbu_protect(fd, imx_handler, devicefile, offset, image_len, 0); if (ret) -- cgit v1.2.3 From 6a0cade746d86ea1caeadbf598f01641a0dc830a Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 08:54:08 +0200 Subject: fs: omap4_usbbootfs: remove commented out code The code has been sitting commented out in version control for close to 7 years now, drop it. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- fs/omap4_usbbootfs.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c index 169cde7ddb..4f159210d1 100644 --- a/fs/omap4_usbbootfs.c +++ b/fs/omap4_usbbootfs.c @@ -29,39 +29,6 @@ struct file_priv { s32 id; u32 size; }; -/* -static int omap4_usbbootfs_create( - struct device_d *dev, const char *pathname, mode_t mode) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_unlink(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_mkdir(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_rmdir(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_write( - struct device_d *_dev, FILE *f, const void *inbuf, size_t size) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_truncate(struct device_d *dev, FILE *f, loff_t size) -{ - return -ENOSYS; -} -*/ static struct file_priv *omap4_usbbootfs_do_open( struct device_d *dev, int accmode, const char *filename) @@ -187,14 +154,6 @@ static struct fs_driver_d omap4_usbbootfs_driver = { .read = omap4_usbbootfs_read, .opendir = omap4_usbbootfs_opendir, .stat = omap4_usbbootfs_stat, -/* - .create = omap4_usbbootfs_create, - .unlink = omap4_usbbootfs_unlink, - .mkdir = omap4_usbbootfs_mkdir, - .rmdir = omap4_usbbootfs_rmdir, - .write = omap4_usbbootfs_write, - .truncate= omap4_usbbootfs_truncate, -*/ .flags = 0, .drv = { .probe = omap4_usbbootfs_probe, -- cgit v1.2.3 From d421771bcea063b9bce551e06552067b9074d015 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Aug 2019 08:54:05 +0200 Subject: startup: allow ctrl+c abort during boot sequence At the moment e.g. a wait for an ARP response during net boot can only aborted if the auto boot countdown was aborted. Otherwise ctrl+c is without effect. For better user experience allow code querying for ctrl+c to see it even if barebox had not dropped into a shell. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- common/startup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/startup.c b/common/startup.c index b5b86d1141..c6e119966a 100644 --- a/common/startup.c +++ b/common/startup.c @@ -314,11 +314,11 @@ static int run_init(void) autoboot = do_autoboot_countdown(); + console_ctrlc_allow(); + if (autoboot == AUTOBOOT_BOOT) run_command("boot"); - console_ctrlc_allow(); - if (autoboot == AUTOBOOT_MENU) run_command(MENUFILE); -- cgit v1.2.3 From 75a74b5c107b3bc30f9c3836208f4c17f9309eed Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Fri, 23 Aug 2019 11:25:31 +0200 Subject: console: fix out-of-bounds read in dputc(/dev/*, ...) Trying to output a single character via echo -a /dev/serial0-1 currently results in garbage output after the newline, because console.c's fops_write discards the buffer length and passes the buffer to (struct cdev)::puts which only handles NUL-terminated strings. Fix this by amending (struct cdev)::puts with a new nbytes parameter, which is correctly propagated. All this functions now return at most the nbytes parameter they were passed in. This fixes __console_puts, which used to count new lines twice in its return value. Fixes: b4f55fcf35 ("console: expose consoles in devfs") Cc: Bastian Krause Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- common/console.c | 19 +++++++++---------- common/ratp/ratp.c | 12 +++++------- drivers/serial/efi-stdio.c | 5 +++-- drivers/serial/serial_efi.c | 5 +++-- fs/pstore/platform.c | 29 +++++++++++++++++++++++++++++ include/console.h | 2 +- 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/common/console.c b/common/console.c index ee17a508ba..3f3a30fc82 100644 --- a/common/console.c +++ b/common/console.c @@ -253,20 +253,19 @@ static void console_set_stdoutpath(struct console_device *cdev) free(str); } -static int __console_puts(struct console_device *cdev, const char *s) +static int __console_puts(struct console_device *cdev, const char *s, + size_t nbytes) { - int n = 0; + size_t i; - while (*s) { - if (*s == '\n') { + for (i = 0; i < nbytes; i++) { + if (*s == '\n') cdev->putc(cdev, '\r'); - n++; - } + cdev->putc(cdev, *s); - n++; s++; } - return n; + return i; } static int fops_open(struct cdev *cdev, unsigned long flags) @@ -298,7 +297,7 @@ static ssize_t fops_write(struct cdev* dev, const void* buf, size_t count, { struct console_device *priv = dev->priv; - priv->puts(priv, buf); + priv->puts(priv, buf, count); return count; } @@ -545,7 +544,7 @@ int console_puts(unsigned int ch, const char *str) if (initialized == CONSOLE_INIT_FULL) { for_each_console(cdev) { if (cdev->f_active & ch) { - n = cdev->puts(cdev, str); + n = cdev->puts(cdev, str, strlen(str)); } } return n; diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c index 9aea1786d6..e84ad22167 100644 --- a/common/ratp/ratp.c +++ b/common/ratp/ratp.c @@ -259,19 +259,17 @@ static int ratp_console_tstc(struct console_device *cdev) return kfifo_len(ctx->console_recv_fifo) ? 1 : 0; } -static int ratp_console_puts(struct console_device *cdev, const char *s) +static int ratp_console_puts(struct console_device *cdev, const char *s, + size_t nbytes) { struct ratp_ctx *ctx = container_of(cdev, struct ratp_ctx, ratp_console); - int len = 0; - - len = strlen(s); if (ratp_busy(&ctx->ratp)) - return len; + return nbytes; - kfifo_put(ctx->console_transmit_fifo, s, len); + kfifo_put(ctx->console_transmit_fifo, s, nbytes); - return len; + return nbytes; } static void ratp_console_putc(struct console_device *cdev, char c) diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c index 0703f727e7..2ca89fa4f8 100644 --- a/drivers/serial/efi-stdio.c +++ b/drivers/serial/efi-stdio.c @@ -243,12 +243,13 @@ static int efi_process_key(struct efi_console_priv *priv, const char *inp) return 1; } -static int efi_console_puts(struct console_device *cdev, const char *s) +static int efi_console_puts(struct console_device *cdev, const char *s, + size_t nbytes) { struct efi_console_priv *priv = to_efi(cdev); int n = 0; - while (*s) { + while (nbytes--) { if (*s == 27) { priv->efi_console_buffer[n] = 0; priv->out->output_string(priv->out, diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c index f0a2b22c2b..667d51f622 100644 --- a/drivers/serial/serial_efi.c +++ b/drivers/serial/serial_efi.c @@ -130,13 +130,14 @@ static void efi_serial_putc(struct console_device *cdev, char c) serial->write(serial, &buffersize, &c); } -static int efi_serial_puts(struct console_device *cdev, const char *s) +static int efi_serial_puts(struct console_device *cdev, const char *s, + size_t nbytes) { struct efi_serial_port *uart = to_efi_serial_port(cdev); struct efi_serial_io_protocol *serial = uart->serial; uint32_t control; efi_status_t efiret; - unsigned long buffersize = strlen(s) * sizeof(char); + unsigned long buffersize = nbytes; do { efiret = serial->getcontrol(serial, &control); diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 0a6fa38edc..15c0174b1f 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -46,6 +46,35 @@ void pstore_set_kmsg_bytes(int bytes) static int pstore_ready; +static void pstore_console_write(const char *s, unsigned c) +{ + const char *e = s + c; + + while (s < e) { + struct pstore_record record = { + .type = PSTORE_TYPE_CONSOLE, + .psi = psinfo, + }; + + if (c > psinfo->bufsize) + c = psinfo->bufsize; + + record.buf = (char *)s; + record.size = c; + psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &record.id, 0, + record.buf, 0, record.size, psinfo); + s += c; + c = e - s; + } +} + +static int pstore_console_puts(struct console_device *cdev, const char *s, + size_t nbytes) +{ + pstore_console_write(s, nbytes); + return nbytes; +} + void pstore_log(const char *str) { uint64_t id; diff --git a/include/console.h b/include/console.h index 4062e5abf6..7afe59e93a 100644 --- a/include/console.h +++ b/include/console.h @@ -42,7 +42,7 @@ struct console_device { int (*tstc)(struct console_device *cdev); void (*putc)(struct console_device *cdev, char c); - int (*puts)(struct console_device *cdev, const char *s); + int (*puts)(struct console_device *cdev, const char *s, size_t nbytes); int (*getc)(struct console_device *cdev); int (*setbrg)(struct console_device *cdev, int baudrate); void (*flush)(struct console_device *cdev); -- cgit v1.2.3 From da3561223ba94dcfb8f6cb97ac42f1e4989cceff Mon Sep 17 00:00:00 2001 From: Cory Tusar Date: Mon, 26 Aug 2019 19:47:41 +0000 Subject: ARM: dts: vf610-zii-cfu1: Fix indentation Whitespace only - no functional changes. Signed-off-by: Cory Tusar Signed-off-by: Sascha Hauer --- arch/arm/dts/vf610-zii-cfu1.dts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/dts/vf610-zii-cfu1.dts b/arch/arm/dts/vf610-zii-cfu1.dts index 1de9ee9ad2..a9793adc3c 100644 --- a/arch/arm/dts/vf610-zii-cfu1.dts +++ b/arch/arm/dts/vf610-zii-cfu1.dts @@ -11,10 +11,10 @@ / { aliases { /* - * NVMEM device corresponding to EEPROM attached to - * the switch shared DT node with it, so we use that - * fact to create a desirable naming - */ + * NVMEM device corresponding to EEPROM attached to + * the switch shared DT node with it, so we use that + * fact to create a desirable naming + */ switch-eeprom = &switch0; }; }; -- cgit v1.2.3 From ed62f3929234beebd169a62993cb50fdf5492b23 Mon Sep 17 00:00:00 2001 From: Cory Tusar Date: Mon, 26 Aug 2019 20:02:25 +0000 Subject: ARM: zii-vf610-dev: Use CTRL-C as autoboot abort This brings the various VF610-based units in line with other ZII platforms. Signed-off-by: Cory Tusar Signed-off-by: Sascha Hauer --- .../boards/zii-vf610-dev/defaultenv-zii-vf610-dev/nv/autoboot_abort_key | 1 + 1 file changed, 1 insertion(+) create mode 100644 arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/nv/autoboot_abort_key diff --git a/arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/nv/autoboot_abort_key b/arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/nv/autoboot_abort_key new file mode 100644 index 0000000000..55920c9a58 --- /dev/null +++ b/arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/nv/autoboot_abort_key @@ -0,0 +1 @@ +ctrl-c \ No newline at end of file -- cgit v1.2.3 From 159e3c833f08f3c80abbd137511cf7f9e594d5bb Mon Sep 17 00:00:00 2001 From: Cory Tusar Date: Thu, 29 Aug 2019 19:10:25 +0000 Subject: Documentation: zii-imx7d-dev: Fix errors with openocd configuration script When attempting to use the existing configuration file to bootstrap an RMU2 board, openocd would consistently fail in the 'safe_reset' function with a number of errors. Disabling the internal reset handling (similar to what's done on the i.MX7 Sabre boards) allowed barebox to download and run successfully. Tested with openocd-0.10.0+dev-00924-g16496488 on a Zodiac RMU2. Signed-off-by: Cory Tusar Tested-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- Documentation/boards/imx/zii-imx7d-dev/openocd.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/boards/imx/zii-imx7d-dev/openocd.cfg b/Documentation/boards/imx/zii-imx7d-dev/openocd.cfg index f971c3fb21..6056b89578 100644 --- a/Documentation/boards/imx/zii-imx7d-dev/openocd.cfg +++ b/Documentation/boards/imx/zii-imx7d-dev/openocd.cfg @@ -138,6 +138,12 @@ proc start_barebox { } { resume $MX7_DDR_BASE_ADDR } +# disable internal reset-assert handling to +# allow reset-init to work +$_TARGETNAME.0 configure -event reset-assert "" +$_TARGETNAME.1 configure -event reset-assert "" +$_TARGETNAME_2 configure -event reset-assert "" + # hook the init function into the reset-init event ${_TARGETNAME}.0 configure -event reset-init { board_init } -- cgit v1.2.3 From f539d54de049730096016ca9d243dedca1e637fb Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Fri, 30 Aug 2019 14:40:01 +0200 Subject: Documentation: efi: fix typos Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- Documentation/boards/efi.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/boards/efi.rst b/Documentation/boards/efi.rst index 3da2daac99..2178c9ab42 100644 --- a/Documentation/boards/efi.rst +++ b/Documentation/boards/efi.rst @@ -43,7 +43,7 @@ name it ``BOOTx64.EFI`` on 64bit architectures and ``BOOTIA32.EFI`` on 32bit architectures. Switching to USB boot in the BIOS should then be enough to start barebox via USB. Some BIOSes allow to specify a path to a binary to be executed, others have a "start UEFI shell" entry which executes -EFI/Shellx64.efi on the :term:`ESP`. This can be a barebox binary aswell. +EFI/Shellx64.efi on the :term:`ESP`. This can be a barebox binary as well. To use the :ref:`state_framework`, the describing devicetree file ``state.dtb`` has to be put into the ``EFI/barebox/`` directory. Supported backends for EFI are raw partitions that can be discovered via a @@ -200,7 +200,7 @@ EFI device paths In EFI each device can be pointed to using a device path. Device paths have multiple components. The toplevel component on X86 systems will be the PCI root complex, on -other systems this can be the physical memory space. Each component will now descrive +other systems this can be the physical memory space. Each component will now describe how to find the child component on the parent bus. Additional device path nodes can describe network addresses or filenames on partitions. Device paths have a binary representation and a clearly defined string representation. These characteristics make @@ -274,7 +274,7 @@ Network Protocol GUID: EFI_GUID( 0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D ) Matching between EFI devices and drivers is done based on the Protocol GUIDs, so -whenever a driver GUID matches one of the GUIDs a device imeplements the drivers +whenever a driver GUID matches one of the GUIDs a device implements the drivers probe function is called. .. _efi_building_edk2: -- cgit v1.2.3 From 59e81b6edd48d49030033a2bc46e584c9868f3ad Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 4 Sep 2019 13:18:51 +0200 Subject: video/stm: fix return value handling for of_get_display_timings() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit of_get_display_timings() returns NULL on failure, not an error pointer. Fixes: 16fd24847d7a ("video: stmfb: Add device tree support") Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- drivers/video/stm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/video/stm.c b/drivers/video/stm.c index 0c190d36ae..d4a618fe50 100644 --- a/drivers/video/stm.c +++ b/drivers/video/stm.c @@ -551,9 +551,9 @@ static int stmfb_probe(struct device_d *hw_dev) } modes = of_get_display_timings(display); - if (IS_ERR(modes)) { + if (!modes) { dev_err(hw_dev, "unable to parse display timings\n"); - return PTR_ERR(modes); + return -EINVAL; } fbi.info.modes.modes = modes->modes; -- cgit v1.2.3 From 59cca4148316026c6b5c2145cc316392fd4c29d7 Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Wed, 4 Sep 2019 14:24:04 +0200 Subject: libfile: fix typos Signed-off-by: Michael Tretter Signed-off-by: Sascha Hauer --- lib/libfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libfile.c b/lib/libfile.c index f6c588d737..3f3ec21fdb 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -242,9 +242,9 @@ EXPORT_SYMBOL(read_file_2); * * This function reads a file to an allocated buffer. * Some TFTP servers do not transfer the size of a file. In this case - * a the file is first read to a temporary file. + * the file is first read to a temporary file. * - * Return: The buffer conataining the file or NULL on failure + * Return: The buffer containing the file or NULL on failure */ void *read_file(const char *filename, size_t *size) { -- cgit v1.2.3 From 0ca284b26d0ef59912380478b71a90976e3e79cc Mon Sep 17 00:00:00 2001 From: Clement Leger Date: Wed, 4 Sep 2019 13:24:49 +0200 Subject: elf: add 64 bits elf loading support This patch add elf64 loading support to the elf loader. Since elf32 and elf64 uses completely different types, to avoid copying all the code and simply replace elf32 with elf64, use a macro which will return the appropriate field for each type of header. This macro generates getter for elf structures according to the class of the loaded elf. All direct elf struct dereference are then replaced by call to generated functions. This allows to keep a common loader code even if types are different. Tested-by: Oleksij Rempel Signed-off-by: Clement Leger Signed-off-by: Sascha Hauer --- common/elf.c | 45 +++++++++++++++++++++++---------------------- include/elf.h | 29 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/common/elf.c b/common/elf.c index 8edf388564..4733accb05 100644 --- a/common/elf.c +++ b/common/elf.c @@ -45,29 +45,31 @@ static void elf_release_regions(struct elf_image *elf) static int load_elf_phdr_segment(struct elf_image *elf, void *src, - Elf32_Phdr *phdr) + void *phdr) { - void *dst = (void *)phdr->p_paddr; + void *dst = (void *) elf_phdr_p_paddr(elf, phdr); int ret; + u64 p_filesz = elf_phdr_p_filesz(elf, phdr); + u64 p_memsz = elf_phdr_p_memsz(elf, phdr); /* we care only about PT_LOAD segments */ - if (phdr->p_type != PT_LOAD) + if (elf_phdr_p_type(elf, phdr) != PT_LOAD) return 0; - if (!phdr->p_filesz) + if (!p_filesz) return 0; - pr_debug("Loading phdr to 0x%p (%i bytes)\n", dst, phdr->p_filesz); + pr_debug("Loading phdr to 0x%p (%llu bytes)\n", dst, p_filesz); - ret = elf_request_region(elf, (resource_size_t)dst, phdr->p_filesz); + ret = elf_request_region(elf, (resource_size_t)dst, p_filesz); if (ret) return ret; - memcpy(dst, src, phdr->p_filesz); + memcpy(dst, src, p_filesz); - if (phdr->p_filesz < phdr->p_memsz) - memset(dst + phdr->p_filesz, 0x00, - phdr->p_memsz - phdr->p_filesz); + if (p_filesz < p_memsz) + memset(dst + p_filesz, 0x00, + p_memsz - p_filesz); return 0; } @@ -75,14 +77,13 @@ static int load_elf_phdr_segment(struct elf_image *elf, void *src, static int load_elf_image_phdr(struct elf_image *elf) { void *buf = elf->buf; - Elf32_Ehdr *ehdr = buf; - Elf32_Phdr *phdr = (Elf32_Phdr *)(buf + ehdr->e_phoff); + void *phdr = (void *) (buf + elf_hdr_e_phoff(elf, buf)); int i, ret; - elf->entry = ehdr->e_entry; + elf->entry = elf_hdr_e_entry(elf, buf); - for (i = 0; i < ehdr->e_phnum; ++i) { - void *src = buf + phdr->p_offset; + for (i = 0; i < elf_hdr_e_phnum(elf, buf) ; ++i) { + void *src = buf + elf_phdr_p_offset(elf, phdr); ret = load_elf_phdr_segment(elf, src, phdr); /* in case of error elf_load_image() caller should clean up and @@ -90,22 +91,22 @@ static int load_elf_image_phdr(struct elf_image *elf) if (ret) return ret; - ++phdr; + phdr += elf_size_of_phdr(elf); } return 0; } -static int elf_check_image(void *buf) +static int elf_check_image(struct elf_image *elf) { - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)buf; - - if (strncmp(buf, ELFMAG, SELFMAG)) { + if (strncmp(elf->buf, ELFMAG, SELFMAG)) { pr_err("ELF magic not found.\n"); return -EINVAL; } - if (ehdr->e_type != ET_EXEC) { + elf->class = ((char *) elf->buf)[EI_CLASS]; + + if (elf_hdr_e_type(elf, elf->buf) != ET_EXEC) { pr_err("Non EXEC ELF image.\n"); return -ENOEXEC; } @@ -124,7 +125,7 @@ struct elf_image *elf_load_image(void *buf) elf->buf = buf; - ret = elf_check_image(buf); + ret = elf_check_image(elf); if (ret) return ERR_PTR(ret); diff --git a/include/elf.h b/include/elf.h index 92c8d9c127..633f4992dd 100644 --- a/include/elf.h +++ b/include/elf.h @@ -400,11 +400,38 @@ static inline void arch_write_notes(struct file *file) { } struct elf_image { struct list_head list; - unsigned long entry; + u8 class; + u64 entry; void *buf; }; struct elf_image *elf_load_image(void *buf); void elf_release_image(struct elf_image *elf); +#define ELF_GET_FIELD(__s, __field, __type) \ +static inline __type elf_##__s##_##__field(struct elf_image *elf, void *arg) { \ + if (elf->class == ELFCLASS32) \ + return (__type) ((struct elf32_##__s *) arg)->__field; \ + else \ + return (__type) ((struct elf64_##__s *) arg)->__field; \ +} + +ELF_GET_FIELD(hdr, e_entry, u64) +ELF_GET_FIELD(hdr, e_phnum, u16) +ELF_GET_FIELD(hdr, e_phoff, u64) +ELF_GET_FIELD(hdr, e_type, u16) +ELF_GET_FIELD(phdr, p_paddr, u64) +ELF_GET_FIELD(phdr, p_filesz, u64) +ELF_GET_FIELD(phdr, p_memsz, u64) +ELF_GET_FIELD(phdr, p_type, u32) +ELF_GET_FIELD(phdr, p_offset, u64) + +static inline unsigned long elf_size_of_phdr(struct elf_image *elf) +{ + if (elf->class == ELFCLASS32) + return sizeof(Elf32_Phdr); + else + return sizeof(Elf64_Phdr); +} + #endif /* _LINUX_ELF_H */ -- cgit v1.2.3 From aa329e50ac45ecdcd73973b5a5e27f9eaf3a7fb3 Mon Sep 17 00:00:00 2001 From: Clement Leger Date: Wed, 4 Sep 2019 13:24:50 +0200 Subject: mips: bootm: Cast elf entry into unsigned long Since elf entry type is now a u64 to accomodate both type of elf files (64 and 32 bits), we need to cast it to the pointer length before casting it to the pointer type. Signed-off-by: Clement Leger Signed-off-by: Sascha Hauer --- arch/mips/lib/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index f14540a4c4..5bb09cc2de 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -72,7 +72,7 @@ static int do_bootm_elf(struct image_data *data) shutdown_barebox(); - entry = (void *)elf->entry; + entry = (void *) (unsigned long) elf->entry; entry(-2, phys_to_virt((unsigned long)fdt)); -- cgit v1.2.3 From e9352093ceb8ca6867d9ff543711743b36ea9112 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 7 Sep 2019 16:59:30 -0700 Subject: mfd: rave-sp: Emulate firmware/bootloader mode reporting on RDU2 Add code to emulate firmware/bootloader mode reporting via "general_status" field on RDU2. This is needed to correctly report if RAVE SP is in bootloader of application mode during startup. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- drivers/mfd/rave-sp.c | 18 ++++++++++++++++-- include/linux/mfd/rave-sp.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c index 1448c4143f..67f7d4c654 100644 --- a/drivers/mfd/rave-sp.c +++ b/drivers/mfd/rave-sp.c @@ -640,6 +640,7 @@ static int rave_sp_emulated_get_status(struct rave_sp *sp, [0] = RAVE_SP_CMD_GET_FIRMWARE_VERSION, [1] = 0, }; + u8 firmware_mode; int ret; ret = rave_sp_exec(sp, cmd, sizeof(cmd), &status->firmware_version, @@ -648,8 +649,21 @@ static int rave_sp_emulated_get_status(struct rave_sp *sp, return ret; cmd[0] = RAVE_SP_CMD_GET_BOOTLOADER_VERSION; - return rave_sp_exec(sp, cmd, sizeof(cmd), &status->bootloader_version, - sizeof(status->bootloader_version)); + ret = rave_sp_exec(sp, cmd, sizeof(cmd), &status->bootloader_version, + sizeof(status->bootloader_version)); + if (ret) + return ret; + + cmd[0] = RAVE_SP_CMD_GET_OPERATIONAL_MODE; + ret = rave_sp_exec(sp, cmd, sizeof(cmd), &firmware_mode, + sizeof(firmware_mode)); + if (ret) + return ret; + + status->general_status = + firmware_mode ? RAVE_SP_STATUS_GS_FIRMWARE_MODE : 0; + + return 0; } static int rave_sp_get_status(struct rave_sp *sp) diff --git a/include/linux/mfd/rave-sp.h b/include/linux/mfd/rave-sp.h index 7b3187cb74..92315c6e12 100644 --- a/include/linux/mfd/rave-sp.h +++ b/include/linux/mfd/rave-sp.h @@ -14,6 +14,7 @@ enum rave_sp_command { RAVE_SP_CMD_GET_FIRMWARE_VERSION = 0x20, RAVE_SP_CMD_GET_BOOTLOADER_VERSION = 0x21, + RAVE_SP_CMD_GET_OPERATIONAL_MODE = 0x25, RAVE_SP_CMD_BOOT_SOURCE = 0x26, RAVE_SP_CMD_GET_BOARD_COPPER_REV = 0x2B, RAVE_SP_CMD_GET_GPIO_STATE = 0x2F, -- cgit v1.2.3 From c1388eaf5d7021c8519f0dc8943be16d1c126454 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 7 Sep 2019 17:03:14 -0700 Subject: i2c/pca954x: Initialize the mux to disconnected state Port of a Linux kernel commit cd823db8b1161ef0d756514d280715a576d65cc3 pca954x power-on default is channel 0 connected. If multiple pca954x muxes are connected to the same physical I2C bus, the parent bus will see channel 0 devices behind both muxes by default. This is bad. Scenario: -- pca954x @ 0x70 -- ch 0 (I2C-bus-101) -- EEPROM @ 0x50 | I2C-bus-1 --- | -- pca954x @ 0x71 -- ch 0 (I2C-bus-111) -- EEPROM @ 0x50 1. Load I2C bus driver: creates I2C-bus-1 2. Load pca954x driver: creates virtual I2C-bus-101 and I2C-bus-111 3. Load eeprom driver 4. Try to read EEPROM @ 0x50 on I2C-bus-101. The transaction will also bleed onto I2C-bus-111 because pca954x @ 0x71 channel 0 is connected by default. Fix: Initialize pca954x to disconnected state in pca954x_probe() Signed-off-by: Petri Gynther Signed-off-by: Jean Delvare Cc: stable@kernel.org Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- drivers/i2c/muxes/i2c-mux-pca954x.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index bbc4870c3e..42bde5ed1c 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -195,10 +195,11 @@ static int pca954x_probe(struct device_d *dev) if (gpio_is_valid(gpio)) gpio_direction_output(gpio, 1); - /* Read the mux register at addr to verify - * that the mux is in fact present. + /* Write the mux register at addr to verify + * that the mux is in fact present. This also + * initializes the mux to disconnected state. */ - if (i2c_smbus_read_byte(client) < 0) { + if (i2c_smbus_write_byte(client, 0) < 0) { dev_warn(&client->dev, "probe failed\n"); goto exit_free; } -- cgit v1.2.3 From cd6fe5bd7395c6d0e8bb3629a8d0e376a7984855 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 7 Sep 2019 17:04:32 -0700 Subject: Documentation: Provide default values for version/release Provide default values for version/release so it would be possible to run Sphinx outside of the build system. Useful for rst-sphinx backend of flycheck in Emacs, for example. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- Documentation/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/conf.py b/Documentation/conf.py index ec6ec0470b..bcd8633c91 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -53,9 +53,9 @@ copyright = u'2014, The barebox project' # The short X.Y version. import os -version = os.environ["KERNELVERSION"] +version = os.environ.get("KERNELVERSION", 'unknown version') # The full version, including alpha/beta/rc tags. -release = os.environ["KERNELRELEASE"] +release = os.environ.get("KERNELRELEASE", 'unknown release') # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -- cgit v1.2.3 From b330984ac85f9057846b20361dbf083c2d43547c Mon Sep 17 00:00:00 2001 From: David Dgien Date: Sun, 8 Sep 2019 18:01:11 -0400 Subject: console: set default console_device devname Some commands (loadb/x/y) rely on console_get_by_name, which searches the list of console devices based on console_device->devname. However, some serial drivers do not set devname, meaning that their respective console_devices can never be found. During console_register, ensure that a default devname is set if one is not already explicitly set. Signed-off-by: David Dgien Signed-off-by: Sascha Hauer --- common/console.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/console.c b/common/console.c index 3f3a30fc82..d04aae58f9 100644 --- a/common/console.c +++ b/common/console.c @@ -323,6 +323,9 @@ int console_register(struct console_device *newcdev) dev->parent = newcdev->dev; platform_device_register(dev); + if (!newcdev->devname) + newcdev->devname = xstrdup(dev_name(dev)); + newcdev->open_count = 0; /* -- cgit v1.2.3 From fb2e987ee1f54bc9fac26be03e93f839faa9e023 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 9 Sep 2019 10:14:44 +0200 Subject: gpio: iopoll: implement gpio_poll_timeout_us Sometimes we need to wait for state change on a GPIO, provide a helper for future code to do this. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- include/gpio.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/gpio.h b/include/gpio.h index 1926edeca7..4d5f2c25c7 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -3,6 +3,7 @@ #include #include +#include #ifdef CONFIG_GENERIC_GPIO void gpio_set_value(unsigned gpio, int value); @@ -31,6 +32,21 @@ static inline int gpio_direction_input(unsigned gpio) void gpio_set_active(unsigned gpio, bool state); int gpio_is_active(unsigned gpio); int gpio_direction_active(unsigned gpio, bool state); + +/** + * gpio_poll_timeout_us - Poll till GPIO reaches requested active state + * @gpio: gpio to poll + * @active: wait till GPIO is active if true, wait till it's inactive if false + * @timeout_us: timeout in microseconds + * + * During the wait barebox pollers are called, if any. + */ +#define gpio_poll_timeout_us(gpio, active, timeout_us) \ + ({ \ + int __state; \ + readx_poll_timeout(gpio_is_active, gpio, __state, \ + __state == (active), timeout_us); \ + }) #else static inline void gpio_set_active(unsigned gpio, int value) { @@ -43,6 +59,8 @@ static inline int gpio_direction_active(unsigned gpio, int value) { return -EINVAL; } + +#define gpio_poll_timeout_us(gpio, val, timeout_us) (-ENOSYS) #endif #if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0 -- cgit v1.2.3 From 66bd3f1c4cc3b76ef40f95dd2ee5a5c60d22c446 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 9 Sep 2019 10:24:07 +0200 Subject: param: make dev_add_param_string_fixed value parameter const The function is so far unused and the parameter's only use is to be passed as argument to dev_add_param_fixed which is const as well. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- include/param.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/param.h b/include/param.h index b618a2305d..dea6990497 100644 --- a/include/param.h +++ b/include/param.h @@ -272,7 +272,7 @@ static inline struct param_d *dev_add_param_string_ro(struct device_d *dev, cons } static inline struct param_d *dev_add_param_string_fixed(struct device_d *dev, const char *name, - char *value) + const char *value) { return dev_add_param_fixed(dev, name, value); } -- cgit v1.2.3 From ea06d25a931324f8c082d13522c9125468cec317 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 9 Sep 2019 10:06:09 +0200 Subject: input: add handler for reset and power key input events Kernel device trees may indicate linux,code = KEY_POWER or KEY_RESTART, mostly for gpio-keys. Make barebox able to act on them by registering an appropriate input notifier. Suggested-by: Oleksij Rempel Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/input/Kconfig | 6 ++++++ drivers/input/Makefile | 1 + drivers/input/specialkeys.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 drivers/input/specialkeys.c diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 1f89ae3892..be061683fb 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -64,4 +64,10 @@ config KEYBOARD_USB help This driver implements support for usb keyboard. +config INPUT_SPECIALKEYS + bool "Special keys handler" + select INPUT + help + Say Y here to handle key events like KEY_RESTART and KEY_POWER. + endmenu diff --git a/drivers/input/Makefile b/drivers/input/Makefile index e694a98d10..36a4204d53 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o obj-$(CONFIG_KEYBOARD_IMX_KEYPAD) += imx_keypad.o obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o +obj-$(CONFIG_INPUT_SPECIALKEYS) += specialkeys.o diff --git a/drivers/input/specialkeys.c b/drivers/input/specialkeys.c new file mode 100644 index 0000000000..ff29b8455d --- /dev/null +++ b/drivers/input/specialkeys.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019 Ahmad Fatoum, Pengutronix + +#include +#include +#include +#include +#include +#include + +static void input_specialkeys_notify(struct input_notifier *in, + struct input_event *ev) +{ + switch (ev->code) { + case KEY_RESTART: + pr_info("Triggering reset due to special key.\n", ev->code); + restart_machine(); + break; + + case KEY_POWER: + pr_info("Triggering poweroff due to special key.\n", ev->code); + poweroff_machine(); + break; + } + + pr_debug("ignoring code: %d\n", ev->code); +} + +static struct input_notifier notifier; + +static int input_specialkeys_init(void) +{ + notifier.notify = input_specialkeys_notify; + return input_register_notfier(¬ifier); +} +late_initcall(input_specialkeys_init); -- cgit v1.2.3 From a10dbfc4175867c0d15f02b7f244837c5d41478e Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 9 Sep 2019 11:20:47 +0200 Subject: edit: replace ASCII codes by symbolic names Code has some magic numbers, replace them. This has the added benefit that at least the touched lines are now charset-agnostic. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- commands/edit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/edit.c b/commands/edit.c index 290222ce15..ba6a8c7cdd 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -524,12 +524,12 @@ static int do_edit(int argc, char *argv[]) } else delete_char(textx); break; - case 13: - case 10: + case '\r': + case '\n': split_line(); break; case 127: - case 8: + case '\b': if (textx > 0) { textx--; delete_char(textx); @@ -542,10 +542,10 @@ static int do_edit(int argc, char *argv[]) merge_line(curline); } break; - case 4: + case CTL_CH('d'): ret = save_file(argv[1]); goto out; - case 3: + case CTL_CH('c'): goto out; default: if ((signed char)c != -1) -- cgit v1.2.3