Sign up here and you can log into the forum!

named pipes, read nand on hub

Have a question about devices internals, memory layout, reverse engineering, etc---This is the place for anything so technical that it would cause a n00b's head to 'splode

Re: named pipes, read nand on hub   

Postby KAD » Wed Oct 29, 2014 7:09 am

I think you forgot the issue is with running from php

/bin/setxenv is a symlink to /bin/setxenv.sh
here's the full script for reference
/bin/setxenv.sh
Code: Select all

# cat /bin/setxenv.sh
#!/bin/sh

DEVICENAME="mtdblock0"
set -e

SKIP_BLK=
COMMAND=
MODE=
KEY=
VALUE=

if [ "$0" = "/bin/setxenv" ]; then
  if [ $# = 0 ] || [ $# -gt 4 ]; then
echo "Syntax error: $0 <skip_blk> [[-b] <keyname> <value>]|[<keyname>]"
exit -1
  fi

  if [ $1 -lt 0 ] || [ $1 -gt 3 ]; then
    echo "Error: skip_blk = 0, 1, 2, or 3"
    exit -1
  fi
  SKIP_BLK=$1

  if [ $# = 1 ]; then
    COMMAND=listall
  fi
  if [ $# = 2 ]; then
    COMMAND=listone
    KEY=$2
  fi
  if [ $# = 3 ]; then
    COMMAND=addone
    MODE=text
    KEY=$2
    VALUE=$3
  fi
  if [ $# = 4 ]; then
    if [ $2 != "-b" ]; then
echo "Syntax error: $0 <skip_blk> [[-b] <keyname> <value>]|[<keyname>]"
exit -1
    else
      COMMAND=addone
      MODE=binary
      KEY=$3
      VALUE=$4
    fi
  fi

fi

if [ $0 = "/bin/unsetxenv" ]; then
  if [ $# != 2 ]; then
echo "Syntax error: $0 <skip_blk> <keyname>"
exit -1
  fi
  SKIP_BLK=$1

  COMMAND=deleteone
  KEY=$2
fi

#echo skip_blk = "$SKIP_BLK"
#echo command = "$COMMAND"
#echo mode = "$MODE"
#echo key = "$KEY"
#echo value = "$VALUE"

# Scripting arguments ...
# Which block (0 .. 3) to be operate on
# SKIP_BLK=0
# XENV2 program parameters ...
# XENV2_PRG_OPT=

###### Should not need to change bellows ...

# Block size (in KB)
PHY_BLK_SIZE=128

# XENV2 block size (in KB)
XENV2_BLK_SIZE=16

# NAND Block device
#NAND_BDEV=/dev/sigmblk0
NAND_BDEV=/dev/${DEVICENAME}
echo "Open $NAND_BDEV"
# XENV2 operation program
XENV2_PRG=/bin/setxenv2_mipsel

#if [ ! -b "$NAND_BDEV" ]; then
#       echo "$NAND_BDEV not found."
#       exit -1
if [ ! -x "$XENV2_PRG" ]; then
        echo "$XENV2_PRG program not found."
        exit -1
fi

PHY_BLOCK_FILE=`mktemp /tmp/phy_blk.tmp.XXXXXX`
XENV2_TMP_FILE=`mktemp /tmp/xenv.tmp.XXXXXX`
PHY_REST_FILE=`mktemp /tmp/phy_rest.tmp.XXXXXX`

dd if=$NAND_BDEV of=$PHY_BLOCK_FILE bs=${PHY_BLK_SIZE}K skip=$SKIP_BLK count=1
dd if=$PHY_BLOCK_FILE of=$XENV2_TMP_FILE bs=1K count=$XENV2_BLK_SIZE
dd if=$PHY_BLOCK_FILE of=$PHY_REST_FILE bs=1K skip=$XENV2_BLK_SIZE

# Operating on XENV2 block
# $XENV2_PRG $XENV2_PRG_OPT $XENV2_TMP_FILE
case "$COMMAND" in
  listall)
  $XENV2_PRG -f $XENV2_TMP_FILE
  ;;
  listone)
  $XENV2_PRG -f $XENV2_TMP_FILE -k $KEY
  ;;
  addone)
  if [ "$MODE" == "text" ]; then
    $XENV2_PRG -f $XENV2_TMP_FILE -k $KEY -v "$VALUE"
  else
    $XENV2_PRG -f $XENV2_TMP_FILE -b -k $KEY -v "$VALUE"
  fi
  cat $XENV2_TMP_FILE /dev/zero | dd of=$PHY_BLOCK_FILE bs=1K count=$XENV2_BLK_SIZE
  cat $PHY_REST_FILE >> $PHY_BLOCK_FILE
  dd if=$PHY_BLOCK_FILE of=$NAND_BDEV bs=${PHY_BLK_SIZE}K seek=$SKIP_BLK count=1
  ;;
  deleteone)
  $XENV2_PRG -f $XENV2_TMP_FILE -u -k $KEY
  cat $XENV2_TMP_FILE /dev/zero | dd of=$PHY_BLOCK_FILE bs=1K count=$XENV2_BLK_SIZE
  cat $PHY_REST_FILE >> $PHY_BLOCK_FILE
  dd if=$PHY_BLOCK_FILE of=$NAND_BDEV bs=${PHY_BLK_SIZE}K seek=$SKIP_BLK count=1
  ;;
esac

sync
sync

rm -f $PHY_BLOCK_FILE $XENV2_TMP_FILE $PHY_REST_FILE

exit 0

#



if I run this
Code: Select all
setxenv 0 l.alpha.fw_sign sisi
from cmd line there are no errors

if I run this
Code: Select all
sh -x setxenv 0 l.alpha.fw_sign sisi
from cmd line, error can not open setxenv, and script does not run

if I run this
Code: Select all
strace setxenv 0 l.alpha.fw_sign sisi
from cmd line there are no errors

if I run this
Code: Select all
shell_exec("sudo su - -c \"setxenv 0 l.alpha.fw_sign sisi\"");
from inside php, error message cat broken pipe

if I run this
Code: Select all
shell_exec("sudo su - -c \"strace setxenv 0 l.alpha.fw_sign sisi\"");
from inside php, no error messages

modifying the shebag is a good idea, I'll give that a go tonight, it may give me some clues about what is going on
although, I think I've realized or come to accept that, /bin/setxenv.sh can not be modified
it exist under official firmware and gets run from official firmware, via the homebrew kit, executing that php script
so if there are any edits that are possible, it will have to be in the php script

edit: oh and with the php, I've tried exec, shell_exec, passthru, system - all with same result
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
PM's are for private matters. Post support questions to the appropriate forum, or they will be ignored.
User avatar
KAD
Global Moderator
 
Posts: 5103
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: named pipes, read nand on hub   

Postby mad_ady » Wed Oct 29, 2014 11:12 pm

If you can't modify the original, you can always make a copy, edit the copy and execute the copy instead :D
User avatar
mad_ady
Developer
 
Posts: 4553
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: named pipes, read nand on hub   

Postby KAD » Fri Nov 07, 2014 11:26 am

just an update

the WD Hub project appears to be shelved for the moment

while I needed to resolve the php issue, I also had a few other issues to work through

one was to confirm that the WD will read the value's that we write to NAND at boot time, and unfortunately that is not happening
it seems that even though the scripts exist to read and write from nand

there is something else controlling the variable we need, and search as I will, I have not been able to find it

what I do know is that something exports the value FW_SIGN=okok at boot time
but it's not found in nand or in sysconfig

this does not happen on SMP, on SMP the WD does not export the FW_SIGN at all during boot, it simply reads the value from nand, and then moves on accordingly
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
PM's are for private matters. Post support questions to the appropriate forum, or they will be ignored.
User avatar
KAD
Global Moderator
 
Posts: 5103
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Previous

Return to WDTV Live

Who is online

Users browsing this forum: No registered users and 1 guest

cron