Add to intrd or Custom initrd

Discussion in 'General Linux' started by professor_jonny, Aug 16, 2013.

  1. professor_jonny

    professor_jonny New Member

    Messages:
    2
    Likes Received:
    2
    Trophy Points:
    3
    Hi there I have an initial ram disk and im wondering how to add to it.
    I have worked out my releace of busybox is compiled without some of the required items needed in my script such as the command stat and the image is missing some things i want to add in like xboxdrv and some dependancys like libusb.
    I'm using the inital ram disk from a dsl image that is loosly based on debian I believe for a utilities disk for the xbox but the problem is I can't add packages as I dont know how to add them in as i can not compile them as it is missing a compiler and its dependancys and the typical sudo apt get install way of things.
    How would I go about installing extra things into my image I'm guessing i need to make a custom image but how do i go about this as there is no command mkinitrd also in dsl?
    My task is to eventually make a script to init the xbox from a custom linuxrc then read a second stage user modifiable script off a fatx partition which I have read write access to so one could modify things without tools to open up the image.
    The script is designed flash multiple flash bios files to the xbox selectable via emulated keyboard presses using the xbox gampad/joystick driver it will dump bioses from the xbox check file sizes compair and flash to ensure no bad flashes and provide a log file for the user incase something goes wrong.
    Eventually I will extend it futher to format partitions and write the operating system files on.
    The game controller also can be customised as it will read the config file off the fatx partition and you basically have the option to do any thing you want or extend it with out opening up the initrd as the flash script and game controller config file is loaded from outside the initrd.
    Here is what I have in my script's so far but it fails because of the missing things
    So far it sets up the xbox special hardware and i2c drivers then mounts the fatx file system and loads the second stage script off the fatx partition.
    I have tested the flash scripts sequences and logic and all work except for the game controller/keyboard driver and file size check's using the stat command.
    If i could add in those two things I'd be happy.
    linuxrc script in root of package

    Code:
    #!/bin/bash
    # linuxrc startup script inital script to setup flash enviroment and 
    # handle control over to second stage
    #-----------------------------------------------------------------------------
    # (c) Copyright 2002  Edgar Hucek <hostmaster@ed-soft.at>
    #  All Rights Reserved.
    #
    #  http://xbox-linux.sourceforge.net
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation; either version
    #  2 of the License, or (at your option) any later version.
    #
    #  Neither Edgar Hucek nor xbox-linux admit liability nor provide
    #  warranty for any of this software. This material is provided
    #  "AS-IS" and at no charge.
    #
    #  (c) Copyright 2002  Edgar Hucek <hostmaster@ed-soft.at>
    #-----------------------------------------------------------------------------
    #  Modified by professor_jonny
    #  Dont email me I'm too busy :-)
    # 
    # 
    #-----------------------------------------------------------------------------
    
    # Output boot sequence to console
    /bin/dmesg -n 1
    # done
    
    # Setup path
    PATH=/bin:/sbin
    export PATH
    # done
    # Setup user read write access
    umask 022
    #done
    # Mount kernel and terminal 
    mount -t proc none /proc
    mount -t devpts none /dev/pts
    echo 0x100 > /proc/sys/kernel/real-root-dev
    #done
    # Make folders for mountpoints
    mkdir -p /cdrom /ram /proc /mnt/xbox
    # done
    # Setup constants for paths to make easy changes in future
    XBOXMOUNTPATH=/mnt/xbox
    MASTERHDDEPARTITION=/dev/discs/disc0/part50
    FLASHAPPPATH=/mnt/xbox/apps/flash
    # done
    # Loading i2c modules for the XBox DVD-Rom for control of dvd from yellow cable
    insmod i2c-core
    insmod i2c-xbox
    insmod i2c-proc
    insmod i2c-dev
    # done
    # load in fat and fatx kernel modules
    insmod fat
    insmod fatx
    # done
    # Mount $MASTERHDDEPARTITION at $XBOXMOUNTPATH
    mount -t fatx -o rw $MASTERHDDEPARTITION $XBOXMOUNTPATH
    # done
    # Now fatxfile system is loaded and mounted setup xboxdrv xbox game controller driver and
    # load config from from $XBOXMOUNTPATH/$FLASHAPPPATH
    sudo xboxdrv --silent --config $FLASHAPPPATH/game.cfg 
    # done
    # Force loading 2nd stage flash script from $XBOXMOUNTPATH/$FLASHAPPPATH/ 
    # ignoring execute bit as we cant set it on a fatx partition
    /bin/bash $FLASHAPPPATH/Flash.sh
    # done
    
    # end
    Flash script stored of fatx


    Code:
    #!/bin/bash
    # second stage flash script to do the actual flashing and log file
    # flash.sh setup file stored on xbox  @ $XBOXMOUNTPATH
    #-----------------------------------------------------
    # 
    #
    #
    # (c) Copyright 2013  Professor_jonny 
    #  All Rights Reserved.
    #
    #  http://www.xbmc4xbox.org.uk
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation.
    #
    #  This material is provided AS-IS" and at no charge if it
    #  makes your toaster catch fire dont blame me.
    #
    #  (c) Copyright 2013  
    #-----------------------------------------------------
    #
    #
    # Setup constants for paths to make easy changes in future
    RELEASETITLE="MECHASSAULT RAINCOAT FLASH DISK MODDED BY PROFESSOR_JONNY"
    XBOXMOUNTPATH=/mnt/xbox
    FLASHAPPPATH=/mnt/xbox/apps/flash
    # Setup constants for logic to make code more readable
    FLASHED=0
    DONE=1
    ZEROCOND=0
    DATE=`date`
    
    LOGFILE=flash.log
    ORGBIOSFILE=original_bios.bin
    FLASHFILE0=256.bin
    FLASHFILE1=512.bin
    FLASHFILE2=1024.bin
    FLASHFILESIZE0=262144
    FLASHFILESIZE0=524288
    FLASHFILESIZE0=1048576
    FILESIZE0=1
    FILESIZE1=1
    FILESIZE2=1
    # Check file sizes of flash files for peace of mind and ouput to screen.
    # This could be extended to halt the xbox but ill give the user the ability
    # to decide this.
    echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    echo
    echo "  $RELEASETITLE"
    echo "  ======================================================="
    echo "  flash file size check procedure."
    echo
    cd $FLASHAPPPATH
    X=1
    while [[ $x -le 3 ]] 
    do
      FILENAME=$FLASHAPPPATH/$FLASHFILE$X
      FILESIZE=$(stat -c %s $FILENAME)
     
      echo "Size of $FILENAME = $FILESIZE bytes."
     
      if [[$x -eq 0]]
      then
      [[FILESIZE = $FILESIZE0]]
      fi
      if [[$x -eq 1]]
      then
      [[[FILESIZE = $FILESIZE1]] 
     fi
      if [[$x -eq 2]]
      then
      [[FILESIZE = $FILESIZE2]]
      fi
      x=$(($x+1))
    done
    #done
    echo "-[ $RELEASETITLE started: $DATE ]-----" >>$LOGFILE
    echo " " >>$LOGFILE
    if $FILESIZE0=$FLASHFILESIZE0
    then
      echo "  $FLASHFILE0 is correct" >>$LOGFILE
    else
      echo "  $FLASHFILE0 is incorrect" >>$LOGFILE
    fi
    if $FILESIZE1=$FLASHFILESIZE1
    then
      echo "  $FLASHFILE1 is correct" >>$LOGFILE
    else
      echo "  $FLASHFILE1 is incorrect" >>$LOGFILE
    fi
    if $FILESIZE2=$FLASHFILESIZE2
    then
      echo "  $FLASHFILE2 is correct" >>$LOGFILE
    else
      echo "  $FLASHFILE2 is incorrect" >>$LOGFILE
    fi
    
    sleep 50
    # Nice screen art
    echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    echo
    echo "  $RELEASETITLE based on raincoat 0.5"
    echo "  ======================================================="
    echo
    echo "  Modified release by Professor_jonny."
    echo
    echo "  Check http://www.xbmc4xbox.org.uk for news and updates."
    echo 
    echo "  Press A to flash 256k bios"
    echo  
    echo "  Press X to flash 512k bios"
    echo  
    echo "  Press Y to flash 1024k bios"
    echo  
    echo "  Press B to shutdown with out flash or wait"
    echo  
    echo "  !!!!WARNING!!!!!"
    echo "  SELECT THE CORRECT ONE AND BE SURE THE BIOS IS THE CORRECT SIZE IN THE XBOX APP DIR"
    echo  
    echo "  --------------------------------------"
    echo
    # If no key is pressed with in 10 seconds shutdown console (in a nice way)
    if read -n 1 -t 10 RESPONCE;
    then
      echo "Great, you made it in time!"
      wait 5
    else
      echo "Sorry, you are too slow in selecting an option and I will now shutdown!"
      wait 5
      sleep 50
      halt -n -f -p
    fi
    #-----------------------------------------------------
    # user selected X Flash 256k bios
    if $responce -eq X 
    then
      # Flash procedure script
      cd $FLASHAPPPATH
      /bin/test -e $XBOXMOUNTPATH/$ORGBIOSFILE
      FILEEXIST=$?
      if /bin/test $FILEEXIST -ne $ZEROCOND
      then
      /bin/raincoat -r $XBOXMOUNTPATH/$ORGBIOSFILE -v >>$LOGFILE
      echo " " >>$LOGFILE
      echo "  Saved original bios..."
      fi
      /bin/raincoat -p $FLASHFILE0 -v >>$LOGFILE
      FLASHRTN=$?
      if /bin/test $FLASHRTN -eq $ZEROCOND
      then
      echo " " >>$LOGFILE
      echo "  Flashed ok..."
      echo "  Power off..."
      cd /
      sleep 15
      halt -n -f -p
      else 
      echo " " >>$LOGFILE
      echo "  Flashing failed, check $LOGFILE for result..."
      echo "  DVD tray eject..."
      cd /
      sleep 15
      eject.xbox.real
      while :
      do
      sleep 5
      done
      fi
    fi
    #-----------------------------------------------------
    # user selected X Flash 512k bios
    if $responce -eq X
    then
      # Flash procedure script
      cd $FLASHAPPPATH
      /bin/test -e $XBOXMOUNTPATH/$ORGBIOSFILE
      FILEEXIST=$?
      if /bin/test $FILEEXIST -ne $ZEROCOND
      then
      /bin/raincoat -r $XBOXMOUNTPATH/$ORGBIOSFILE -v >>$LOGFILE
      echo " " >>$LOGFILE
      echo "  Saved original bios..."
      fi
      /bin/raincoat -p $FLASHFILE1 -v >>$LOGFILE
      FLASHRTN=$?
      if /bin/test $FLASHRTN -eq $ZEROCOND
      then
      echo " " >>$LOGFILE
      echo "  Flashed ok..."
      echo "  Power off..."
      cd /
      umount $XBOXMOUNTPATH
      sleep 15
      halt -n -f -p
      else 
      echo " " >>$LOGFILE
      echo "  Flashing failed, check $LOGFILE for result..."
      echo "  DVD tray eject..."
      cd /
      sleep 15
      eject.xbox.real
      while :
      do
      sleep 5
      done
      fi
    fi
    
    #-----------------------------------------------------
    # user selected Y Flash 1024k bios
    if $responce -eq Y
    then
      # Flash procedure script
      cd $FLASHAPPPATH
      /bin/test -e $XBOXMOUNTPATH/$ORGBIOSFILE
      FILEEXIST=$?
      if /bin/test $FILEEXIST -ne $ZEROCOND
      then
      /bin/raincoat -r $XBOXMOUNTPATH/$ORGBIOSFILE -v >>$LOGFILE
      echo " " >>$LOGFILE
      echo "  Saved original bios..."
      fi
      /bin/raincoat -p $FLASHFILE2 -v >>$LOGFILE
      FLASHRTN=$?
      if /bin/test $FLASHRTN -eq $ZEROCOND
      then
      echo " " >>$LOGFILE
      echo "  Flashed ok..."
      echo "  Power off..."
      cd /
      sleep 15
      halt -n -f -p
      else 
      echo " " >>$LOGFILE
      echo "  Flashing failed, check $LOGFILE for result..."
      echo "  DVD tray eject..."
      cd /
      sleep 15
      eject.xbox.real
      while :
      do
      sleep 5
      done
      fi
    fi
    
    #-----------------------------------------------------
    # dont flash user selected shutdown
    if $responce -eq B 
    then
      echo "  Flashing failed, user selected shutdown" >>$LOGFILE
      echo "  Flashing failed, check $LOGFILE for result..."
      sleep 15
      halt -n -f -p
    fi
    # end
    game.cfg stored on fatx

    Code:
    #!/bin/bash
    #-----------------------------------------------------
    # game.cfg xboxdrv keyboard setup file stored on xbox  @ $XBOXMOUNTPATH
    #
    #
    # (c) Copyright 2013  Professor_jonny 
    #  All Rights Reserved.
    #
    #  http://www.xbmc4xbox.org.uk
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation.
    #
    #  This material is provided AS-IS" and at no charge if it
    #  makes your toaster catch fire dont blame me.
    #
    #  (c) Copyright 2013  
    #-----------------------------------------------------
    #
    #
    #  A is keyboard key A
    #  B is keyboard key B
    #  X is keyboard key X
    #  Y is keyboard key Y
    [xboxdrv]
    ui-clear=true
    trigger-as-button = true
    silent = true
    [ui-buttonmap]
    a = KEY_A
    b = KEY_B
    x = KEY_X
    y = KEY_Y
    # EOF #
    ryanvade and DevynCJohnson like this.
  2. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,216
    Likes Received:
    407
    Trophy Points:
    83
  3. professor_jonny

    professor_jonny New Member

    Messages:
    2
    Likes Received:
    2
    Trophy Points:
    3
    Thanks that worked a trick I have managed to get it to boot with the new image after beefing up the ramdisk size in linuxboot.cfg .
    I kept on getting attempt to access beyond end of device as my image is bigger than 4mb and threw me for a while as i thaught the image was corrupt or I had set the wrong block size when creating the image.

    Now I'm at the point where I need to put on extralinux commands updated full build of busybox.

    As with the xbox as there is no patches for newer kernels will there be any problems dropping on a new pre compiled binary?

    how would i replace busybox in an online image im guessing i use exec ?
  4. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,216
    Likes Received:
    407
    Trophy Points:
    83

Share This Page