BabbageRedbootToUboot
Revision 1 as of 2009-12-02 16:00:20
Clear message
Launchpad Entry: mobile-lucid-imx51-debian-cd-to-uboot
Created: 2009-12-02
Contributors: OliverGrawert
Packages affected: uboot-imx
Rationale
Scope
Implementation
Proof of concept script
log() { echo "$*" >&2 } hex2dec() { printf "%d\n" "$1" } IMAGE=$1 BOOT_SIZE="$((16 * 1024 * 1024))" # create MBR log "initializing disk label (MBR and partition table)..." parted -s "$IMAGE" mklabel msdos # create uboot partition log "creating uboot partition..." UBOOT_SIZE=$(wc -c uboot-imx51_to2.bin|cut -d ' ' -f1) parted -s "$IMAGE" mkpart primary fat32 "512B" "$(($UBOOT_SIZE - 1))B" # make partition1 be "Non-FS data" PART1_ID_OFFSET="$(hex2dec 0x1c2)" printf '\xda' | dd conv=notrunc bs="$PART1_ID_OFFSET" of="$IMAGE" seek=1 2>/dev/null # outputs actual partition start offset, end offset, and length, suffixed with # B get_part_data() { local n="$1" LANG=C parted -s "$IMAGE" unit B print | awk "/^ $n / { print \$2 \" \" \$3 \" \" \$4 }" # safer version using parted -m; needs newer parted #LANG=C parted -m -s "$IMAGE" unit B print | grep "^$n:" | cut -d: -f 2,3,4 --output-delimiter=" " } PART1_END_B="`(set -- $(get_part_data 1); echo "$2")`" # dump uboot in place log "writing uboot to disk..." dd conv=notrunc bs=1024 if=uboot-imx51_to2.bin of="$IMAGE" seek=1 skip=1 # create /boot parted -s "$IMAGE" mkpart primary fat32 "$((${PART1_END_B%B} + 1))B" "${BOOT_SIZE}B" PART2_START_B="`(set -- $(get_part_data 2); echo "$1")`" dd if=/dev/zero of=./boot.img bs=1024 count=$(($BOOT_SIZE / 1024)) mkdosfs ./boot.img # copy kernel and initramfs in place here mcopy -i ./boot.img /boot/vmlinuz-2.6.31-14-generic-pae ::vmlinuz dd conv=notrunc bs=${PART2_START_B%B} if=./boot.img of="$IMAGE" seek=1 rm ./boot.img