Author Topic: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE  (Read 17150 times)

SNESFAN

  • Guest
[GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« on: February 11, 2013, 03:19:20 am »
This guide will take you from a fresh install of linux (ubuntu 13.04 in my case) to a compiled OS ready to be flashed to your zero. I have not seen this process spelt out to a T anywhere, so I'm composing it myself. Credits to zear from dingoonity for the original how-to process of replacing the internal microsd and mth for helping me fix some of the troubles I came across while compiling. Also big shout out to Justin (aka GCW) for making such an awesome device. I imagine there will be many good years ahead for him and his team.


I will break this process down as simple as possible. I will assume you have ubuntu (or your chosen flavor of linux already installed) and you know how to open a terminal.

first we install all the prereqs

Code: [Select]
sudo apt-get install git bison flex g++ texinfo mercurial subversion libncurses5-dev libusb-dev libconfuse-dev

say (Y)es when asked.

----------------------
Next we download and compile the toolchain and rootfs (rootfs.squashfs) "~" refers to your home directory

Code: [Select]
cd ~
git clone git://github.com/gcwnow/buildroot.git
cd buildroot
make gcw0_defconfig
make

It should take several hours to complete but when the build is done, your toolchain will be under ~/buildroot/output/host/usr/ and the rootfs will be here ~/buildroot/output/images/rootfs.squashfs

Next we copy the toolchain to /opt/ and set permissions for future use with the kernel compile and any other software that will go on the zero you want to compile.

Code: [Select]
mkdir -p /opt
sudo chmod -R 777 /opt/
cp -r ~/buildroot/output/host/usr/* /opt/

--------------------------

Next we download and compile the kernel

prereq for this is that toolchain created and placed in /opt/ directory we did in the above step

we are setting the envrionmental variable that tells the compiler what to use when compiling the kernel. Then we are downloading the source, setting the configureation file to build for the zero then building the kernel.

Code: [Select]
cd ~
PATH=$PATH:/opt/bin
export PATH
git clone git://github.com/gcwnow/linux.git
cd linux
make ARCH=mips gcw0_defconfig
make ARCH=mips vmlinuz.bin -j4

-j4 is variable depending on how many cores you want to build with. Some may use -j2 some may use -j8 depending on how powerful your machine is.

Once completed your kernel (vmlinuz.bin) will be in ~/linux/
-------------

So now we have our rootfs.squashfs (file system) and our vmlinuz.bin (kernel) now comes the optional fun part of taking apart and flashing the zero.

1) Open the case
2) Remove microSD from the slot
3) Put new, empty microSD to the slot
4) Close the case

--------------

Now we're ready to flash the zero. We are downloading the 3 sources for the flash utilities. UBIBoot compiles the bootloader for the zero, Imager puts together the kernel and file system packages to be flashed. ingenic-boot actually does the flashing.

Code: [Select]
cd ~
git clone https://github.com/gcwnow/UBIBoot.git
git clone https://github.com/gcwnow/imager.git
git clone https://github.com/gcwnow/ingenic-boot.git
cd UBIBoot
make CONFIG=gcw0

here you must choose one of the 2 commands based on the device you are building for. This is for the bootloader only. If you are creative you can find a way to build for both, but for this guide we're only choosing one.
Code: [Select]
(256MB "FrankenZero" / Prototypes / Clones)
cp ./output/gcw0/ubiboot-v11_ddr2_256mb.bin ~/imager/ubiboot.bin

(512MB "Kickstarter" / Regular / "Production / SE / Pre-order")
cp ./output/gcw0/ubiboot-v20_mddr_512mb.bin ~/imager/ubiboot.bin

after you've copied your chosen boot.bin, continue

Code: [Select]
cd ~/imager
./create_mbr.sh
cp ~/linux/vmlinuz.bin ~/imager/vmlinuz.bin
./create_system_image.sh
cp ~/buildroot/output/images/rootfs.squashfs ~/imager/rootfs.squashfs
./create_data_image.sh
cd ~/ingenic-boot
make

copy the bundled files to the flasher app we just made
Code: [Select]
cp ~/imager/images/* ~/ingenic-boot/

So you have all your tools compiled, congrats! Almost there, the last step is to flash it to the device.

Make sure your device is powered off, then while holding SELECT button power it on. Release the SELECT button after about 2 seconds. You won't see anything happen on your screen but it is entering a special download mode where you are able to flash the bootloader and firmware.

to make sure your device is connected correctly

Code: [Select]
cd ~/ingenic-boot
sudo ./ingenic-boot -probe

the output should show "JZ4770" if it shows "no xburst devices found" it means you didn't put your device into download mode correctly, you need to try agian, no special drivers are needed so don't worry about that.

if you got the correct output we are now ready to proceed with flashing... last command choose the one that corresponds to the type of device you have.

(256MB "FrankenZero" / Prototypes / Clones)
Code: [Select]
sudo ./ingenic-boot -config=v11_ddr2_256mb -mbr=mbr.bin -boot=ubiboot.bin -system=system.bin -data=data.bin -check

(512MB "Kickstarter" / Regular / "Production / SE / Pre-order")
Code: [Select]
sudo ./ingenic-boot -mbr=mbr.bin -boot=ubiboot.bin -system=system.bin -data=data.bin -check


During the flash process it will start with "probe 1th" and spit out the status of the flashing process. Once it says done just let the device sit it should reboot and you should be good to go. If you find I missed something or typo'd anything let me know and I'll fix it.

--------------------------------------------------
For those that just want to use the tool, I will make snapshots and post them here occasionally to ensure you are starting off with a somewhat up to date image whenever possible before running the official "untethered" update tool.

2015MAY24
LINUX -> https://www.dropbox.com/s/43epexcnozg48nx/GCW0-Flasher-LINUX-20130524.zip
WINDOWS -> https://www.dropbox.com/s/swurdbx8qo6vjr1/GCW0-Flasher-WIN-20130524.zip


2013APR30
https://www.dropbox.com/s/o4oz7neympmftpw/GCW0-Flasher-20130430.zip

:updated 7/25/13: corrected some changes to build process

-enjoy
SNESFAN
« Last Edit: July 25, 2013, 09:16:30 pm by SNESFAN »

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #1 on: April 30, 2013, 09:10:10 pm »
updated OP w/ corrections due to changes & added pre-compiled images w/ flasher utility

please note, there is now 3 boot-loaders to choose from included in the precompiled package at the end of the OP

LINUX USERS CHOOSE ONE OF THE FOLLOWING
--------------------------
bootFZ.bin is for all original 256mb GCW0 prototypes, clones, frankenzeros devices

bootSE.bin is for all 512MB Special Edition, pre-order devices (possibly discontinued try kickstarter version if this doesn't boot)

bootKS.bin is for all 512MB Kickstarter, Production, or "normal" devices


WINDOWS USERS CHOOSE ONE OF THE FOLLOWING
--------------------------
sd_image_frankenzero.bin is for all original 256mb GCW0 prototypes, clones, frankenzeros devices

sd_image_specialedition.bin is for all 512MB Special Edition, pre-order devices (possibly discontinued try kickstarter version if this doesn't boot)

sd_image_kickstarter.bin is for all 512MB Kickstarter, Production, or "normal" devices

if one doesn't work, yours is possibly branded incorrectly, try another
« Last Edit: May 24, 2013, 07:58:05 pm by SNESFAN »

mth

  • Posts: 319
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #2 on: May 01, 2013, 08:22:51 am »
There weren't many 512MB V1.1 units produced. It's likely that both the SE and the Kickstarter units will be 512MB V2.0. The SE units will have a different bezel print and a larger and really fast internal SD card, as far as I know.

The 512MB V1.1 unit triggered the highmem problems several weeks before the first V2.0 unit was available, so it was very useful for development.

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #3 on: May 01, 2013, 11:26:30 am »
Is the v1.1 and v2.0 the printed number on the PCB in the upper left?

If so, that would make things slightly easier to identify for someone popping off the back of the device.

As a note, the same v1.1 markings exist for the 256mb boards so you have to also look for the little "(M)" micron graphic on the 2 memory chips to know you have a 512MB board.
« Last Edit: May 01, 2013, 11:28:30 am by SNESFAN »

mth

  • Posts: 319
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #4 on: May 01, 2013, 06:28:49 pm »
Yes, "V1.1" and "V2.0" refers to the number on the PCB. There is a simpler check though: on V2.0, the power LED works as you would expect it to: it turns on immediately as soon as you turn on the device. On V1.1, the power LED only works when the unit is connected to DC power.

BAFelton

  • Posts: 276
    • Open Consoles
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #5 on: May 19, 2013, 01:36:03 pm »
Tried to reflash my proto with a virtual ubuntu.

Used the gcw0-flasher, but i have this message on the terminal :



Any help ?

My Zer0 is in download mode, it appears like this on 7 :




On the IRC atm.

pcercuei

  • Posts: 1732
    • My devblog
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #6 on: May 19, 2013, 05:45:51 pm »
Unfortunately, SNESFAN's tuto is out of date (the flashing part at least).
An updated tutorial can be found here: https://github.com/gcwnow/ingenic-boot/wiki
« Last Edit: May 19, 2013, 05:53:30 pm by pcercuei »

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #7 on: May 20, 2013, 12:53:51 am »
I think for a virtual machine in windows (like virtualbox) you need correct windows drivers to pass along to the virtual.

here's a copy but I don't think that's your main problem.
http://forum.openhandhelds.net/index.php?action=dlattach;topic=208.0;attach=407

I ran into some issues when compiling in a virtual environment so I personally did mine as a dual boot setup. If I can figure out what settings need adjusted I'll include those as a note to the OP so it can be done as a virtual instead of dualboot.

I also need to check dependencies from the looks of it, for using the standalone flasher. I'm guessing it's something to do with trying to sudo the flash script from the home folder. I'll check it out.

I'll be updating it shortly to see what's been changed since they fixed the internal fs corruption bug, but I did update it since they did the 3 different bootloaders.
« Last Edit: May 20, 2013, 01:05:34 am by SNESFAN »

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #8 on: May 23, 2013, 10:12:15 pm »
k, should be fixed now, updated OP

Looks like they changed the script names around a little bit and added a mbr image and left ubiboot untouched after compiling.

I will have some binaries and a freeware raw image flasher in a little bit for windows users to write to a sdcard instead of to the device, and will include a easier command to run (dd) if you're a linux user as I think the previous script would fail out for whatever reason if you didn't go through the entire compile process.'

Will also make a seperate download for the 4 image flasher for linux users if they want to use that instead of the 1 image flasher.


------------------
EDIT: updated OP with 4 image flasher for linux w/ 3 choices for bootloader and 1 image flasher for windows with 3 sd card images each for the different types of bootloaders. I didn't include a readme file for the windows version as it's pretty self explanatory. If you need a tut let me know.
« Last Edit: May 24, 2013, 07:49:18 pm by SNESFAN »

mth

  • Posts: 319
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #9 on: May 27, 2013, 03:07:01 pm »
Two corrections:
  • the SE units will be "v20_mddr_512mb", just like the KS units
  • if you want to flash a prototype, you have to add "--config=v11_ddr2_256mb" to the ingenic-boot command line (or update the fw/current.cfg symlink)

Some background about the changes I made a week ago:

Originally the boot image contained the MBR and two copies of the boot loader. However, it turns out that when booting from SD, there is no backup boot loader support (unlike when booting from NAND), so the second copy of the boot loader was redundant. Since there was already an option to write the boot loader separately, I figured it made more sense to write the MBR separately as well.

Currently the rootfs is located inside the data partition, but we are considering moving it into the same partition as the kernel, since that reduces the chance of the rootfs getting damaged in case of crashes or power failure. Also this would make it far easier to repair or reformat the data partition if it got damaged. The names of the images were updated to match this new layout.

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #10 on: July 25, 2013, 09:14:13 pm »
updated OP once more with some small changes to paths and the changes noted by mth

precompiled files uploading

MacDonals

  • Posts: 79
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #11 on: July 30, 2013, 02:15:16 pm »
This is great, I needed this guide.  I am planning on dropping a 32GB card inside and a 64GB card in the expansion slot.  So yeah, need to build it.  I use Fedora, but looking at the instructions that should be fine...

msparky83

  • Posts: 6
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #12 on: September 12, 2013, 07:11:37 am »
I've been trolling these forums for quite some time now, and recently decided to actually join Dingoonity further get into the GCW-ZERO scene.  Ok, so i'll be that guy and ask how we could possibly use the win flash tool if the OS in question is windows 8, and the initial FDU mode failed, and so did the manual install of the drivers.  Am I missing something here.  At the moment i'm not 100% versed in Linux, and I would prefer to be able to flash my device in Win to upgrade to the 32 Gig micro SD.  If someone can help me with this issue it would be greatly appreciated.  Cheers, and thanks in advance.

SNESFAN

  • Guest
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #13 on: September 12, 2013, 03:49:12 pm »
The windows flash tool writes the .bin file in raw format to a microsd, I would recommend using a external card reader to flash the image then insert it into the device.
« Last Edit: September 13, 2013, 03:57:24 am by SNESFAN »

msparky83

  • Posts: 6
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #14 on: September 13, 2013, 03:49:15 am »
Doh' why the heck didn't I think of that?  Thanks mate.  I've been trying to do it the hard way.

ruffnutts

  • Posts: 2648
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #15 on: September 26, 2013, 09:18:34 pm »
Does these images work for internal 64GB card?

pcercuei

  • Posts: 1732
    • My devblog
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #16 on: September 26, 2013, 09:21:48 pm »
They work for every size of card.

ruffnutts

  • Posts: 2648
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #17 on: September 26, 2013, 09:23:31 pm »
They work for every size of card.

Thanks mate I shall invest ;D

mth

  • Posts: 319
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #18 on: October 05, 2013, 04:44:31 am »
From now on, we will be posting flash images on gcw-zero.com. The page also contains instructions, although not as detailed as SNESFAN wrote them.

ruffnutts

  • Posts: 2648
Re: [GUIDE] BUILD FIRMWARE FROM SOURCE AND FLASH TO DEVICE
« Reply #19 on: October 05, 2013, 04:19:09 pm »
From now on, we will be posting flash images on gcw-zero.com. The page also contains instructions, although not as detailed as SNESFAN wrote them.

Ok thanks mth.. sounds great to me 8)

 

Post a new topic
Post a new topic