Merge lp:~morphis/goget-ubuntu-touch/add-turbo-bootstrap-support into lp:goget-ubuntu-touch

Proposed by Simon Fels on 2016-04-12
Status: Merged
Approved by: Ɓukasz Zemczak on 2016-08-03
Approved revision: 239
Merged at revision: 229
Proposed branch: lp:~morphis/goget-ubuntu-touch/add-turbo-bootstrap-support
Merge into: lp:goget-ubuntu-touch
Diff against target: 129 lines (+74/-9)
2 files modified
devices/fastboot.go (+7/-0)
ubuntu-device-flash/touch.go (+67/-9)
To merge this branch: bzr merge lp:~morphis/goget-ubuntu-touch/add-turbo-bootstrap-support
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve on 2016-07-12
Sergio Schvezov 2016-04-12 Approve on 2016-07-11
Alex Tu (community) Needs Fixing on 2016-05-03
Review via email: mp+291583@code.launchpad.net

Commit message

Add bootstrap support for turbo/frieza/cooler devices

The bootloader on turbo/frieza/cooler does not have support for fastboot format <partition> or fastboot boot <image>. Therefor we have to workaround this by using a OEM specific bootloader command to reboot into recovery and adjusting the cleanup of the /cache partition before we push any files.

Also this adds an alias for turbo which is named "smdk" from the bootloader which can't be changed anymore on our production devices.

Description of the change

Corresponding MP for turbo to add the new "format cache" command can be found at https://code.launchpad.net/~morphis/zhongshan/+git/platform_bootable_recovery/+merge/291582

Opened this for a first discussion if we want to add device specific quirks this way.

To post a comment you must log in.
Alex Tu (alextu) wrote :

verified the prebuilt one [1] and it works fine on latest engineer mode recovery which enabled adb[2] by command:
$ ubuntu-device-flash touch --channel ubuntu-touch/rc-proposed/meizu.en --recovery-image=${the-recovery[2]}.img --bootstrap --device turbo

[1] https://private-fileshare.canonical.com/~morphis/ubuntu-device-flash
[2] https://git.launchpad.net/~device-release/turbo/+git/recovery/plain/recovery.img

Alex Tu (alextu) wrote :

LGTM.

review: Approve
Sergio Schvezov (sergiusens) wrote :

Thanks for your contribution, interesting to see what happened when bootloaders are not taken care of early ;-)

The only thing that worries me here is the fact that we only really format cache because there could be files from a failed "flash" there, by wiping we make sure there is enough space. Maybe a message about this when using turbo would be good and make for an easier troubleshoot.

Alex Tu (alextu) :
review: Needs Fixing
Alex Tu (alextu) wrote :

refer the conversation on irc, we might need to do some more operations to simulate fastboot -w then do update, so the proposed way might be 1. reboot recovery to erase data and cache partition 2. reboot recovery again to do update.

<ondra> alextu as for MP for recovery, so I still believe format cache is needed, but it should do proper cache format, or at least delete all from cache, not skip files under /cache/recovery
<ondra> alextu to fix cases when cache is running out of space and there are some old hanging files
<alextu> ondra, hmm ... agree, it seems no reason to keep updates which in /cache/recovery .
* alextu going to upload another mp for that.
<ondra> alextu problem is that then it's not gonna solve problem morphis|off is addressing with that change, when he wants to emulate fastboot -w
<ondra> alextu which should format userdata and cache
<ondra> alextu but then we wipe tarballs which we need to do install update, so it's kinda broken
<ondra> alextu only thing I can think of is to a) move format chache to the end, so it's formatted at the end of update, so it's safe to wipe it all, or we will need two runs, something like "format cache and userdata and reboot back to recovery" so u-d-f can start pushing files
<alextu> ondra, hmm ... sounds option b) is more like what we want to simulate
<ondra> alextu yep
<alextu> ondra, option a) will also remove cache/device-build which is the version of device tarball which updated by u-d-f
<ondra> alextu true

Bin Li (binli) wrote :

After talked with abeato and morphis, we prepare to add 'rm -rf /cache/*' in u-d-f.

Bin Li (binli) wrote :

And I read the code, I found the u-d-f will download the tarballs first, then fastboot.format /cache, and reboot into recovery, then call bitPusher to push these tarballs, and before push it will rm previous tarball like below. After that u-d-f push the tarballs into recovery.

adb.Shell("rm -rf /cache/recovery/*.xz /cache/recovery/*.xz.asc")

So for simple I think we just change above line. Is it ok? Thanks!

adb.Shell("rm -rf /cache/*")

Bin Li (binli) wrote :
review: Approve

Sam behaviour has been observed in frieza and cooler. Can we simply try the "rm -rf /cache/*" if format cache has failed?

review: Needs Fixing

Tested on cooler now, works fine.

review: Approve

Tested on frieza too. Worked as expected.

Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~morphis/goget-ubuntu-touch/add-turbo-bootstrap-support into lp:goget-ubuntu-touch failed. Below is the output from the failed tests.

Checking formatting
Formatting wrong in following files
ubuntu-device-flash/touch.go

# we always run in a fresh dir in tarmac
export GOPATH=$(mktemp -d)
trap 'rm -rf "$GOPATH"' EXIT

# this is a hack, but not sure tarmac is golang friendly
mkdir -p $GOPATH/src/launchpad.net/goget-ubuntu-touch
cp -a . $GOPATH/src/launchpad.net/goget-ubuntu-touch
cd $GOPATH/src/launchpad.net/goget-ubuntu-touch

./run-checks

Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~morphis/goget-ubuntu-touch/add-turbo-bootstrap-support into lp:goget-ubuntu-touch failed. Below is the output from the failed tests.

Checking formatting
Formatting wrong in following files
ubuntu-device-flash/touch.go

# we always run in a fresh dir in tarmac
export GOPATH=$(mktemp -d)
trap 'rm -rf "$GOPATH"' EXIT

# this is a hack, but not sure tarmac is golang friendly
mkdir -p $GOPATH/src/launchpad.net/goget-ubuntu-touch
cp -a . $GOPATH/src/launchpad.net/goget-ubuntu-touch
cd $GOPATH/src/launchpad.net/goget-ubuntu-touch

./run-checks

239. By Simon Fels on 2016-07-21

Correct formatting

Robert Bruce Park (robru) wrote :

This MP was released through bileto, but then tarmac merged it prematurely, confusing bileto. If you intend to continue using goget-ubuntu-touch in bileto you need to disable tarmac.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'devices/fastboot.go'
--- devices/fastboot.go 2015-04-16 22:59:18 +0000
+++ devices/fastboot.go 2016-07-21 15:57:39 +0000
@@ -85,3 +85,10 @@
85 }85 }
86 return device, err86 return device, err
87}87}
88
89// Send OEM specific commands to bootloader
90func (fastboot Fastboot) SendOemCommand(command string) (err error) {
91 cmd := append(fastboot.params, []string{"oem", command}...)
92 err = exec.Command(fastbootCommand, cmd...).Run()
93 return err
94}
8895
=== modified file 'ubuntu-device-flash/touch.go'
--- ubuntu-device-flash/touch.go 2016-06-13 14:19:39 +0000
+++ ubuntu-device-flash/touch.go 2016-07-21 15:57:39 +0000
@@ -2,7 +2,7 @@
2// ubuntu-device-flash - Tool to download and flash devices with an Ubuntu Image2// ubuntu-device-flash - Tool to download and flash devices with an Ubuntu Image
3// based system3// based system
4//4//
5// Copyright (c) 2013-2014 Canonical Ltd.5// Copyright (c) 2013-2016 Canonical Ltd.
6//6//
7// Written by Sergio Schvezov <sergio.schvezov@canonical.com>7// Written by Sergio Schvezov <sergio.schvezov@canonical.com>
8//8//
@@ -35,6 +35,7 @@
35 Bootstrap bool `long:"bootstrap" description:"bootstrap the system, do this from the bootloader"`35 Bootstrap bool `long:"bootstrap" description:"bootstrap the system, do this from the bootloader"`
36 Wipe bool `long:"wipe" description:"Clear all data after flashing"`36 Wipe bool `long:"wipe" description:"Clear all data after flashing"`
37 Serial string `long:"serial" description:"Serial of the device to operate"`37 Serial string `long:"serial" description:"Serial of the device to operate"`
38 AdbSerial string `long:"adb-serial" description:"Serial for ADB to specify the device to operate"`
38 DeveloperMode bool `long:"developer-mode" description:"Enables developer mode after the factory reset, this is meant for automation and makes the device insecure by default (requires --password)"`39 DeveloperMode bool `long:"developer-mode" description:"Enables developer mode after the factory reset, this is meant for automation and makes the device insecure by default (requires --password)"`
39 AdbKeys string `long:"adb-keys" description:"Specify a local adb keys files, instead of using default ~/.android/adbkey.pub (requires --developer-mode)"`40 AdbKeys string `long:"adb-keys" description:"Specify a local adb keys files, instead of using default ~/.android/adbkey.pub (requires --developer-mode)"`
40 DeviceTarball string `long:"device-tarball" description:"Specify a local device tarball to override the one from the server (using official Ubuntu images with different device tarballs)"`41 DeviceTarball string `long:"device-tarball" description:"Specify a local device tarball to override the one from the server (using official Ubuntu images with different device tarballs)"`
@@ -234,17 +235,60 @@
234 if err := touchCmd.fastboot.Flash("recovery", recovery); err != nil {235 if err := touchCmd.fastboot.Flash("recovery", recovery); err != nil {
235 return errors.New("can't flash recovery image")236 return errors.New("can't flash recovery image")
236 }237 }
237 if err := touchCmd.fastboot.Format("cache"); err != nil {238
238 log.Print("Cache formatting was not successful, flashing may fail, " +239 var deviceSupportsCacheFormat bool = true
239 "check your partitions on device")240 var deviceSupportsBootImage bool = true
240 }241 var deviceSupportsOemRebootRecovery bool = false
241242
242 if err := touchCmd.fastboot.BootImage(recovery); err != nil {243 if touchCmd.Device == "turbo" {
243 return errors.New("Can't boot recovery image")244 deviceSupportsCacheFormat = false
244 }245 deviceSupportsBootImage = false
246 deviceSupportsOemRebootRecovery = true
247 }
248 if touchCmd.Device == "frieza" || touchCmd.Device == "cooler" {
249 deviceSupportsCacheFormat = false
250 }
251
252 if deviceSupportsCacheFormat {
253 if err := touchCmd.fastboot.Format("cache"); err != nil {
254 log.Print("Cache formatting was not successful, flashing may fail, " +
255 "check your partitions on device")
256 }
257 }
258
259 if deviceSupportsBootImage {
260 if err := touchCmd.fastboot.BootImage(recovery); err != nil {
261 return errors.New("Can't boot recovery image")
262 }
263 } else if deviceSupportsOemRebootRecovery {
264 // Some bootloaders does not support the BootImage command so we have
265 // to flash the recovery first and then reboot through a OEM specific
266 // command the bootloader offers.
267 if err := touchCmd.fastboot.SendOemCommand("reboot recovery"); err != nil {
268 return errors.New("Can't reboot device")
269 }
270 } else {
271 log.Print("We can't reboot your device automatically. Please reboot " +
272 "your device manually to recovery mode.")
273 }
274
275 log.Print("Waiting for device to enter recovery mode ...")
245 if err := touchCmd.adb.WaitForRecovery(); err != nil {276 if err := touchCmd.adb.WaitForRecovery(); err != nil {
246 return err277 return err
247 }278 }
279
280 if !deviceSupportsCacheFormat {
281 // On some devices we can't run `fastboot format cache` as the bootloader
282 // does not support this command. We're erasing all bits from the
283 // cache partition manually once we've booted into the recovery.
284 if _, err := touchCmd.adb.Shell("rm -rf /cache/*"); err != nil {
285 log.Fatal("Cannot cleanup /cache/ to ensure clean deployment", err)
286 }
287
288 if _, err := touchCmd.adb.Shell("mkdir /cache/recovery"); err != nil {
289 log.Fatal("Failed to recreate filesystem structure on cache partition", err)
290 }
291 }
248 }292 }
249 go bitPusher(touchCmd.adb, files, done)293 go bitPusher(touchCmd.adb, files, done)
250 for i := 0; i < totalFiles; i++ {294 for i := 0; i < totalFiles; i++ {
@@ -309,10 +353,24 @@
309 touchCmd.fastboot.SetSerial(touchCmd.Serial)353 touchCmd.fastboot.SetSerial(touchCmd.Serial)
310 }354 }
311355
356 if touchCmd.AdbSerial != "" {
357 touchCmd.adb.SetSerial(touchCmd.AdbSerial)
358 }
359
312 if touchCmd.Device == "" {360 if touchCmd.Device == "" {
313 if touchCmd.Bootstrap {361 if touchCmd.Bootstrap {
314 log.Print("Expecting the device to be in the bootloader... waiting")362 log.Print("Expecting the device to be in the bootloader... waiting")
315 touchCmd.Device, err = touchCmd.fastboot.GetDevice()363 touchCmd.Device, err = touchCmd.fastboot.GetDevice()
364
365 // For turbo it was missed to put the proper name into the bootloader
366 // and this can't be changed anymore after production already started.
367 // Reflashing the bootloader through an OTA update to fix this is also
368 // very unlikely to happen so we have to work around here and make sure
369 // this never happens again.
370 if touchCmd.Device == "smdk" {
371 touchCmd.Device = "turbo"
372 }
373
316 return err374 return err
317 } else {375 } else {
318 log.Print("Expecting the device to expose an adb interface...")376 log.Print("Expecting the device to expose an adb interface...")

Subscribers

People subscribed via source and target branches