initramfs-add-dsdt.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # Adds a DSDT file to the initrd (if it's an initramfs)
  3. # first argument is the name of archive
  4. # second argument is the name of the file to add
  5. # The file will be copied as /DSDT.aml
  6. # 20060126: fix "Premature end of file" with some old cpio (Roland Robic)
  7. # 20060205: this time it should really work
  8. # check the arguments
  9. if [ $# -ne 2 ]; then
  10. program_name=$(basename $0)
  11. echo "\
  12. $program_name: too few arguments
  13. Usage: $program_name initrd-name.img DSDT-to-add.aml
  14. Adds a DSDT file to an initrd (in initramfs format)
  15. initrd-name.img: filename of the initrd in initramfs format
  16. DSDT-to-add.aml: filename of the DSDT file to add
  17. " 1>&2
  18. exit 1
  19. fi
  20. # we should check it's an initramfs
  21. tempcpio=$(mktemp -d)
  22. # cleanup on exit, hangup, interrupt, quit, termination
  23. trap 'rm -rf $tempcpio' 0 1 2 3 15
  24. # extract the archive
  25. gunzip -c "$1" > "$tempcpio"/initramfs.cpio || exit 1
  26. # copy the DSDT file at the root of the directory so that we can call it "/DSDT.aml"
  27. cp -f "$2" "$tempcpio"/DSDT.aml
  28. # add the file
  29. cd "$tempcpio"
  30. (echo DSDT.aml | cpio --quiet -H newc -o -A -O "$tempcpio"/initramfs.cpio) || exit 1
  31. cd "$OLDPWD"
  32. # re-compress the archive
  33. gzip -c "$tempcpio"/initramfs.cpio > "$1"