diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..14bbb48 --- /dev/null +++ b/README.en.md @@ -0,0 +1,221 @@ +# Amlogic boot scripts for Armbian + +**Language / Idioma:** [🟢 English](README.en.md) | [Português](README.md) + +## Table of Contents +- [Overview](#overview) +- [Setup](#setup) +- [Supported Devices](#supported-devices) +- [Advanced - Bootloader Customization](#advanced---bootloader-customization) + +## Overview + +The Armbian images for Amlogic TV Boxes use secondary, chain loaded u-boot blobs to boot mainline kernel images. +The vendor u-boot bootloaders can however boot mainline Linux perfectly without them. So they are not needed. + +All it takes are some simple modifications of some of the Armbian u-boot scripts. + +## Setup +assumption: you have vendor u-boot (the one that came with the box) running on eMMC. If you don't, you can just restore the stock Android image with Amlogic USB Burning tool. + ++ **Step 1:** Download latest Armbian for s9xxx-box, let's use [bookworm minimal](https://dl.armbian.com/aml-s9xx-box/Bookworm_current_minimal) ++ **Step 2:** Burn the image to a USB flash drive ++ **Step 3:** Copy the modified boot scripts (**[aml_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/aml_autoscript)**, **[s905_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/s905_autoscript)**, **[emmc_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/emmc_autoscript)** ) to the fat partition on the USB drive. Overwrite the existing files. ++ **Step 4:** If you have a GXBB (S905) or GXL (S905X/W/L) soc, you also need **[gxl-fixup.scr](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/gxl-fixup.scr)** ++ **Step 5:** Add an armbianEnv.txt file with the following content (file is also on github): +```bash +extraargs=earlycon=meson,0xfe07a000 console=ttyS0,921600n8 rootflags=data=writeback rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 watchdog.stop_on_reboot=0 pd_ignore_unused clk_ignore_unused rootdelay=5 +bootlogo=false +verbosity=7 +usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u +console=both + +# DTB file for this tvbox +# fdtfile=amlogic/meson-gxl-s905x-nexbox-a95x.dtb +fdtfile=amlogic/meson-sm1-x96-air-gbit.dtb + +# set this to the UUID of the root partition (value can be found +# in /extlinux/extlinux.conf after APPEND root= or with blkid) +rootdev=UUID=92139c84-3871-41d7-a3f2-e8a943cbfa87 + +# Enable ONLY for gxbb (S905) / gxl (S905X/L/W) to create fake u-boot header +#soc_fixup=gxl- +``` ++ **Step 6:** Change *fdtfile* to the DTB for your box. ++ **Step 7:** (optional since version 3:) Change *rootdev* to the right UUID for the rootfs for your image or change to /dev/sda2 when booting from USB or /dev/mmcblk0p2 when booting from SDCARD ++ **Step 8:** Only if your box has a GXBB (S905) or GXL (S905X/W/L) soc, uncomment the line *soc_fixup=gxl-* ++ **Step 9:** Power off the the box. ++ **Step 10:** Put the USB disk in your box. ++ **Step 11:** Push the reset button and hold the button ++ **Step 12:** power up your box while holding the reset button for approx 7 seconds. ++ **Step 13:** If you're lucky, it will now boot Armbian with a mainline kernel. Without any secondary u-boot blobs. + +## Supported Devices + +**✅ Fully Tested & Working:** +- S905X, S905W, S912, S905X2, S922X, S905X3, S905X4 (HTV H8) + +**⚠️ Partial Support:** +- S905: Boots only on first attempt (known limitation) + +**❓ Untested:** +- S905W2: Likely compatible but untested (not currently supported by Armbian kernel) + +All used files and source files can be found on [Github](https://github.com/projetotvbox/amlogic-bootscripts-Armbian). + +--- + +## Advanced - Bootloader Customization + +### ⚠️ Disclaimer & Prerequisites + +**DISCLAIMER:** Modifying your device's bootloader can result in a bricked device. Any damage or data loss is your sole responsibility. Proceed only if you understand the risks. + +**Required Prerequisites:** + +- **Functional ARM Linux System:** Armbian, Debian, or Ubuntu ARM running from USB/SD on your Amlogic device + - Necessary to access internal eMMC and run analysis/extraction commands + - System must boot correctly to provide shell access + +- **Serial TTL Adapter (3.3V UART):** High-quality USB serial adapter + - ⚠️ **CRITICAL:** Use 3.3V only. 5V will damage the device! + - Requires soldering skills to connect TX/RX/GND to the board + +- **Serial Terminal Software:** PuTTY, Minicom, or picocom + +- **Patience & Methodology:** Follow each step carefully + +### 🔒 Mandatory: Backup Your eMMC + +Before ANY experiment, create a complete backup: + +```bash +# Bit-by-bit backup with compression (saves space) +sudo dd if=/dev/mmcblkX bs=1M status=progress | gzip -c > backup_emmc_full.img.gz + +# To restore in case of disaster: +# gunzip -c backup_emmc_full.img.gz | sudo dd of=/dev/mmcblkX bs=1M status=progress +``` + +Why gzip? A 16GB backup becomes 2-4GB, saving significant space. + +### Checking Vendor Bootloader Support + +#### Step 1: Connect Serial Cable +Solder TX, RX, GND to your device's UART pads and connect to your PC. + +#### Step 2: Open Serial Console +Using picocom as example: + +```bash +# Find your serial device +ls -la /dev/ttyUSB* + +# Connect at 115200 baud (adjust if different) +picocom -b 115200 /dev/ttyUSB0 + +# Or with minicom: +minicom -D /dev/ttyUSB0 -b 115200 +``` + +#### Step 3: Interrupt U-Boot +Power on the device and quickly press `Ctrl+C` or `Enter` to interrupt U-Boot before it boots. + +#### Step 4: Check Bootloader Variables +Once in U-Boot console, type: + +```bash +printenv bootcmd +``` + +Expected output should be similar to: +``` +bootcmd=run start_autoscript; run storeboot +``` + +Check for related variables: +```bash +printenv start_usb_autoscript +printenv start_mmc_autoscript +printenv start_emmc_autoscript +``` + +**Note:** Variable names may differ slightly. Look for patterns like `start_*_autoscript`. + +### Modifying Vendor Bootloader (Advanced Users Only) + +If your bootloader is writable and you want to force script support, execute these commands in U-Boot console: + +```bash +setenv start_autoscript 'if mmcinfo; then run start_mmc_autoscript; fi; if usb start; then run start_usb_autoscript; fi; run start_emmc_autoscript' +setenv start_emmc_autoscript 'if fatload mmc 1 1020000 emmc_autoscript; then setenv devtype "mmc"; setenv devnum 1; autoscr 1020000; fi;' +setenv start_mmc_autoscript 'if fatload mmc 0 1020000 s905_autoscript; then setenv devtype "mmc"; setenv devnum 0; autoscr 1020000; fi;' +setenv start_usb_autoscript 'for usbdev in 0 1 2 3; do if fatload usb ${usbdev} 1020000 s905_autoscript; then setenv devtype "usb"; setenv devnum 0; autoscr 1020000; fi; done' +setenv bootdelay 1 +``` + +#### ⚠️ CRITICAL: Setting bootcmd - Preserve Your Original Command + +**DO NOT simply use `run start_autoscript; run storeboot`** - This is generic and may brick your device if your original bootcmd was different! + +**Step-by-step approach:** + +1. **First, WRITE DOWN your original bootcmd:** + ```bash + printenv bootcmd + # Write down the EXACT output here: + # _________________________________ + ``` + +2. **Then set bootcmd to preserve it:** + ```bash + setenv bootcmd 'run start_autoscript; [PASTE YOUR ORIGINAL BOOTCMD HERE]' + ``` + +**Examples from real devices:** + +**Example 1 - Generic Amlogic Box:** +```bash +# Original was: +# bootcmd=run storeboot + +# So you do: +setenv bootcmd 'run start_autoscript; run storeboot' +``` + +**Example 2 - Different Vendor (HTV H8):** +```bash +# Original was: +# bootcmd=run start_emmc_autoscript; run storeboot + +# So you do: +setenv bootcmd 'run start_autoscript; run start_emmc_autoscript; run storeboot' +``` + +**Example 3 - Complex Bootcmd:** +```bash +# Original was: +# bootcmd=if test -n ${upgrade_step}; then echo BOOT_STEP equals $upgrade_step; setenv upgrade_step; fi; run storeboot + +# So you do: +setenv bootcmd 'run start_autoscript; if test -n ${upgrade_step}; then echo BOOT_STEP equals $upgrade_step; setenv upgrade_step; fi; run storeboot' +``` + +#### Final step - Save & Verify Changes + +```bash +saveenv +reset +``` + +Interrupt U-Boot again and verify variables were saved: + +```bash +printenv bootcmd +``` + +**Success indicators:** +- Variables were saved → Bootloader is writable and modifications should work +- Variables weren't saved → Read-only bootloader; cannot apply this method + +--- diff --git a/README.md b/README.md index f6d8dce..7a60b75 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,221 @@ -# Amlogic boot scripts for Armbian +# Scripts de Boot do Amlogic para Armbian -The Armbian images for Amlogic TV Boxes use secondary, chain loaded u-boot blobs to boot mainline kernel images. -The vendor u-boot bootloaders can however boot mainline Linux perfectly without them. So they are not needed. +**Language / Idioma:** [🟢 Português](README.md) | [English](README.en.md) -All it takes are some simple modifications of some of the Armbian u-boot scripts. +## Índice +- [Visão Geral](#visão-geral) +- [Configuração](#configuração) +- [Dispositivos Suportados](#dispositivos-suportados) +- [Avançado - Personalização do Bootloader](#avançado---personalização-do-bootloader) -# Setup -assumption: you have vendor u-boot (the one that came with the box) running on eMMC. If you don't, you can just restore the stock Android image with Amlogic USB Burning tool. +## Visão Geral -+ **Step 1:** Download latest Armbian for s9xxx-box, let's use [bookworm minimal](https://dl.armbian.com/aml-s9xx-box/Bookworm_current_minimal) -+ **Step 2:** Burn the image to a USB flash drive -+ **Step 3:** Copy the modified boot scripts (**[aml_autoscript](https://github.com/devmfc/amlogic-bootscripts-Armbian/blob/main/aml_autoscript)**, **[s905_autoscript](https://github.com/devmfc/amlogic-bootscripts-Armbian/blob/main/s905_autoscript)**, **[emmc_autoscript](https://github.com/devmfc/amlogic-bootscripts-Armbian/blob/main/emmc_autoscript)** ) to the fat partition on the USB drive. Overwrite the existing files. -+ **Step 4:** If you have a GXBB (S905) or GXL (S905X/W/L) soc, you also need **[gxl-fixup.scr](https://github.com/devmfc/amlogic-bootscripts-Armbian/blob/main/gxl-fixup.scr)** -+ **Step 5:** Add an armbianEnv.txt file with the following content (file is also on github): +As imagens do Armbian para TV Boxes Amlogic usam blobs secundários de u-boot carregados em cadeia para inicializar imagens do kernel mainline. +Os bootloaders u-boot do fabricante, no entanto, podem inicializar o Linux mainline perfeitamente sem eles. Portanto, eles não são necessários. + +Tudo o que é necessário são algumas modificações simples em alguns dos scripts u-boot do Armbian. + +## Configuração +Pressuposição: você tem o u-boot do fabricante (o que veio com a box) rodando na eMMC. Se não, você pode restaurar a imagem Android original com a ferramenta Amlogic USB Burning. + ++ **Passo 1:** Baixe a versão mais recente do Armbian para s9xxx-box, vamos usar [bookworm minimal](https://dl.armbian.com/aml-s9xx-box/Bookworm_current_minimal) ++ **Passo 2:** Grave a imagem em um pendrive USB ++ **Passo 3:** Copie os scripts de boot modificados (**[aml_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/aml_autoscript)**, **[s905_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/s905_autoscript)**, **[emmc_autoscript](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/emmc_autoscript)** ) para a partição FAT no pendrive. Sobrescreva os arquivos existentes. ++ **Passo 4:** Se você tem um SoC GXBB (S905) ou GXL (S905X/W/L), você também precisa de **[gxl-fixup.scr](https://github.com/projetotvbox/amlogic-bootscripts-Armbian/blob/main/gxl-fixup.scr)** ++ **Passo 5:** Adicione um arquivo armbianEnv.txt com o seguinte conteúdo (o arquivo também está no github): ```bash -extraargs=earlycon rootflags=data=writeback rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 +extraargs=earlycon=meson,0xfe07a000 console=ttyS0,921600n8 rootflags=data=writeback rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 watchdog.stop_on_reboot=0 pd_ignore_unused clk_ignore_unused rootdelay=5 bootlogo=false verbosity=7 usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u console=both -# DTB file for this tvbox +# Arquivo DTB para este TV Box # fdtfile=amlogic/meson-gxl-s905x-nexbox-a95x.dtb fdtfile=amlogic/meson-sm1-x96-air-gbit.dtb -# set this to the UUID of the root partition (value can be found -# in /extlinux/extlinux.conf after APPEND root= or with blkid) +# defina isto para o UUID da partição raiz (o valor pode ser encontrado +# em /extlinux/extlinux.conf depois de APPEND root= ou com blkid) rootdev=UUID=92139c84-3871-41d7-a3f2-e8a943cbfa87 -# Enable ONLY for gxbb (S905) / gxl (S905X/L/W) to create fake u-boot header +# Ativar APENAS para gxbb (S905) / gxl (S905X/L/W) para criar cabeçalho u-boot falso #soc_fixup=gxl- ``` -+ **Step 6:** Change *fdtfile* to the DTB for your box. -+ **Step 7:** (optional since version 3:) Change *rootdev* to the right UUID for the rootfs for your image or change to /dev/sda2 when booting from USB or /dev/mmcblk0p2 when booting from SDCARD -+ **Step 8:** Only if your box has a GXBB (S905) or GXL (S905X/W/L) soc, uncomment the line *soc_fixup=gxl-* -+ **Step 9:** Power off the the box. -+ **Step 10:** Put the USB disk in your box. -+ **Step 11:** Push the reset button and hold the button -+ **Step 12:** power up your box while holding the reset button for approx 7 seconds. -+ **Step 13:** If you're lucky, it will now boot Armbian with a mainline kernel. Without any secondary u-boot blobs. ++ **Passo 6:** Altere *fdtfile* para o DTB da sua box. ++ **Passo 7:** (opcional desde a versão 3:) Altere *rootdev* para o UUID correto do rootfs para sua imagem ou mude para /dev/sda2 quando inicializar do USB ou /dev/mmcblk0p2 quando inicializar do SDCARD ++ **Passo 8:** Apenas se sua box tiver um SoC GXBB (S905) ou GXL (S905X/W/L), descomente a linha *soc_fixup=gxl-* ++ **Passo 9:** Desligue a box. ++ **Passo 10:** Coloque o disco USB na sua box. ++ **Passo 11:** Pressione o botão reset e mantenha pressionado ++ **Passo 12:** Ligue a box enquanto mantém o botão reset pressionado por aproximadamente 7 segundos. ++ **Passo 13:** Se você tiver sorte, agora ele inicializará o Armbian com um kernel mainline. Sem nenhum blob u-boot secundário. + +## Dispositivos Suportados + +**✅ Totalmente Testado e Funcionando:** +- S905X, S905W, S912, S905X2, S922X, S905X3, S905X4 (HTV H8) + +**⚠️ Suporte Parcial:** +- S905: Inicia apenas na primeira tentativa (limitação conhecida) + +**❓ Não Testado:** +- S905W2: Provavelmente compatível mas não testado (não suportado atualmente pelo kernel do Armbian) + +Todos os arquivos usados e arquivos de origem podem ser encontrados no [Github](https://github.com/projetotvbox/amlogic-bootscripts-Armbian). + +--- + +## Avançado - Personalização do Bootloader -All used files and source files can be found on [Github](https://github.com/devmfc/amlogic-bootscripts-Armbian). +### ⚠️ Aviso Legal & Pré-requisitos + +**AVISO:** Modificar o bootloader do seu dispositivo pode resultar em um dispositivo travado (brick). Qualquer dano ou perda de dados é de sua responsabilidade exclusiva. Proceda apenas se entender os riscos. + +**Pré-requisitos Obrigatórios:** + +- **Sistema ARM Linux Funcional:** Armbian, Debian ou Ubuntu ARM rodando a partir de USB/SD no seu dispositivo Amlogic + - Necessário para acessar a eMMC interna e executar comandos de análise/extração + - O sistema deve inicializar corretamente para fornecer acesso shell + +- **Adaptador Serial TTL (3.3V UART):** Adaptador série USB de alta qualidade + - ⚠️ **CRÍTICO:** Use apenas 3.3V. 5V danificará o dispositivo! + - Requer habilidades de soldagem para conectar TX/RX/GND na placa + +- **Software de Terminal Serial:** PuTTY, Minicom ou picocom -This is tested on S905X, S905W, S912, S905X2, S922X, S905X3 and they all boot the kernel. -I did test S905 also, but it boots only the first time for some reason. -It will probably also work for S905X4 and S905W2, but did not test those. They are not supported by the Armbian kernel at this moment anyway. +- **Paciência e Metodologia:** Siga cada passo cuidadosamente + +### 🔒 Obrigatório: Faça Backup da sua eMMC + +Antes de QUALQUER experimento, crie um backup completo: + +```bash +# Backup bit-a-bit com compressão (economiza espaço) +sudo dd if=/dev/mmcblkX bs=1M status=progress | gzip -c > backup_emmc_full.img.gz + +# Para restaurar em caso de desastre: +# gunzip -c backup_emmc_full.img.gz | sudo dd of=/dev/mmcblkX bs=1M status=progress +``` + +Por que gzip? Um backup de 16GB se torna 2-4GB, economizando espaço significativo. + +### Verificando o Suporte do Bootloader do Fabricante + +#### Passo 1: Conectar Cabo Serial +Solde TX, RX, GND nos pads UART do seu dispositivo e conecte ao seu PC. + +#### Passo 2: Abrir Console Serial +Usando picocom como exemplo: + +```bash +# Encontre seu dispositivo serial +ls -la /dev/ttyUSB* + +# Conecte a 115200 baud (ajuste se diferente) +picocom -b 115200 /dev/ttyUSB0 + +# Ou com minicom: +minicom -D /dev/ttyUSB0 -b 115200 +``` + +#### Passo 3: Interromper U-Boot +Ligue o dispositivo e pressione rapidamente `Ctrl+C` ou `Enter` para interromper o U-Boot antes de inicializar. + +#### Passo 4: Verificar Variáveis do Bootloader +Uma vez no console do U-Boot, digite: + +```bash +printenv bootcmd +``` + +A saída esperada deve ser semelhante a: +``` +bootcmd=run start_autoscript; run storeboot +``` + +Verifique as variáveis relacionadas: +```bash +printenv start_usb_autoscript +printenv start_mmc_autoscript +printenv start_emmc_autoscript +``` + +**Nota:** Os nomes das variáveis podem ser ligeiramente diferentes. Procure por padrões como `start_*_autoscript`. + +### Modificando Bootloader do Fabricante (Apenas Usuários Avançados) + +Se seu bootloader é gravável e você quer forçar o suporte a scripts, execute esses comandos no console do U-Boot: + +```bash +setenv start_autoscript 'if mmcinfo; then run start_mmc_autoscript; fi; if usb start; then run start_usb_autoscript; fi; run start_emmc_autoscript' +setenv start_emmc_autoscript 'if fatload mmc 1 1020000 emmc_autoscript; then setenv devtype "mmc"; setenv devnum 1; autoscr 1020000; fi;' +setenv start_mmc_autoscript 'if fatload mmc 0 1020000 s905_autoscript; then setenv devtype "mmc"; setenv devnum 0; autoscr 1020000; fi;' +setenv start_usb_autoscript 'for usbdev in 0 1 2 3; do if fatload usb ${usbdev} 1020000 s905_autoscript; then setenv devtype "usb"; setenv devnum 0; autoscr 1020000; fi; done' +setenv bootdelay 1 +``` + +#### ⚠️ CRÍTICO: Configurando bootcmd - Preserve Seu Comando Original + +**NÃO use simplesmente `run start_autoscript; run storeboot`** - Isto é genérico e pode danificar seu dispositivo se seu bootcmd original foi diferente! + +**Abordagem passo-a-passo:** + +1. **Primeiro, ANOTE seu bootcmd original:** + ```bash + printenv bootcmd + # Anote a saída EXATA aqui: + # _________________________________ + ``` + +2. **Então configure bootcmd para preservá-lo:** + ```bash + setenv bootcmd 'run start_autoscript; [COLE SEU BOOTCMD ORIGINAL AQUI]' + ``` + +**Exemplos de dispositivos reais:** + +**Exemplo 1 - Box Amlogic Genérica:** +```bash +# Original era: +# bootcmd=run storeboot + +# Então você faz: +setenv bootcmd 'run start_autoscript; run storeboot' +``` + +**Exemplo 2 - Fabricante Diferente (HTV H8):** +```bash +# Original era: +# bootcmd=run start_emmc_autoscript; run storeboot + +# Então você faz: +setenv bootcmd 'run start_autoscript; run start_emmc_autoscript; run storeboot' +``` + +**Exemplo 3 - Bootcmd Complexo:** +```bash +# Original era: +# bootcmd=if test -n ${upgrade_step}; then echo BOOT_STEP equals $upgrade_step; setenv upgrade_step; fi; run storeboot + +# Então você faz: +setenv bootcmd 'run start_autoscript; if test -n ${upgrade_step}; then echo BOOT_STEP equals $upgrade_step; setenv upgrade_step; fi; run storeboot' +``` + +#### Passo Final - Salve e Verifique as Alterações + +```bash +saveenv +reset +``` + +Interrompa o U-Boot novamente e verifique se as variáveis foram salvas: + +```bash +printenv bootcmd +``` + +**Indicadores de Sucesso:** +- Variáveis foram salvas → Bootloader é gravável e as modificações devem funcionar +- Variáveis não foram salvas → Bootloader somente leitura; não é possível aplicar este método + +--- diff --git a/armbianEnv.txt b/armbianEnv.txt index dfb3439..f9ff5db 100644 --- a/armbianEnv.txt +++ b/armbianEnv.txt @@ -1,4 +1,4 @@ -extraargs=earlycon rootflags=data=writeback rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 +extraargs=earlycon=meson,0xfe07a000 console=ttyS0,921600n8 rootflags=data=writeback rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 watchdog.stop_on_reboot=0 pd_ignore_unused clk_ignore_unused rootdelay=5 bootlogo=false verbosity=7 usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u @@ -14,6 +14,4 @@ fdtfile=amlogic/meson-sm1-x96-air-gbit.dtb #rootdev=LABEL=armbi_root # Enable ONLY for gxbb (S905) / gxl (S905X/L/W) to create fake u-boot header -#soc_fixup=gxl- - - +#soc_fixup=gxl- \ No newline at end of file