I can use the dd command to read a memory address (ex: 0x400):

dd if=/dev/mem count=4 bs=1 skip=$(( 0x400 ))

But how would I write a value to physical address (ex: 0x400)? I tried this:

function T_WRITE2 {
  printf $1 | dd of=/dev/mem count=4 bs=1 skip=$(( 0x400 ))

But I get the error:

dd: 'standard input': cannot skip to specified offset

(How do I get input to not skip any but the output to skip to the address to write?)

  • Remember that promiscuous /dev/mem has been widely turned off for about 16 years, now. – JdeBP Feb 3 '20 at 15:44
  • @JdeBP 0x400–0x4FF remains accessible however, using /dev/mem (as root), as do various other areas of memory. – Stephen Kitt Feb 3 '20 at 16:54
  • Not necessarily. It all depends, from factors not stated in this question and not givens here. unix.stackexchange.com/q/532381/5132 – JdeBP Feb 3 '20 at 18:17
  • @JdeBP, true, I fell into the x86 pit of doom. – Stephen Kitt Feb 3 '20 at 18:33

skip skips bytes in the input; to write to a specific offset in the output, you need to “seek”, using the seek option:

dd of=/dev/mem count=4 bs=1 seek=$((0x400))
  • I don't think that devices can be truncated. – mosvy Feb 3 '20 at 14:23
  • @mosvy they can’t, but dd might complain (then again, given that one of its main use-cases is writing to devices, it probably won’t). – Stephen Kitt Feb 3 '20 at 14:28
  • dd.c – mosvy Feb 3 '20 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.