memtool(1)

๐Ÿ’– memtool(1) โ€” the manual, but make it slay ๐Ÿ’–

okay so bestie, gather round, because this one is a General Commands Manual and it's genuinely so useful. It's called memtool, and yes, it does exactly what the name says. Let's go. โœจ


๐ŸŒธ NAME ๐ŸŒธ

memtool โ€” display and modify memory. that's it, that's the whole vibe. ๐Ÿ’…


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

memtool -V
memtool md [-b|-w|-l|-q] [-x] [-s filename] region
memtool mw [-b|-w|-l|-q] [-d filename] start data...

like, three whole moods. pick your fighter. ๐Ÿซถ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So memtool lets you read and write regions of files. And here's the iconic part: when you point it at /dev/mem โ€” which is the default file, btw, in case you were wondering โ€” those regions are literally memory mapped registers. main character behaviour, honestly. ๐Ÿ‘‘

Right now there are exactly two subcommands, no more no less:

  • mw โ€” write to memory / a file ๐Ÿ“
  • md โ€” read from memory / a file ๐ŸŒˆ

Usually memtool operates on files (regular ones or devices) using mmap(2). But here's the plot twist ๐Ÿซข โ€” if filename is of the form mdio:ethname.id, where ethname is the name of an ethernet device and id is an MDIO address, then the phy with address id on the MDIO bus related to the ethernet device ethname gets accessed instead. (iykyk ๐Ÿ’œ) And to prevent ambiguities when you're using the mmap access method, just use mmap:filename as the parameter. easy. โœจ

โš ๏ธ Real talk, bestie. On some machines there are alignment restrictions that forbid, for example, reading a word from an address that isn't word aligned. memtool does not try to be smart here โ€” it just tries whatever the caller requested. This might result in all kinds of errors, and those errors are not considered to be a bug of the tool, but either the machine or the caller. so like... don't come for memtool, okay? ๐Ÿ˜ญ

โœจ OPTIONS โœจ

  • -V โ€” dump memtool version and exit. short, sweet, done. ๐Ÿ’…

๐Ÿ’– COMMON OPTIONS FOR SUBCOMMANDS ๐Ÿ’–

these ones you'll be reaching for constantly, ngl.

  • -b โ€” use byte wise (8-bit) access ๐Ÿ“
  • -w โ€” use word wise (16-bit) access ๐ŸŒธ
  • -l โ€” use long wise (32-bit) access ๐Ÿฆ‹
  • -q โ€” use quad wise (64-bit) access โœจ
  • -d filename โ€” write to filename. ๐Ÿ“
  • -s filename โ€” read from filename. ๐Ÿ“–
  • -x โ€” swap bytes at output ๐Ÿ”„

๐ŸŒˆ REGIONS ๐ŸŒˆ

Memory regions can be specified in two different forms, and honestly both are giving:

start[+size]
start-end

Okay let's break it down ๐Ÿซถ:

  • start specifies the byte offset of the region's beginning, i.e. the first included address.
  • size specifies the size of the region in bytes and defaults to 0x100. yes bestie, that's the default, don't forget it. ๐Ÿ’…
  • Alternatively, end specifies the offset of the last included address.

And about those offsets โ€” you can write them in decimal or in hexadecimal with a prefix 0x. Plus, for the big numbers era, you can use the suffixes G, M, and k, which multiply by 1024^3, 1024^2, and 1024 respectively. math but make it cute. ๐Ÿงฎโœจ


and that's the whole page, bestie!! this lovely little manual is from December 2015, and the page itself is memtool(1) โ€” general commands manual, iconic as always. go read some memory, you've got this. ๐ŸŽ€๐Ÿ’–๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from