Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msg API changes #219

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions cm4-tool/tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ int main(int argc, char *argv[])
{
msg_t msg;
multi_i_t *i = (void *)msg.i.raw;
multi_o_t *o = (void *)msg.o.raw;
int opt, usage = 0, file = 0, example = 0, start = 0, terminal = 0, termno = -1;
unsigned int offset = 0;
char *path = NULL;
Expand Down Expand Up @@ -133,8 +132,7 @@ int main(int argc, char *argv[])
msg.type = mtDevCtl;
msg.o.data = NULL;
msg.o.size = 0;

i->id = driver.id;
msg.oid = driver;

if (file) {
i->cm4_type = CM4_LOAD_FILE;
Expand All @@ -154,8 +152,8 @@ int main(int argc, char *argv[])
return -1;
}

if (o->err < 0) {
fprintf(stderr, "imxrt117x-cm4 driver failed to run the binary (err %d)\n", o->err);
if (msg.o.err < 0) {
fprintf(stderr, "imxrt117x-cm4 driver failed to run the binary (err %d)\n", msg.o.err);
free(path);

return -1;
Expand All @@ -170,8 +168,8 @@ int main(int argc, char *argv[])
msg.type = mtDevCtl;
msg.o.data = NULL;
msg.o.size = 0;
msg.oid = driver;
i->cm4_type = CM4_RUN_CORE;
i->id = driver.id;
msg.i.data = (void *)&offset;
msg.i.size = sizeof(offset);

Expand All @@ -182,8 +180,8 @@ int main(int argc, char *argv[])
return -1;
}

if (o->err < 0) {
fprintf(stderr, "imxrt117x-cm4 driver failed to start the core (err %d)\n", o->err);
if (msg.o.err < 0) {
fprintf(stderr, "imxrt117x-cm4 driver failed to start the core (err %d)\n", msg.o.err);
free(path);

return -1;
Expand Down
7 changes: 3 additions & 4 deletions metacheck/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,22 @@ static int readraw(oid_t oid, uint32_t addr, void *data, int size)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;

msg.type = mtDevCtl;
msg.o.data = data;
msg.o.size = size;
msg.oid = oid;

idevctl->type = flashsrv_devctl_readraw;
idevctl->read.oid = oid;
idevctl->read.size = size;
idevctl->read.address = addr;

if (msgSend(oid.port, &msg) < 0) {
return -1;
}

if (odevctl->err != size) {
return odevctl->err;
if (msg.o.err != size) {
return msg.o.err;
}

return 0;
Expand Down
36 changes: 15 additions & 21 deletions nandpart/flashmng.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,31 @@ int flashmng_isBad(const oid_t *oid, const flashsrv_info_t *info, unsigned int b
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = *oid;
idevctl->type = flashsrv_devctl_isbad;
idevctl->badblock.oid = *oid;
idevctl->badblock.address = block * info->erasesz;

err = msgSend(oid->port, &msg);
if (err < 0) {
return err;
}

return odevctl->err;
return msg.o.err;
}


int flashmng_erase(const oid_t *oid, const flashsrv_info_t *info, unsigned int start, unsigned int size)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = *oid;
idevctl->type = flashsrv_devctl_erase;
idevctl->erase.oid = *oid;
idevctl->erase.address = start * info->erasesz;
idevctl->erase.size = size * info->erasesz;

Expand All @@ -59,22 +57,21 @@ int flashmng_erase(const oid_t *oid, const flashsrv_info_t *info, unsigned int s
return err;
}

return odevctl->err;
return msg.o.err;
}


int flashmng_readMeta(const oid_t *oid, const flashsrv_info_t *info, void *data, unsigned int page)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = *oid;
msg.o.data = data;
msg.o.size = info->oobsz;
idevctl->type = flashsrv_devctl_readmeta;
idevctl->read.oid = *oid;
idevctl->read.address = page * info->writesz;
idevctl->read.size = info->oobsz;

Expand All @@ -83,22 +80,21 @@ int flashmng_readMeta(const oid_t *oid, const flashsrv_info_t *info, void *data,
return err;
}

return odevctl->err;
return msg.o.err;
}


int flashmng_writeMeta(const oid_t *oid, const flashsrv_info_t *info, const void *data, unsigned int page)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.i.data = (void *)data; /* TODO: remove cast after msg.i.data becomes const void * */
msg.oid = *oid;
msg.i.data = data;
msg.i.size = info->oobsz;
idevctl->type = flashsrv_devctl_writemeta;
idevctl->write.oid = *oid;
idevctl->write.address = page * info->writesz;
idevctl->write.size = info->oobsz;

Expand All @@ -107,7 +103,7 @@ int flashmng_writeMeta(const oid_t *oid, const flashsrv_info_t *info, const void
return err;
}

return odevctl->err;
return msg.o.err;
}


Expand Down Expand Up @@ -154,43 +150,41 @@ int flashmng_readPtable(const oid_t *oid, const flashsrv_info_t *info, ptable_t
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = *oid;
msg.o.data = ptable;
msg.o.size = info->writesz;
idevctl->type = flashsrv_devctl_readptable;
idevctl->ptable.oid = *oid;

err = msgSend(oid->port, &msg);
if (err < 0) {
return err;
}

return odevctl->err;
return msg.o.err;
}


int flashmng_writePtable(const oid_t *oid, const flashsrv_info_t *info, ptable_t *ptable)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = *oid;
msg.i.data = ptable;
msg.i.size = info->writesz;
idevctl->type = flashsrv_devctl_writeptable;
idevctl->ptable.oid = *oid;

err = msgSend(oid->port, &msg);
if (err < 0) {
return err;
}

return odevctl->err;
return msg.o.err;
}


Expand All @@ -209,9 +203,9 @@ int flashmng_info(const oid_t *oid, flashsrv_info_t *info)
return err;
}

if (odevctl->err == EOK) {
if (msg.o.err == EOK) {
*info = odevctl->info;
}

return odevctl->err;
return msg.o.err;
}
28 changes: 12 additions & 16 deletions nandtool/flashmng.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ int flashmng_readraw(oid_t oid, off_t addr, void *data, size_t size)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;

msg.type = mtDevCtl;
msg.o.data = data;
msg.o.size = size;
msg.oid = oid;

idevctl->type = flashsrv_devctl_readraw;
idevctl->read.oid = oid;
idevctl->read.size = size;
/* FIXME: Now imx6ull nand DevCtl API supports only 32-bit offsets */
idevctl->read.address = (uint32_t)addr;
Expand All @@ -62,26 +61,25 @@ int flashmng_readraw(oid_t oid, off_t addr, void *data, size_t size)
return -1;
}

return odevctl->err;
return msg.o.err;
}


static int write_ex(oid_t oid, uint32_t addr, const void *data, size_t size, int type)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
int err;

msg.type = mtDevCtl;
msg.oid = oid;
msg.i.data = (void *)data; /* TODO: fix after msg.i.data becomes const void * */
msg.i.size = size;
idevctl->type = type;
idevctl->write.oid = oid;
idevctl->write.address = addr;
idevctl->write.size = size;

if (((err = msgSend(oid.port, &msg)) < 0) || ((err = odevctl->err) < 0))
if (((err = msgSend(oid.port, &msg)) < 0) || ((err = msg.o.err) < 0))
return err;

if (err != size)
Expand Down Expand Up @@ -112,20 +110,19 @@ int flashmng_erase(oid_t oid, unsigned int start, unsigned int size)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
flashsrv_info_t *info;
int err;

if ((info = flashmng_info(oid)) == NULL)
return -EFAULT;

msg.type = mtDevCtl;
msg.oid = oid;
idevctl->type = flashsrv_devctl_erase;
idevctl->erase.oid = oid;
idevctl->erase.address = start * info->erasesz;
idevctl->erase.size = size * info->erasesz;

if (((err = msgSend(oid.port, &msg)) < 0) || ((err = odevctl->err) < 0))
if (((err = msgSend(oid.port, &msg)) < 0) || ((err = msg.o.err) < 0))
return err;

return EOK;
Expand Down Expand Up @@ -187,22 +184,21 @@ int flashmng_isbad(oid_t oid, unsigned int block)
{
msg_t msg = { 0 };
flash_i_devctl_t *idevctl = (flash_i_devctl_t *)msg.i.raw;
flash_o_devctl_t *odevctl = (flash_o_devctl_t *)msg.o.raw;
flashsrv_info_t *info;
int err;

if ((info = flashmng_info(oid)) == NULL)
return -EFAULT;

msg.type = mtDevCtl;
msg.oid = oid;
idevctl->type = flashsrv_devctl_isbad;
idevctl->badblock.oid = oid;
idevctl->badblock.address = block * info->erasesz;

if (((err = msgSend(oid.port, &msg)) < 0) || ((err = odevctl->err) < 0))
if (((err = msgSend(oid.port, &msg)) < 0) || ((err = msg.o.err) < 0))
return err;

return odevctl->err;
return msg.o.err;
}


Expand All @@ -218,7 +214,7 @@ flashsrv_info_t *flashmng_info(oid_t oid)
msg.type = mtDevCtl;
idevctl->type = flashsrv_devctl_info;

if ((msgSend(oid.port, &msg) < 0) || (odevctl->err < 0))
if ((msgSend(oid.port, &msg) < 0) || (msg.o.err < 0))
return NULL;

flashmng_common.info.metasz = odevctl->info.metasz;
Expand All @@ -228,9 +224,9 @@ flashsrv_info_t *flashmng_info(oid_t oid)

msg.type = mtGetAttr;
msg.i.attr.type = atSize;
msg.i.attr.oid = oid;
msg.oid = oid;

if ((msgSend(oid.port, &msg) < 0) || (msg.o.attr.err < 0)) {
if ((msgSend(oid.port, &msg) < 0) || (msg.o.err < 0)) {
flashmng_common.oid.port = 0;
flashmng_common.oid.id = 0;
return NULL;
Expand Down
Loading
Loading