[AT&T Samsung Galaxy S II SGH-I777] creepyncrawly:
Prepare Your Phone to Return to the Store or for Warranty Replacement by following these steps:

1. Read the flash counter to make sure your flash count is at "NO". If it reads "YES (x counts)" then you must buy or build a Jig to reset it to "NO"...

...or use chainfire's "Triangle Away" program (which only work on ICS, Android 4.x)

2. Flash the UCKH7-CL503881 stock kernel and system package using Odin or Heimdall.

3. Deal with any special problems.

4. Do a wipe data/factory reset, and remove any personal or sensitive information that remains on the phone.

Note:

Both new and refurbished SGH-I777 phones are now shipping with Android version 2.3.6, UCKK6. As of this writing, March 24, 2012, there is no release of the UCKK6 firmware on sammobile.com, and no one has pulled the stock UCKK6 firmware and packaged it into an Odin flashable tar. For warranty return of phones that shipped with UCKK6, I recommend flashing the stock UCKH7 package contained in this guide. An alternative would be to flash Entropy512's Return/Unbrick to stock Kernel + cache + rooted UCKK6 system package from here, and then to manually remove the traces of root.

Discussion

The Samsung Galaxy S II contains an internal flash counter which is incremented each time a non-stock binary (kernel/rom) is flashed using Odin or Heimdall. The purpose of the flash counter is believed to be to allow Samsung and or AT&T technicians to detect if the phone has a voided warranty through flashing non-stock firmware. In order to safely return the phone to the store or to a warranty center, it is necessary that the flash counter indicates "NO" custom binary download and "Samsung Official" current binary. If the flash counter has been incremented, it is necessary to reset the flash counter before returning the phone. The only known way to do this on Gingerbread is by using a Micro Usb Jig to place the phone into download mode which resets the flash counter. Since the advent of ICS for the I777, it is also possible to reset the flash counter using chairfire's TriangleAway application, but only while running an ICS rom.

The Jig is a micro usb plug with 301,000 ohms of resistance connected across pins 4 and 5. The use of the Jig became well known in late 2010 when a batch of Samsung Galaxy S Captivate phones were shipped with bootloaders that did not allow a button combination to enter download mode. That was before the Galaxy S II was released, and the only purpose for the Jig was to put the phone into download mode. Shortly after the International version of the Galaxy S II was released in May 2011, it was discovered that using a Jig to place the phone into download mode also resets the flash counter. Some who had a Jig for their Captivate found that the Jig would not work on the Galaxy S II. It seems that the Galaxy S II's tolerance for the 301k ohms is closer than the Captivate was, so if the resistance of the Jig was a little bit out of tolerance, it wouldn't work on the newer phone.

If you are handy, you can build your own jig. There are several threads in the Captivate forums that detail how, either with or without soldering. For a place to start, check out this thread and this one. There are also multiple places that sell pre-made Jigs. Check out dayv's thread in the Accessories forum. I bought a cheap JIG that works for under $2.00 and free shipping. A google search for "where to buy micro usb jig" will bring up a good number of them. Some of these may not be close enough tolerance for the Galaxy S II. Users on this forum have reported good results with Jigs from Moble Tech Videos.

Once your flash counter reads "NO", use Odin or Heimdall to flash the stock kernel, system image and modem. A wipe data/factory reset performed from the phone or from stock 3e recovery, and removing any personal or sensitive information on the internal sdcard, completes the process.

Information from dayv:

Information from pinoymutt:

Entropy512 adds:

If you are reading this Guide before you have flashed anything that would increment the flash counter, your best bet woruld be to never increment the flash counter in the first place. It is possible to root and to flash a custom ROM/Kernel without incrementing the flash counter. Please see the Guide: How to Flash Custom Binaries Without Ever Incrementing the Flash Counter!!

1.) How to read the flash counter on an AT&T Samsung Galaxy S II

Boot into download mode by this method:

With the phone powered off, plug in the usb cable while holding the vol up + vol down buttons (but not the power button).

When the warning screen appears, press Volume up to continue into download mode.

At the top of the screen you will see:

ODIN MODE

PRODUCT NAME: SGH-I777

CUSTOM BINARY DOWNLOAD: NO --or-- YES (x counts)

CURRENT BINARY: SAMSUNG OFFICIAL --or-- CUSTOM
​

Once you have verified the information, remove the usb cable, and hold down the power button until the phone begins to reboot. (Do not do this if you are actually flashing the phone. Interrupting a flash can cause bad things to happen.)

You will not see the above information if you enter download mode by another method, ie. by using adb or the power menu, etc.

If your Custom Binary Download is NO, proceed to step 2. If your Custom Binary download is YES, your only option to reset this to NO is to use a Jig. The Jig is a micro usb plug with 301k ohms of resistance connected across pins 4 and 5. On the i777 running original bootloaders, it will reset the flash counter to NO as it puts the phone into download mode. You can make your own jig, or purchase one from many sources on the web. See the Discussion above for more information.

2a.) Flash the UCKH7-CL503881 stock kernel and system package using Odin3 One-Click Downloader (Windows)

Download the "I777UCKH7-CL503881-No-BL.7z" package from Hotfile | Dev-Host 270.17 MB.

Extract the contents of the zip file to a directory on your hard disk drive. This Odin3 One-click downloader contains firmware from the stock binary download available from samfirmware on sammobile.com. The bootloaders boot.bin, sbl.bin and param.lfs have been removed for safety. (Contains cache.img, factoryfs.img, hidden.img, modem.bin and zImage.)

Start the Odin3 One-Click Downloader program by double clicking on "I777UCKH7-CL503881-No-BL.exe".

Now Enter Download Mode:

With the phone powered off, plug in the usb cable while holding the vol up + vol down buttons (but not the power button).

When the warning screen appears, press Volume up to continue into download mode.

In Odin, the small edit box in the upper left corner will turn yellow, and say something like [0:COM8]. The number could be different.

Click Start. Watch the progress bar advance in green while the message box in the lower area describes the steps. When the flash is finished, the top left larger edit box will turn green and say PASS! and your phone will automatically reboot.

Unplug the usb cable from you phone after it boots up. Success. You're Bone Stock.

If your phone enters a bootloop, enter 3e recovery and perform a wipe data/factory reset. See step 4.

2b.) Flash the UCKH7-CL503881 stock kernel and system package from the command line using Heimdall (Linux and Mac OS)

Tested on Linux, should work on Mac OS

Download and install the latest version of Heimdall Command Line for your operating system from here. (Latest version 1.3.1 at this writing.)

Download the UCKH7-CL503881 stock kernel and system package from Hotfile | Dev-Host 269.86 MB.

Extract the contents of this 7zip package to a directory on your hard disk drive, and move or copy all files to the directory where you have the Heimdall command line executable. These were extracted from the stock binary download available from samfirmware on sammobile.com. (Contains cache.img, factoryfs.img, hidden.img, modem.bin and zImage.)

Enter the following at the command prompt:

heimdall flash --kernel zImage --factoryfs factoryfs.img --cache cache.img --hidden hidden.img --modem modem.bin

Reboot the phone. Success. You're Bone Stock.

If your phone enters a bootloop, enter 3e recovery and perform a wipe data/factory reset. See step 4.

3.) Dealing with special problems.

If you are unable to reset the flash counter with a jig, you may have a modified version of the secondary bootloader, perhaps from flashing one of the leaked versions of I777 firmware onto your phone, and will need to flash back to the I777 Stock sbl.bin in order to clear the flash counter.

If your flash counter says that your phone is an I9100, you have an I9100 secondary bootloader, probably from flashing an I9100 rom onto your phone, and you will need to flash back to the I777 Stock sbl.bin to correct the flash counter. You will also probably need to flash the stock param.lfs back onto your phone.

If you get the error "'logo_att.jpg' draw failed", you will need to replace the param.lfs with the I777 Stock param.lfs.

If you get the "Deleting Cryption Meta Data" error while your phone is in a bootloop, see this post.

Necessary files and flashing instructions for these are in the Download Repository.

4.) Do a wipe data/factory reset, and remove any personal or sensitive information that remains on the phone.

To perform a wipe data/factory reset from the phone:

From the home screen, go to Menu > Settings > Privacy > Factory Data Reset (Gingerbread) or Menu > Settings > Back up and reset > Factory data reset (ICS).

If you want to Format USB Storage (erase the internal sdcard), tick the check box.

Click the "Reset Phone" button.

Done.

To perform wipe data/factory reset from 3e recovery:

Reboot into stock 3e recovery: With the phone powered off, hold down the vol up + vol down + power buttons continuously until the initial boot screen appears a second time. Then let the phone boot on into the recovery screen.

Use the vol up and vol down keys to select the "wipe data/factory reset" option.

Press the home button to start the wipe data/factory reset.

Done.

To format USB storage separately (internal sdcard) from the phone:

From the home screen, go to Menu > Settings > Storage > Format USB Storage.

Click the "Format USB Storage" button.

Done.