Changeset View
Changeset View
Standalone View
Standalone View
sbin/nvmecontrol/firmware.c
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | if ((*buf = malloc(filesize)) == NULL) | ||||
errx(1, "unable to malloc %d bytes", filesize); | errx(1, "unable to malloc %d bytes", filesize); | ||||
if ((*size = read(fd, *buf, filesize)) < 0) | if ((*size = read(fd, *buf, filesize)) < 0) | ||||
err(1, "error reading '%s'", path); | err(1, "error reading '%s'", path); | ||||
/* XXX assuming no short reads */ | /* XXX assuming no short reads */ | ||||
if (*size != filesize) | if (*size != filesize) | ||||
errx(1, | errx(1, | ||||
"error reading '%s' (read %d bytes, requested %d bytes)", | "error reading '%s' (read %d bytes, requested %d bytes)", | ||||
path, *size, filesize); | path, *size, filesize); | ||||
close(fd); | |||||
} | } | ||||
static void | static void | ||||
update_firmware(int fd, uint8_t *payload, int32_t payload_size) | update_firmware(int fd, uint8_t *payload, int32_t payload_size) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
int32_t off, resid, size; | int32_t off, resid, size; | ||||
void *chunk; | void *chunk; | ||||
Show All 21 Lines | if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) | ||||
err(1, "firmware download request failed"); | err(1, "firmware download request failed"); | ||||
if (nvme_completion_is_error(&pt.cpl)) | if (nvme_completion_is_error(&pt.cpl)) | ||||
errx(1, "firmware download request returned error"); | errx(1, "firmware download request returned error"); | ||||
resid -= size; | resid -= size; | ||||
off += size; | off += size; | ||||
} | } | ||||
free(chunk); | |||||
} | } | ||||
static int | static int | ||||
activate_firmware(int fd, int slot, int activate_action) | activate_firmware(int fd, int slot, int activate_action) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
uint16_t sct, sc; | uint16_t sct, sc; | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |