Skip to content

examples/mtdpart:Register MTD devices using the mtd_register method #3130

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jingfei195887
Copy link

@jingfei195887 jingfei195887 commented Jul 13, 2025

Summary

  1. Due to the automatic wrapping of MTD devices during the open() process, the legacy registration methods ftl_initialize() and bchdev_register() are no longer required for MTD device registration. The new method is now changed to register_mtddriver

  2. Some code for space release and deregistration has been added, and certain error handling methods have been updated.

Test

Run the examples/mtdpart in sim:nsh for test an test is passed

nsh> mtdpart
Flash Geometry:
  blocksize:      512
  erasesize:      4096
  neraseblocks:   32
  No. partitions: 4
  Partition size: 64 Blocks (32768 bytes)
Creating partitions
  Partition 1. Block offset=0, size=64
  Partition 2. Block offset=64, size=64
  Partition 3. Block offset=128, size=64
  Partition 4. Block offset=192, size=64
Initializing media:
Checking partitions:
  Partition 1. Byte offset=0, size=32768
  Partition 2. Byte offset=32768, size=32768
  Partition 3. Byte offset=65536, size=32768
  Partition 4. Byte offset=98304, size=32768
Verifying media:
PASS: Everything looks good

@xiaoxiang781216
Copy link
Contributor

please fix:

Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:551:1: error: Too many blank lines
/home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:457: verifed ==> verified

@jingfei195887
Copy link
Author

please fix:

Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:551:1: error: Too many blank lines
/home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:457: verifed ==> verified

sure, working on this now

@jingfei195887
Copy link
Author

please fix:

Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:551:1: error: Too many blank lines
/home/runner/work/nuttx-apps/nuttx-apps/apps/examples/mtdpart/mtdpart_main.c:457: verifed ==> verified

done

@xiaoxiang781216
Copy link
Contributor

still have ci error, please run checkpatch.sh before you update patch. @jingfei195887

1. Due to the automatic wrapping of MTD devices during the open() process,
   the legacy registration methods ftl_initialize() and bchdev_register()
   are no longer required for MTD device registration. The new method is
   now changed to register_mtddriver

2. Some code for space release and deregistration has been added,
   and certain error handling methods have been updated.
@@ -204,7 +194,9 @@ int main(int argc, FAR char *argv[])
if (ret < 0)
{
ferr("ERROR: mtd->ioctl failed: %d\n", ret);
exit(3);
unregister_mtddriver("/dev/mtd0");
Copy link
Contributor

@xiaoxiang781216 xiaoxiang781216 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the end and add label err_mtd

@@ -317,8 +294,9 @@ int main(int argc, FAR char *argv[])
if (nbytes < 0)
{
printf("ERROR: write to /dev/mtd0 failed: %d\n", errno);
fflush(stdout);
exit(9);
close(fd);
Copy link
Contributor

@xiaoxiang781216 xiaoxiang781216 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move close to the end and add label err_fd

fflush(stdout);
exit(1);
status = 1;
goto errout;
Copy link
Contributor

@xiaoxiang781216 xiaoxiang781216 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
goto errout;
goto err;

@@ -133,8 +133,7 @@ int main(int argc, FAR char *argv[])
FAR struct mtd_dev_s *part[CONFIG_EXAMPLES_MTDPART_NPARTITIONS + 1];
FAR struct mtd_geometry_s geo;
FAR uint32_t *buffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need zero

printf("ERROR: error status %d\n", status);
}

if (buffer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the check


if (status)
{
printf("ERROR: error status %d\n", status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the unnecessary log

free(buffer);
}

if (master)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need zero at line 132, please fix ALL warning before submit your change.

fflush(stdout);
exit(7);
status = 6;
goto errout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto err_buf

exit(3);
printf("ERROR: register_mtddriver /dev/mtd0 failed: %d\n", ret);
status = 2;
goto errout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto err_mtd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants