Wednesday, November 4, 2015

Boot Intel Edison from SD card (With Debian or Ubilinux)

This tutorial describes a way to boot an Edison board with the Root Filesystem on an external storage (SD card or USB stick). The kernel and bootloader remain on the local eMMC. For now, we are not able to boot a kernel from an external storage.

Before following any of these steps, make sure you have booted ubilinux or debian os (from Emutexlabs) on Intel Edison.


1. Prepare External Storage (MicroSD Card)

 

  • You need to have a SD card formatted with ext4 file system to store the root file system
  • On your desktop computer with Linux installed, using GParted, format your SD card using ext4 file-system. Eject the SD Card and insert it back



  • Download and unpack Debian image from emutexlabs website. In the unpacked directory (with the "flashall.sh" script) run the following commands to prepare the SD card. These commands mount the edison-image-edison.ext4 rootfs image and copy the contents onto the SD card (be sure to be root to do that)


     
  • In the unpacked directory,
sudo su
mkdir Rootfs
mount ./edison-image-edison.ext4 Rootfs
cp -a Rootfs/* /media/saru/eb361b92-c285-44a6-9f32-da393c879487
sync

  • Now, eject the SD Card and ready to boot


2. Find out the SD card device name 

 

On a running Edison board, plug your formatted SD card and get the device name. 
  • Run the below command, 
dmesg | tail -n 10

Here, the SD card device is “/dev/mmcblk1” and the partition we’ve created is "/dev/mmcblk1p1"

 

3. Boot the board using SD card



Debian system on Edison, does not mount the microsd card automatically. To mount sdcard at boot, modify the /etc/fstab system file in edison.
  • Find the UUID for the sd card 
blkid 

  • add an entry for the partition to automount it at startup. Add file system, mount point, type, options, dump and pass information of sdcard partition to fstab file and save it. Example, the format looks like below,
           /dev/sdcX      /media/sdcard    ext4    defaults    0     0
nano /etc/fstab
#Add an entry for the partition
UUID=eb361b92-c285-44a6-9f32-da393c879487    /media/sdcard    ext4    defaults    0 0

mkdir -p /media/sdcard/
reboot
 After reboot, debian os automatically mounts the sdcard.


To boot using the external device, you need to modify the U-Boot environment variable named "mmc-bootargs" with kernel boot arguments. We cannot modify U-Boot environment variables from edison linux console in debian os. It is possible only in U-Boot command prompt.


Note:    
To modify U-Boot env variables, u-boot and u-boot-tools packages are available in debian repository. The tools fw_printenv/fw_setenv in the u-boot source tree normally work with MTD partitions but they don’t support MMC.


To modify u-boot env variables ,during the boot, on the serial console, when it prompts to press a key to stop booting, press any key and then run the following commands in the U-Boot command prompt.

> setenv mmc-bootargs 'setenv bootargs root=${myrootfs} rootdelay=3 rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}'

> setenv myrootfs '/dev/mmcblk1p1'

> setenv myrootfs_sdcard /dev/mmcblk1p1

> setenv myrootfs_emmc PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4

> setenv do_boot_emmc 'setenv myrootfs ${myrootfs_emmc}; run do_boot'

> setenv do_boot_sdcard 'setenv myrootfs ${myrootfs_sdcard}; run do_boot'

> setenv bootdelay 5

> saveenv

> run do_boot_sdcard



After boot, verify that you are using rootfs stored on your external device.


Note: 
If you want to switch to eMMC just occasionally, during the boot, on the serial console, when it prompts to press a key to stop booting, press any key and then run the below command in the U-Boot command prompt that appears:
> run do_boot_emmc

25 comments:

  1. Great post, very helpful... Thanks! Useful in more ways than one... i've been searching for ways to backup/restore ubilinux edison images after they've been customized with all kinds of additional software and it's impossible to (a) install a lot of additional software without running out of space on the rootfs, esp in the /usr/lib, /usr/share dirs and (b) reliably do backup or restore of the final image if it's installed to emmc.

    ReplyDelete
  2. Ike - did you figure out how to backup/restore all of ubilinux after customization? It'd be good to know your explicit steps. Thanks.

    ReplyDelete
  3. Hi Sarweshkumar, thanks for your guide! I have tried out the steps and able to boot from SDcard. Just wondering if the Intel Edison should boot from SDcard by default when I run "reboot" or startup the board?

    As I am able to boot from SDcard by stopping the booting (when reboot is run), and typing "run do_boot_sdcard" in the U-boot command prompt. However, when I just run "reboot", my Intel Edison seems to get struck in a loop and is unable to boot. It gets struck in the following loop.

    Starting kernel ...

    [ 0.748114] pca953x 1-0020: failed reading register
    [ 0.753265] pca953x 1-0021: failed reading register
    [ 1.645846] pmic_ccsm pmic_ccsm: Error reading battery profile from battid frmwrk
    [ 1.654736] pmic_ccsm pmic_ccsm: Battery Over heat exception
    [ 1.654823] pmic_ccsm pmic_ccsm: Battery0 temperature inside boundary

    Please advise if this is the expected behaviour? Or should my Intel Edison boot from SDcard directly without running "run do_boot_sdcard" on the U-boot command prompt?

    Cheers!
    Greyshades

    ReplyDelete
  4. Hi Greyshades,
    Thanks for your feedback.

    Forgot to add two more commands in U-Boot command prompt. Now I've updated the instructions, please check once.

    If you are configuring the Edison for the first time to boot from sdcard, you should execute 'run do_boot_sdcard' (shown above)

    Everytime you don't have to interrupt the boot sequence and type 'run do_boot_sdcard'. Just a normal reboot command is fine.

    If you want to switch to eMMC just occasionally, execute run 'do_boot_emmc'.

    Known Issue:
    * Sometimes, it may throw you this error 'mmc1: error -110 whilst initialising SD card'

    Workaround:
    * Pressing the hardware RESET or SW1UI5 button will fix the issue and this one has been tested.

    Please let me know whether the problem persists or not.

    ReplyDelete
    Replies
    1. Dear Sarweshkumar,

      Thanks for your help!

      Yes, it works now! And I am able to reboot without the previous issue.

      Just to check, the 2 lines you added to U-Boot command prompt are those in blue?

      Best Regards!
      Greyshades

      Delete
    2. Hi Greyshades,

      I think, I added 2nd line and the 7th line.

      Delete
  5. hello!

    i am new to this iot , i have bought an edison. i want to know is it really necessary for me to insert the sdcard when unzipping the latest image because it shows not enough space in edison. and if it is necessary for me to use the sd card , can i use any normal sd card and also is it necessary to use the 4gb sd card only ????????

    please help me out with this!!!

    ReplyDelete
  6. Hello Mr. Rayan,

    Sorry for not replying sooner. If the default space on edison is not enough, you can use sdcard and it can be upto 32GB.

    ReplyDelete
  7. In step 1 in the unpacked directory, you have this line.

    cp -a Rootfs/* /media/saru/eb361b92-c285-44a6-9f32-da393c879487
    sync

    This appears to be incorrect or missing a step. I think you should define this file /media/saru... first. Perhaps this is done by mounting the SD card to some file like this using UUID to this? As it is this doesn't work.

    ReplyDelete
    Replies
    1. Hi Earle,
      Sorry for my late reply. When you insert an sdcard, Ubuntu machine automatically mounts the sdcard in media directory(I have observed this behaviour in Ubuntu 14.04 and above, not sure about other Linux distributions.)
      "/media/saru/eb361b92-c285-44a6-9f32-da393c879487" - This line represents the path of mounted directory. 'saru' is my ubuntu machine's username.

      Delete
  8. hello sarweshkumar,

    Thanks for this wonderful guide. I am finding trouble in finding the name of the device with dmesg command and also blkid is not working. please help me to come over the trouble..

    ReplyDelete
    Replies
    1. Hi,
      It looks like sdcard issue. Make sure your sdcard is proper and partitions are correct. Let me know if you need anything else

      Delete
  9. Starting kernel ...

    [ 0.760942] pca953x 1-0020: failed reading register
    [ 0.761354] pca953x 1-0021: failed reading register
    [ 0.771257] pca953x 1-0022: failed reading register
    [ 0.776348] pca953x 1-0023: failed reading register
    [ 1.659643] pmic_ccsm pmic_ccsm: Error reading battery profile from battid frmwrk
    [ 1.668319] pmic_ccsm pmic_ccsm: Battery Over heat exception
    [ 1.676537] pmic_ccsm pmic_ccsm: Battery0 temperature outside boundary
    I am getting struck here. what to do?????

    ReplyDelete
    Replies
    1. I'll check. Please give me sometime

      Delete
    2. Hi,

      Did you get a chance look at this problem? I'm also getting same problem. I am using class-10 32 GB SD Card.

      Delete
  10. sarwesh i did upto last step . while running from u- boot environment run do_boot_sdcard it got struck in starting kernal.
    And also if reboot its not showing sdcard, if a give halt then it showing. i dont know why its showing " Mounting local filesystems...mount: special device UUID=2cdae164-ec2f-4ebb-87cd-6698fad78847 does not exist
    failed." for halt is working properly.

    ReplyDelete
    Replies
    1. Hi Vethakrishna,

      I didn't get this statement "And also if reboot its not showing sdcard, if I give halt then it showing".

      Try to print the Boot variables once. Use 'printenv' command in U-Boot command prompt to check the values of boot variables and let me know the results

      Delete
    2. bcoz of large file size am splited into parts.sorry for inconvenience. pls refer below.
      Additionally i wanna say that, am using intel edison mini breakout board,for terminal am using putty. through otg cable am connecting micro sd card reader . i did upto last part of ur post blog.last cmd when i give that run do_bot_sdcard , console loading and stucking in starting kernal. dont know where i done mistake. :(

      Delete
  11. part1
    boot > printenv
    boot_target_cmd=run do_flash_os;run do_probe_dfu;run do_compute_target;run mmc-bootargs;run load_kernel;zboot ${loadaddr}
    bootargs_console=console=ttyMFD2 earlyprintk=ttyMFD2,keep
    bootargs_debug=loglevel=4
    bootargs_ethconfig=rndis
    bootargs_target=first-install
    bootcmd=echo "Target:${target_name}"; run do_partition; run do_handle_bootargs_mode;
    bootdelay=5
    dfu_alt_info_ram=kernel ram ${loadaddr} 0x800000
    dfu_alt_info_reset=reset ram 0x0 0x0
    dfu_to_sec=3
    do_boot=run boot_target_cmd;
    do_boot_emmc=setenv myrootfs ${myrootfs_emmc}; run do_boot
    do_boot_sdcard=setenv myrootfs ${myrootfs_sdcard}; run do_boot
    do_bootargs_rootfs=setenv bootargs_rootfs rootwait root=PARTUUID=${uuid_rootfs} rootfstype=ext4

    ReplyDelete
    Replies
    1. part2
      do_compute_target=if itest.b ${first_install_retry} -gt ${first_install_max_retries} || itest.b ${ota_update_retry} -gt ${ota_update_max_retries}; then echo "Switch to Rescue target"; setenv bootargs_target rescue; saveenv; fi
      do_dfu_alt_info_ifwi=setenv dfu_alt_info "ifwi${hardware_id} mmc 0 8192 mmcpart 1;ifwib${hardware_id} mmc 0 8192 mmcpart 2"
      do_dfu_alt_info_mmc=setenv dfu_alt_info "ifwi${hardware_id} mmc 0 8192 mmcpart 1;ifwib${hardware_id} mmc 0 8192 mmcpart 2;u-boot0 part 0 1;u-boot-env0 part 0 2;u-boot1 part 0 3;u-boot-env1 part 0 4;boot part 0 7;rootfs part 0 8;update part 0 9;home part 0 10;vmlinuz fat 0 7;initrd fat 0 7"
      do_dnx=setenv dfu_alt_info ${dfu_alt_info_ram};dfu 0 ram 0 ram;run bootcmd
      do_fallback=echo "Unknown boot mode: $bootargs_mode"; env delete -f bootargs_mode; saveenv; echo "Resetting to default boot mode and reboot..."; reset;
      do_flash=run do_force_flash_os;
      do_flash_ifwi=run do_dfu_alt_info_ifwi ; dfu 0 mmc 0
      do_flash_os=if itest.b ${do_flash_os_done} -eq 1 ; then echo "Flashing already done..." ; else run do_force_flash_os; fi
      do_flash_os_done=1
      do_flashall=run do_partition;run do_flash_ifwi;run do_flash_os
      do_force_flash_os=run do_dfu_alt_info_mmc ; sleep 1 ; setenv do_flash_os_done 1 ; saveenv ; dfu 0 mmc 0
      do_force_partition=echo "Partitioning using GPT"; gpt write mmc 0 ${partitions} ; mmc rescan; setenv do_partition_done 1 ; saveenv
      do_handle_bootargs_mode=run do_preprocess_bootargs_mode; if itest.s $bootargs_mode == "ota" ; then run do_ota; fi; if itest.s $bootargs_mode == "boot" ; then run do_boot; fi; if itest.s $bootargs_mode == "flash"; then run do_flash; fi; run do_fallback; exit;
      do_load_ota_scr=if fatload mmc 0:9 $ota_script_addr ota_update.scr ; then setenv ota_status 0 ; else setenv ota_status 1 ; fi
      do_ota=run do_ota_init ; run do_load_ota_scr ; run do_source_ota_scr ; run do_ota_clean
      do_ota_clean=saveenv ; reset
      do_ota_init=setenv ota_status 1 ; env delete -f bootargs_mode
      do_partition=if itest.b ${do_partition_done} -eq 1; then echo "Partitioning already done..."; else run do_force_partition ; fi
      do_partition_done=1
      do_preprocess_bootargs_mode=if env exists bootargs_mode ; then ; else setenv bootargs_mode "boot" ;fi;
      do_probe_dfu=run do_dfu_alt_info_mmc ; dfu 0 mmc 0 $dfu_to_sec
      do_source_ota_scr=if test $ota_status -eq 0 ; then if source $ota_script_addr ; then setenv ota_status 0 ; else setenv ota_status 2 ; fi ; fi
      first_install_max_retries=3
      first_install_retry=0
      hardware_id=00
      init_dfu=run do_dfu_alt_info_mmc ; saveenv
      load_kernel=fatload mmc 0:7 ${loadaddr} vmlinuz
      loadaddr=0x100000
      mmc-bootargs=setenv bootargs root=${myrootfs} rootdelay=3 rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}
      myrootfs=/dev/sda1
      myrootfs_emmc=PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4
      myrootfs_sdcard=/dev/sda1
      ota_script_addr=0x100000
      ota_update_max_retries=3
      ota_update_retry=0
      partitions=uuid_disk=${uuid_disk};name=u-boot0,start=1MiB,size=2MiB,uuid=${uuid_uboot0};name=u-boot-env0,size=1MiB,uuid=${uuid_uboot_env0};name=u-boot1,size=2MiB,uuid=${uuid_uboot1};name=u-boot-env1,size=1MiB,uuid=${uuid_uboot_env1};name=factory,size=1MiB,uuid=${uuid_factory};name=panic,size=24MiB,uuid=${uuid_panic};name=boot,size=32MiB,uuid=${uuid_boot};name=rootfs,size=1536MiB,uuid=${uuid_rootfs};name=update,size=768MiB,uuid=${uuid_update};name=home,size=-,uuid=${uuid_home};

      Delete
    2. part3
      serial#=92108b44bebfbfbba2838a5cbc248b58
      stderr=serial
      stdin=serial
      stdout=serial
      target_name=blank
      usb0addr=02:00:86:24:8b:58
      uuid_boot=db88503d-34a5-3e41-836d-c757cb682814
      uuid_disk=21200400-0804-0146-9dcc-a8c51255994f
      uuid_factory=333a128e-d3e3-b94d-92f4-d3ebd9b3224f
      uuid_home=f13a0978-b1b5-1a4e-8821-39438e24b627
      uuid_panic=f20aa902-1c5d-294a-9177-97a513e3cae4
      uuid_rootfs=012b3303-34ac-284d-99b4-34e03a2335f4
      uuid_uboot0=d117f98e-6f2c-d04b-a5b2-331a19f91cb2
      uuid_uboot1=8a4bb8b4-e304-ae48-8536-aff5c9c495b1
      uuid_uboot_env0=25718777-d0ad-7443-9e60-02cb591c9737
      uuid_uboot_env1=08992135-13c6-084b-9322-3391ff571e19
      uuid_update=faec2ecf-8544-e241-b19d-757e796da607

      Environment size: 4988/65531 bytes

      Delete
    3. part 2
      do_compute_target=if itest.b ${first_install_retry} -gt ${first_install_max_retries} || itest.b ${ota_update_retry} -gt ${ota_update_max_retries}; then echo "Switch to Rescue target"; setenv bootargs_target rescue; saveenv; fi
      do_dfu_alt_info_ifwi=setenv dfu_alt_info "ifwi${hardware_id} mmc 0 8192 mmcpart 1;ifwib${hardware_id} mmc 0 8192 mmcpart 2"
      do_dfu_alt_info_mmc=setenv dfu_alt_info "ifwi${hardware_id} mmc 0 8192 mmcpart 1;ifwib${hardware_id} mmc 0 8192 mmcpart 2;u-boot0 part 0 1;u-boot-env0 part 0 2;u-boot1 part 0 3;u-boot-env1 part 0 4;boot part 0 7;rootfs part 0 8;update part 0 9;home part 0 10;vmlinuz fat 0 7;initrd fat 0 7"
      do_dnx=setenv dfu_alt_info ${dfu_alt_info_ram};dfu 0 ram 0 ram;run bootcmd
      do_fallback=echo "Unknown boot mode: $bootargs_mode"; env delete -f bootargs_mode; saveenv; echo "Resetting to default boot mode and reboot..."; reset;
      do_flash=run do_force_flash_os;
      do_flash_ifwi=run do_dfu_alt_info_ifwi ; dfu 0 mmc 0
      do_flash_os=if itest.b ${do_flash_os_done} -eq 1 ; then echo "Flashing already done..." ; else run do_force_flash_os; fi
      do_flash_os_done=1
      do_flashall=run do_partition;run do_flash_ifwi;run do_flash_os
      do_force_flash_os=run do_dfu_alt_info_mmc ; sleep 1 ; setenv do_flash_os_done 1 ; saveenv ; dfu 0 mmc 0
      do_force_partition=echo "Partitioning using GPT"; gpt write mmc 0 ${partitions} ; mmc rescan; setenv do_partition_done 1 ; saveenv
      do_handle_bootargs_mode=run do_preprocess_bootargs_mode; if itest.s $bootargs_mode == "ota" ; then run do_ota; fi; if itest.s $bootargs_mode == "boot" ; then run do_boot; fi; if itest.s $bootargs_mode == "flash"; then run do_flash; fi; run do_fallback; exit;
      do_load_ota_scr=if fatload mmc 0:9 $ota_script_addr ota_update.scr ; then setenv ota_status 0 ; else setenv ota_status 1 ; fi
      do_ota=run do_ota_init ; run do_load_ota_scr ; run do_source_ota_scr ; run do_ota_clean
      do_ota_clean=saveenv ; reset
      do_ota_init=setenv ota_status 1 ; env delete -f bootargs_mode
      do_partition=if itest.b ${do_partition_done} -eq 1; then echo "Partitioning already done..."; else run do_force_partition ; fi
      do_partition_done=1
      do_preprocess_bootargs_mode=if env exists bootargs_mode ; then ; else setenv bootargs_mode "boot" ;fi;
      do_probe_dfu=run do_dfu_alt_info_mmc ; dfu 0 mmc 0 $dfu_to_sec
      do_source_ota_scr=if test $ota_status -eq 0 ; then if source $ota_script_addr ; then setenv ota_status 0 ; else setenv ota_status 2 ; fi ; fi
      first_install_max_retries=3
      first_install_retry=0
      hardware_id=00
      init_dfu=run do_dfu_alt_info_mmc ; saveenv
      load_kernel=fatload mmc 0:7 ${loadaddr} vmlinuz
      loadaddr=0x100000
      mmc-bootargs=setenv bootargs root=${myrootfs} rootdelay=3 rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}
      myrootfs=/dev/sda1
      myrootfs_emmc=PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4
      myrootfs_sdcard=/dev/sda1
      ota_script_addr=0x100000
      ota_update_max_retries=3
      ota_update_retry=0
      partitions=uuid_disk=${uuid_disk};name=u-boot0,start=1MiB,size=2MiB,uuid=${uuid_uboot0};name=u-boot-env0,size=1MiB,uuid=${uuid_uboot_env0};name=u-boot1,size=2MiB,uuid=${uuid_uboot1};name=u-boot-env1,size=1MiB,uuid=${uuid_uboot_env1};name=factory,size=1MiB,uuid=${uuid_factory};name=panic,size=24MiB,uuid=${uuid_panic};name=boot,size=32MiB,uuid=${uuid_boot};name=rootfs,size=1536MiB,uuid=${uuid_rootfs};name=update,size=768MiB,uuid=${uuid_update};name=home,size=-,uuid=${uuid_home};

      Delete
    4. Hi,
      Once again, I executed all the instructions yesterday. It is working fine. Faced problems when I used class 4 sdcard. Try using class 10 sdcard and let me know the results

      If you had missed some commands, interrupt the boot sequence and edit U-Boot variables. Don't forget to save the updated variables

      Delete
  12. I used sd card10 32gb. might be problem with my card reader i think so.
    Really thank you for guidance.:)

    ReplyDelete

Fun with RGB LED

People often need home lighting control in their lives. These individuals can easily find relevant products which often use different meth...