title: create bootable sdcard for embedded board which will ultimately run android
body: <p>Context: </p>
  
  <p>I designed an embedded system and I ported Android Gingerbread to run on it. I use an ARM Cortex-A8 based CPU module that has the CPU, SDRAM, NANDFLASH on it and all the rest available on module pins so I can add my own hardware interfaces. The first one came with u-boot pre-installed. All I had to do to install my Gingerbread was to place the 4 images (kernel.img, system.img, ramdisk-yaffs.img and userdata.img) in a directory (/sdfuse) on the SD-CARD and just burn it to the on-board NANDFLASH using command "sdfuse flash kernel kernel.img" and the equivalent commands for the other 3 files. Simple enough. After that, I use the SDCARD in Android as an external storage. (Life was good!)</p>
  
  <p>The Problem:</p>
  
  <p>Now I bought more modules and they did not come with u-boot pre-loaded. So, I need to make a bootable SDcard with u-boot on it. It needs to be FAT in order to be recognized by my processor at boot time. I actually have a SDHC 4GB card in FAT32, successfully installed U-boot and it boots my system up to the u-boot prompt telling me it can't find the 4 image files. It's expected since the images are not there yet. The problem is now I can't create the /sdfuse folder and put the 4 image files on it. Neither my MACBook nor my Ubuntu machine let me mount that SDcard anymore to create the "/sdfuse" folder on it. Both diskmanagers see the SD-Card but neither allow to mount it. Obviously, I missed something somewhere. What I have now is a bootable 4GB FAT32 SD-Card with U-boot on it but the rest of the card is not usable anymore. Anybody knows what the problem could be? Why can't I use this 4GB bootable FAT32 partition to install my "/sdfuse" folder with the images? I used a Ubuntu machine to create the bootable SD-Card so, the USB/SD-Card reader is working well, in other words, the problem is not hatdware but some software configurations of some sort.</p>
  
  <p>EDIT following Chris Stratton comment about file system:
  I have an SD Card containing the "/sdfuse" with the 4 image files (kernel.img etc) and a bunch of other file and folders. With Ubuntu Diskutility, I can see it as one partition W95 FAT32 (LBA) (0x0c) Master Boot Record. I can read/write just about anything on it from Ubuntu and MacOSX. The second SD-Card that I made is also seen has one FAT32 partition Master Boot Record, type W95 FAT32 (LBA) (0X0c) but I can't mount it neither from Ubuntu (but seen under /dev/sdb) nor MacOSX. That last one, is the one with u-boot on it. Just strange!  Just to work around the problem, I just had an idea so I can keep working, I just tried to boot with the "u-boot SD-Card" then, I changed the SD-Card "live" for the one with the 4 files. I used the command "sdfuse" to flash u-boot, kernel, android etc to my NANDFLASH device. Then, when I force a reboot from NAND, it boots into Android. It is OK for development but this is way too complicated for a production procedure.  Chris Stratton is probably right when he points to a filesystem partition or structure. I just did not figure it out yet. Anybody has some clues?</p>
  
  <p>After running from Ubuntu Terminal "dmesg | tail", I get the following results:</p>
  
  <pre><code> dmesg | tail
  [5871490.553791] sd 16:0:0:0: [sdb] 7829504 512-byte logical blocks: (4.00 GB/3.73 GiB)
  [5871490.556190] sd 16:0:0:0: [sdb] Write Protect is off
  [5871490.556197] sd 16:0:0:0: [sdb] Mode Sense: 03 00 00 00
  [5871490.556201] sd 16:0:0:0: [sdb] Assuming drive cache: write through
  [5871490.559054] sd 16:0:0:0: [sdb] Assuming drive cache: write through
  [5871490.559064]  sdb: sdb1
  [5871490.563912] sd 16:0:0:0: [sdb] Assuming drive cache: write through
  [5871490.563920] sd 16:0:0:0: [sdb] Attached SCSI removable disk
  [5872079.044194] FAT: bogus number of reserved sectors
  [5872079.044201] VFS: Can't find a valid FAT filesystem on dev sdb1.
  </code></pre>
  
  <p>So, it appears there is something wrong with the format even though the card boots and is seen has a W95 FAT32 (LBA)(0x0c) </p>
  
  <p>EDIT following the Comment from  <a href="https://stackoverflow.com/users/319204/thecodeartist">TheCodeArtist</a></p>
  
  <p>Here is how I create a "u-boot" bootable image disk. I run a script (on my Ubuntu machine) that was created by Samsung. Here is what is inside the script:</p>
  
  <pre><code>#
  # Copyright (C) 2010 Samsung Electronics Co., Ltd.
  #              http://www.samsung.com/
  # 
  # This program is free software; you can redistribute it and/or modify
  # it under the terms of the GNU General Public License version 2 as
  # published by the Free Software Foundation.
  #
  ####################################
  reader_type1="/dev/sdb"
  reader_type2="/dev/mmcblk0"
  
  if [ -z $1 ]
  then
      echo "usage: ./sd_fusing.sh &lt;SD Reader's device file&gt;"
      exit 0
  fi
  
  if [ $1 = $reader_type1 ]
  then 
      partition1="$11"
      partition2="$12"
      partition3="$13"
      partition4="$14"
  
  elif [ $1 = $reader_type2 ]
  then 
      partition1="$1p1"
      partition2="$1p2"
      partition3="$1p3"
      partition4="$1p4"
  
  else
      echo "Unsupported SD reader"
      exit 0
  fi
  
  if [ -b $1 ]
  then
      echo "$1 reader is identified."
  else
      echo "$1 is NOT identified."
      exit 0
  fi
  
  ####################################
  # make partition
  echo "make sd card partition"
  echo "./sd_fdisk $1" 
  ./sd_fdisk $1 
  dd iflag=dsync oflag=dsync if=sd_mbr.dat of=$1 
  rm sd_mbr.dat
  
  ####################################
  # format
  umount $partition1 2&gt; /dev/null
  umount $partition2 2&gt; /dev/null
  umount $partition3 2&gt; /dev/null
  umount $partition4 2&gt; /dev/null
  
  echo "mkfs.vfat -F 32 $partition1"
  mkfs.vfat -F 32 $partition1
  
  #echo "mkfs.ext2 $partition2"
  #mkfs.ext2 $partition2  
  
  #echo "mkfs.ext2 $partition3"
  #mkfs.ext2 $partition3  
  
  #echo "mkfs.ext2 $partition4"
  #mkfs.ext2 $partition4  
  
  ####################################
  # mount 
  #umount /media/sd 2&gt; /dev/null
  #mkdir -p /media/sd
  #echo "mount -t vfat $partition1 /media/sd"
  #mount -t vfat $partition1 /media/sd
  
  ####################################
  #&lt;BL1 fusing&gt;
  bl1_position=1
  uboot_position=49
  
  echo "BL1 fusing"
  ./mkbl1 ../u-boot.bin SD-bl1-8k.bin 8192
  dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=$1 seek=$bl1_position
  rm SD-bl1-8k.bin
  
  ####################################
  #&lt;u-boot fusing&gt;
  echo "u-boot fusing"
  dd iflag=dsync oflag=dsync if=../u-boot.bin of=$1 seek=$uboot_position
  
  ####################################
  #&lt;Message Display&gt;
  echo "U-boot image is fused successfully."
  echo "Eject SD card and insert it again."
  </code></pre>
  
  <p>Also, you can see there is a call to a function "sd_fdisk".   I have the source code but it is also on Google code: <a href="https://code.google.com/p/x210ii/source/browse/uboot/sd_fusing/sd_fdisk.c?r=e21cf135fa176ca05e92135b339d060a1af84eb6" rel="nofollow noreferrer">sd_fdisk.c</a></p>