From stock to Cyanogenmod: The Sony Ericsson Case

3,578 views

Published on

Porting a device to CyanogenMod is (usually) not an easy task. There is an extensive amount of work behind a port that touches every single layer of the Android stack.

During this talk, I will be presenting a case study on how we ported 15 Sony Ericsson devices. While there is no specific formula for doing so, this talk will try to present a sequence of steps that we took in making these devices fully operational.

You can expect several advanced topics to be discussed, all in an interactive session where I expect people to interrupt if they have questions or suggestions. Among those topics, we will discuss:

- Kernel changes
- Hardware Interface Layers
- Coexisting with other devices
- Reverse Engineering

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,578
On SlideShare
0
From Embeds
0
Number of Embeds
99
Actions
Shares
0
Downloads
95
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

From stock to Cyanogenmod: The Sony Ericsson Case

  1. 1. FROM STOCK TO CYANOGENMOD: THE SONY ERICSSON CASE DROIDCON INDIA | NOVEMBER 19, 2011 DIOGO FERREIRA | DEFER@CYANOGENMOD.COM | @DEFERSaturday, November 19, 11
  2. 2. INTRODUCTIONSaturday, November 19, 11
  3. 3. INTRODUCTION OEM DEVICES RUN SLIGHTLY MODIFIED VERSIONS OF ANDROID SPORTING FANCY FEATURES AND PERIPHERALS ADDING UI CUSTOMIZATIONSSaturday, November 19, 11
  4. 4. INTRODUCTION OEM DEVICES RUN SLIGHTLY MODIFIED VERSIONS OF ANDROID SPORTING FANCY FEATURES AND PERIPHERALS ADDING UI CUSTOMIZATIONS CYANOGENMOD SUPPORTS MANY DEVICES ACROSS DIFFERENT HARDWARE PLATFORMSSaturday, November 19, 11
  5. 5. INTRODUCTION OEM DEVICES RUN SLIGHTLY MODIFIED VERSIONS OF ANDROID SPORTING FANCY FEATURES AND PERIPHERALS ADDING UI CUSTOMIZATIONS CYANOGENMOD SUPPORTS MANY DEVICES ACROSS DIFFERENT HARDWARE PLATFORMS GET CM! REPO INIT -U GIT://GITHUB.COM/CYANOGENMOD/ANDROID.GIT -B GINGERBREAD REPO SYNC -J4Saturday, November 19, 11
  6. 6. THE RECOVERY PART ONESaturday, November 19, 11
  7. 7. PRELIMINARIESSaturday, November 19, 11
  8. 8. PRELIMINARIES KEEP A COPY OF THE STOCK SYSTEM FILES ADB PULL /SYSTEM IS ENOUGH THESE WILL BE NEEDED LATER ON!Saturday, November 19, 11
  9. 9. PRELIMINARIES KEEP A COPY OF THE STOCK SYSTEM FILES ADB PULL /SYSTEM IS ENOUGH THESE WILL BE NEEDED LATER ON!Saturday, November 19, 11
  10. 10. PRELIMINARIES KEEP A COPY OF THE STOCK SYSTEM FILES ADB PULL /SYSTEM IS ENOUGH THESE WILL BE NEEDED LATER ON! BE FEARLESS, IT IS USUALLY VERY HARD TO BRICK A DEVICESaturday, November 19, 11
  11. 11. WE NEED A RECOVERY!Saturday, November 19, 11
  12. 12. WE NEED A RECOVERY! BACKUP THE ORIGINAL ROMSaturday, November 19, 11
  13. 13. WE NEED A RECOVERY! BACKUP THE ORIGINAL ROM GO BACK TO IT ANYTIMESaturday, November 19, 11
  14. 14. WE NEED A RECOVERY! BACKUP THE ORIGINAL ROM GO BACK TO IT ANYTIME ENABLES YOU TO ACTUALLY FLASH CMSaturday, November 19, 11
  15. 15. WE NEED A RECOVERY! BACKUP THE ORIGINAL ROM GO BACK TO IT ANYTIME ENABLES YOU TO ACTUALLY FLASH CMSaturday, November 19, 11
  16. 16. WE NEED A RECOVERY! BACKUP THE ORIGINAL ROM GO BACK TO IT ANYTIME ENABLES YOU TO ACTUALLY FLASH CM BUT YOU NEED A DEVICE REPOSITORY TO COMPILE ITSaturday, November 19, 11
  17. 17. GETTING THINGS GOINGSaturday, November 19, 11
  18. 18. GETTING THINGS GOING WE HAVE YOU COVERED!Saturday, November 19, 11
  19. 19. GETTING THINGS GOING WE HAVE YOU COVERED! BUILD/TOOLS/DEVICE/MKVENDOR.SH <MANUFACTURER> <DEVICE> /PATH/TO/ YOUR/BOOT.IMGSaturday, November 19, 11
  20. 20. GETTING THINGS GOING WE HAVE YOU COVERED! BUILD/TOOLS/DEVICE/MKVENDOR.SH <MANUFACTURER> <DEVICE> /PATH/TO/ YOUR/BOOT.IMG BUILD/TOOLS/DEVICE/MKVENDOR.SH SEMC ANZU BOOT.IMGSaturday, November 19, 11
  21. 21. GETTING THINGS GOING WE HAVE YOU COVERED! BUILD/TOOLS/DEVICE/MKVENDOR.SH <MANUFACTURER> <DEVICE> /PATH/TO/ YOUR/BOOT.IMG BUILD/TOOLS/DEVICE/MKVENDOR.SH SEMC ANZU BOOT.IMG WHERE DO I GET THE BOOT IMAGE?Saturday, November 19, 11
  22. 22. GETTING THINGS GOING WE HAVE YOU COVERED! BUILD/TOOLS/DEVICE/MKVENDOR.SH <MANUFACTURER> <DEVICE> /PATH/TO/ YOUR/BOOT.IMG BUILD/TOOLS/DEVICE/MKVENDOR.SH SEMC ANZU BOOT.IMG WHERE DO I GET THE BOOT IMAGE? DUMP_IMAGE BOOT /SDCARD/BOOT.IMGSaturday, November 19, 11
  23. 23. GETTING THINGS GOING WE HAVE YOU COVERED! BUILD/TOOLS/DEVICE/MKVENDOR.SH <MANUFACTURER> <DEVICE> /PATH/TO/ YOUR/BOOT.IMG BUILD/TOOLS/DEVICE/MKVENDOR.SH SEMC ANZU BOOT.IMG WHERE DO I GET THE BOOT IMAGE? DUMP_IMAGE BOOT /SDCARD/BOOT.IMG YOU NOW HAVE YOUR BAREBONES DEVICE REPOSITORY OVER AT MANUFACTURER/DEVICESaturday, November 19, 11
  24. 24. BUILDING A RECOVERY IMAGE . BUILD/ENVSETUP.SH LUNCH FULL_<DEVICE>-ENG LUNCH FULL_ANZU-ENG MAKE -J4 RECOVERYIMAGE YOU WILL HAVE A RECOVERY IMAGE IN OUT/TARGET/PRODUCT/<DEVICE>/ RECOVERY.IMGSaturday, November 19, 11
  25. 25. HOW DO I RUN IT?Saturday, November 19, 11
  26. 26. HOW DO I RUN IT? USUALLY: FLASH_IMAGE RECOVERY RECOVERY.IMGSaturday, November 19, 11
  27. 27. HOW DO I RUN IT? USUALLY: FLASH_IMAGE RECOVERY RECOVERY.IMG RARELY: FASTBOOT FLASH RECOVERY RECOVERY.IMGSaturday, November 19, 11
  28. 28. HOW DO I RUN IT? USUALLY: FLASH_IMAGE RECOVERY RECOVERY.IMG RARELY: FASTBOOT FLASH RECOVERY RECOVERY.IMG IN MY CASE: FASTBOOT BOOT RECOVERY RECOVERY.IMG FOR SONY ERICSSON, THERE IS NO DEDICATED RECOVERY PARTITION!Saturday, November 19, 11
  29. 29. AND THEN THERE WAS A RECOVERYSaturday, November 19, 11
  30. 30. AND THEN THERE WAS A RECOVERY OR WAS THERE?Saturday, November 19, 11
  31. 31. AND THEN THERE WAS A RECOVERY OR WAS THERE? SONY ERICSSON WAS THE FIRST TO USE 32-BIT FRAMEBUFFERS RECOVERY CODE NEEDED TO BE ADAPTED CHANGES GATHERED FROM CODEAURORA FORUMSaturday, November 19, 11
  32. 32. THE FIRST BOOT PART TWOSaturday, November 19, 11
  33. 33. WHERE TO START?Saturday, November 19, 11
  34. 34. WHERE TO START? YOUR PREVIOUSLY CREATED DEVICE REPOSITORY!Saturday, November 19, 11
  35. 35. WHERE TO START? YOUR PREVIOUSLY CREATED DEVICE REPOSITORY! BOARDCONFIG.MK FILL IN THE BLANKS! THE BUILD SYSTEM NEEDS TO KNOW YOUR DEVICE THERE IS PROBABLY A SIMILAR DEVICE IN THE TREE, USE IT!Saturday, November 19, 11
  36. 36. WHERE TO START? YOUR PREVIOUSLY CREATED DEVICE REPOSITORY! BOARDCONFIG.MK FILL IN THE BLANKS! THE BUILD SYSTEM NEEDS TO KNOW YOUR DEVICE THERE IS PROBABLY A SIMILAR DEVICE IN THE TREE, USE IT! FOR THE SONY ERICSSON ANZU: TARGET_BOARD_PLATFORM := MSM7X30 TARGET_CPU_ABI := ARMEABI-V7A ...Saturday, November 19, 11
  37. 37. WHERE TO START?Saturday, November 19, 11
  38. 38. WHERE TO START? DEVICE_<DEVICE>.MKSaturday, November 19, 11
  39. 39. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE!Saturday, November 19, 11
  40. 40. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTSSaturday, November 19, 11
  41. 41. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTS FOR A PRELIMINARY BOOT YOU SHOULD BE OK USING THE DEFAULTSSaturday, November 19, 11
  42. 42. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTS FOR A PRELIMINARY BOOT YOU SHOULD BE OK USING THE DEFAULTS BUT NOTHING WILL WORKSaturday, November 19, 11
  43. 43. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTS FOR A PRELIMINARY BOOT YOU SHOULD BE OK USING THE DEFAULTS BUT NOTHING WILL WORK BUILD IT!Saturday, November 19, 11
  44. 44. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTS FOR A PRELIMINARY BOOT YOU SHOULD BE OK USING THE DEFAULTS BUT NOTHING WILL WORK BUILD IT! LUNCH FULL_<DEVICE>.MKSaturday, November 19, 11
  45. 45. WHERE TO START? DEVICE_<DEVICE>.MK TELL THE SYSTEM WHAT TO COMPILE! DIFFERENT DEVICES HAVE DIFFERENT REQUIREMENTS FOR A PRELIMINARY BOOT YOU SHOULD BE OK USING THE DEFAULTS BUT NOTHING WILL WORK BUILD IT! LUNCH FULL_<DEVICE>.MK MAKE -J4 OTAPACKAGESaturday, November 19, 11
  46. 46. THE FUN STARTS!Saturday, November 19, 11
  47. 47. THE FUN STARTS!Saturday, November 19, 11
  48. 48. PLATFORM SUPPORT PART THREESaturday, November 19, 11
  49. 49. WHAT ABOUT IT? ANDROID NEEDS TO KNOW HOW TO TALK TO YOUR HARDWARE ANDROID FRAMEWORK / USERSPACE SENSORS AUDIO DISPLAY ... KERNEL HARDWARESaturday, November 19, 11
  50. 50. ADDING PLATFORM SUPPORTSaturday, November 19, 11
  51. 51. ADDING PLATFORM SUPPORT USUALLY YOU DON’T NEED TO, CM ALREADY SUPPORTS: OMAP3/4, TEGRA 2, QUALCOMM 7X30/8X60/8KSaturday, November 19, 11
  52. 52. ADDING PLATFORM SUPPORT USUALLY YOU DON’T NEED TO, CM ALREADY SUPPORTS: OMAP3/4, TEGRA 2, QUALCOMM 7X30/8X60/8K IF YOU DO, GET THEM FROM REFERENCE BOARD REPOS: QUALCOMM: HTTP://WWW.CODEAURORA.ORG TI: HTTP://WWW.OMAPZOOM.ORG NVIDIA: HTTP://NV-TEGRA.NVIDIA.COM LINARO: HTTP://WWW.LINARO.ORGSaturday, November 19, 11
  53. 53. ADDING PLATFORM SUPPORT: CAVEATS Saturday, November 19, 11
  54. 54. ADDING PLATFORM SUPPORT: CAVEATS BEWARE: IT SHOULD BE CONTAINEDSaturday, November 19, 11
  55. 55. ADDING PLATFORM SUPPORT: CAVEATS BEWARE: IT SHOULD BE CONTAINED YOU MUST ENSURE IT WILL NOT BREAK OTHER DEVICESSaturday, November 19, 11
  56. 56. ADDING PLATFORM SUPPORT: CAVEATS BEWARE: IT SHOULD BE CONTAINED YOU MUST ENSURE IT WILL NOT BREAK OTHER DEVICES IF YOU REALLY MUST CHANGE THINGS OUTSIDE THE INTERFACE LAYERS:Saturday, November 19, 11
  57. 57. ADDING PLATFORM SUPPORT: CAVEATS BEWARE: IT SHOULD BE CONTAINED YOU MUST ENSURE IT WILL NOT BREAK OTHER DEVICES IF YOU REALLY MUST CHANGE THINGS OUTSIDE THE INTERFACE LAYERS: BOARD CONFIG OPTION + #IFDEFSaturday, November 19, 11
  58. 58. ADDING PLATFORM SUPPORT: CAVEATS BEWARE: IT SHOULD BE CONTAINED YOU MUST ENSURE IT WILL NOT BREAK OTHER DEVICES IF YOU REALLY MUST CHANGE THINGS OUTSIDE THE INTERFACE LAYERS: BOARD CONFIG OPTION + #IFDEF SYSTEM PROPERTY + ALTERNATING BRANCHES IN THE JAVA SIDESaturday, November 19, 11
  59. 59. HARDWARE ABSTRACTION LAYERSSaturday, November 19, 11
  60. 60. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNELSaturday, November 19, 11
  61. 61. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORSSaturday, November 19, 11
  62. 62. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APISSaturday, November 19, 11
  63. 63. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APIS IF VENDORS FOLLOW THEM, WE CAN JUST USE PROPRIETARY HALSSaturday, November 19, 11
  64. 64. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APIS IF VENDORS FOLLOW THEM, WE CAN JUST USE PROPRIETARY HALS IF THEY DO NOT, IT WILL BE A MIX OF:Saturday, November 19, 11
  65. 65. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APIS IF VENDORS FOLLOW THEM, WE CAN JUST USE PROPRIETARY HALS IF THEY DO NOT, IT WILL BE A MIX OF: REFERENCE DESIGNSSaturday, November 19, 11
  66. 66. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APIS IF VENDORS FOLLOW THEM, WE CAN JUST USE PROPRIETARY HALS IF THEY DO NOT, IT WILL BE A MIX OF: REFERENCE DESIGNS INTUITIONSaturday, November 19, 11
  67. 67. HARDWARE ABSTRACTION LAYERS THEY LIVE BETWEEN THE FRAMEWORK AND THE KERNEL LIGHTS, GPS, GRALLOC + OVERLAY, AUDIO, CAMERA, SENSORS A SET OF WELL-DEFINED APIS IF VENDORS FOLLOW THEM, WE CAN JUST USE PROPRIETARY HALS IF THEY DO NOT, IT WILL BE A MIX OF: REFERENCE DESIGNS INTUITION REVERSE ENGINEERINGSaturday, November 19, 11
  68. 68. SOLVING HAL API BREAKS OUR HEADER VENDOR’S HEADER CLASS CAMERAHARDWAREINTERFACE { CLASS CAMERAHARDWAREINTERFACE { VOID STARTCAMERA(); VOID STOPCAMERA(); VOID STOPCAMERA(); VOID STARTCAMERA(); } }Saturday, November 19, 11
  69. 69. SOLVING HAL API BREAKS OUR HEADER VENDOR’S HEADER CLASS CAMERAHARDWAREINTERFACE { CLASS CAMERAHARDWAREINTERFACE { VOID STARTCAMERA(); 0X04 VOID STOPCAMERA(); VOID STOPCAMERA(); 0X08 VOID STARTCAMERA(); } }Saturday, November 19, 11
  70. 70. SOLVING HAL API BREAKS OUR HEADER VENDOR’S HEADER CLASS CAMERAHARDWAREINTERFACE { CLASS CAMERAHARDWAREINTERFACE { VOID STARTCAMERA(); 0X04 VOID STOPCAMERA(); 0X04 VOID STOPCAMERA(); 0X08 VOID STARTCAMERA(); 0X08 } }Saturday, November 19, 11
  71. 71. SOLVING HAL API BREAKS OUR HEADER VENDOR’S HEADER CLASS CAMERAHARDWAREINTERFACE { CLASS CAMERAHARDWAREINTERFACE { VOID STARTCAMERA(); 0X04 VOID STOPCAMERA(); 0X04 VOID STOPCAMERA(); 0X08 VOID STARTCAMERA(); 0X08 } } CAMERAHARDWAREINTERFACE *HW = GETHARDWARE(); HW = 0X38 HW->STARTCAMERA(); (*(0X38+0X04))();Saturday, November 19, 11
  72. 72. #@#”!#$!”””!!!!!Saturday, November 19, 11
  73. 73. SOLVING HAL BREAKSSaturday, November 19, 11
  74. 74. SOLVING HAL BREAKS COMPARE A KNOWN SOURCE WITH THE BINARY BLOB NOTE DOWN THE OFFSETS FOR METHOD CALLS ORDER THE HEADER APPROPRIATELYSaturday, November 19, 11
  75. 75. SOLVING HAL BREAKS COMPARE A KNOWN SOURCE WITH THE BINARY BLOB NOTE DOWN THE OFFSETS FOR METHOD CALLS ORDER THE HEADER APPROPRIATELYSaturday, November 19, 11
  76. 76. SOLVING HAL BREAKS COMPARE A KNOWN SOURCE WITH THE BINARY BLOB NOTE DOWN THE OFFSETS FOR METHOD CALLS ORDER THE HEADER APPROPRIATELY VENDORS COULD EASILY AVOID BREAKING HALS: ADD METHODS TO THE END OF HEADERS STOP REORDERING THEM!Saturday, November 19, 11
  77. 77. FOR SONY ERICSSONSaturday, November 19, 11
  78. 78. FOR SONY ERICSSON MOST OF THE HALS WERE GREAT BUT THEY BROKE THE CAMERA API REORDERING THE METHODS AFTER REVERSE ENGINEERING FIXED ITSaturday, November 19, 11
  79. 79. FOR SONY ERICSSON MOST OF THE HALS WERE GREAT BUT THEY BROKE THE CAMERA API REORDERING THE METHODS AFTER REVERSE ENGINEERING FIXED IT ONCE THE HEADER IS REVERSED, WE ADD IT TO THE DEVICE REPOSITORY HEADERS ARE COMMON FOR ALL DEVICES IF YOU CHANGE THE GLOBAL ONE, THINGS WILL BREAK.Saturday, November 19, 11
  80. 80. FOR SONY ERICSSON 8255 SOC FROM QUALCOMM 7X30 FAMILY, ALREADY SUPPORTED IN CYANOGENMOD CUSTOM LIGHTS HAL REMEMBER THE 32-BIT DISPLAY? GRALLOC DID TOO PRECOMPILED BLOBS FOR GPS, SENSORS AND CAMERA SOMETIMES YOU JUST DON’T HAVE A CHOICESaturday, November 19, 11
  81. 81. CONCLUSIONSSaturday, November 19, 11
  82. 82. CONCLUSIONS PORTING A DEVICE IS NOT IMPOSSIBLESaturday, November 19, 11
  83. 83. CONCLUSIONS PORTING A DEVICE IS NOT IMPOSSIBLE YOU CAN’T BREAK OTHER DEVICES THIS IS REALLY HARD!Saturday, November 19, 11
  84. 84. CONCLUSIONS PORTING A DEVICE IS NOT IMPOSSIBLE YOU CAN’T BREAK OTHER DEVICES THIS IS REALLY HARD! IF THERE IS PLATFORM SUPPORT FOR YOUR DEVICE, SUPPORT CAN BE ADDED IN A FEW HOURS SOMETIMES AS FEW AS 15 MINUTESSaturday, November 19, 11
  85. 85. CONCLUSIONS PORTING A DEVICE IS NOT IMPOSSIBLE YOU CAN’T BREAK OTHER DEVICES THIS IS REALLY HARD! IF THERE IS PLATFORM SUPPORT FOR YOUR DEVICE, SUPPORT CAN BE ADDED IN A FEW HOURS SOMETIMES AS FEW AS 15 MINUTES ALWAYS CHECK OUT SIMILAR DEVICES THE SAME SOC MEANS IT WILL BE SIMILARSaturday, November 19, 11
  86. 86. YOUR QUESTIONS PART FOURSaturday, November 19, 11

×