# wdmc-gen2 **Repository Path**: hgr2004/wdmc-gen2 ## Basic Information - **Project Name**: wdmc-gen2 - **Description**: WDMC-Gen2 的构建工具 基于 Marvell ARMADA 375 的 WD My Cloud Gen2 运行主线内核和 Debian 的一切 - **Primary Language**: Shell - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-27 - **Last Updated**: 2024-05-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # build tools for wdmc-gen2 ## WD My Cloud Gen2 based on Marvell ARMADA 375 此存储库包含用于构建您自己的 linux 内核、ramdisk 和 debian 以运行 WD MyCloud Gen2 驱动器的文档和源代码。它也可以用作起点,让类似的设备运行,或者只是了解一般的 linux 启动。 包括什么? 运行主线内核和 Debian 的一切 设备树源 ./dts/armada-375-wdmc-gen2.dts 各种内核的内核配置 (check ./config/) TXT 文件中的一些调整和指针 ./docs/ 用于构建旧内核的工具链包含在 txz ./toolchain/ 中。我建议通过 apt 使用 gcc-arm-none-eabi 工具链! 构建脚本,用于构建内核、虚拟硬盘并 debootstrap Debian 系统 设备的一些修复/自定义 用于就地更新虚拟硬盘的脚本 如何使用? 克隆存储库,运行 build.sh,选择所需的选项,部署到 WDMC2。 构建的先决条件将由 build.sh 自动安装。 buildscript 是在 Ubuntu Jammy 上开发和测试的,gcc-arm-none-eabi 托管在 VirtualBox 中,使用较旧的 debian/ubuntu 版本或 wsl(2) 时存在已知问题 apt-get install build-essential bc libncurses5 dialog u-boot-tools git libncurses-dev lib32z1 lib32ncurses5-dev libmpc-dev libmpfr-dev libgmp3-dev flex bison debootstrap debian-archive-keyring qemu-user-static 适用于 ARM EABI 的 GCC apt-get install gcc-arm-none-eabi 或者(仅在上述不起作用的情况下使用) 将 gcc/glibc 存档从工具链解压缩到 /opt 在 build.sh 中调整 GCC 的路径 build.sh 提供了一种构建内核、rootfs 和 uRamdisk 的方法 以 root 身份运行 build.sh(或使用 sudo) 脚本将使用对话框询问功能和配置 跳过对话框的可能参数包括: --kernel 要选择内核构建: --kernelbranch {branch} 从 kernel.org 中选择内核分支 --clean 在编译内核之前重置和获取 Git(删除可能的更改) --config 使用 menuconfig 允许用户自定义内核 --rootfs 要选择 rootfs 创建: --release {debianrelease} 选择要用作 rootfs 的 Debian 发行版 --changes 在卸载和打包之前暂停并等待 rootfs 中的更改(这允许您进行自定义) --initramfs 在 rootfs 中创建新的 initramfs --root-pw {rootpw} 为新 RootFs 选择 root PW --hostname {host} 为新 rootfs 选择主机名 --zram 通过 ZRAM 启用日志记录和交换 --boot {usb/hdd} 选择要使用的 FSTAB(用于从 USB 或 HDD 启动) 如果未给出参数,则使用默认值或提示用户 如果构建 rootfs build.sh 将包含来自 ./tweaks/ 的调整,您可以在那里调整 fstab 和其他各种内容,文件将直接复制到 rootfs 根据所选操作,脚本将: 对于内核: git clone 并检出内核 将 kernel-config 和 device tree 插入到内核中 尝试使用 MenuConfig 制作它 将 dtb 附加到 zImage,然后附加到 mkimage 将结果放在 ./output/boot 和 ./output/modules 中 对于 rootfs: 使用 debootstrap 在 ./output/rootfs/ 中生成 Debian rootfs 通过APT应用调整并设置一些有用的程序 将内核制作的结果复制到正确的文件夹(boot 和 lib)中 如果启用了 Building InitramFS,它还将: 在chroot中运行build_initramfs.sh并生成新的uRamdisk 将 rootfs 打包到tar.gz中,以便您可以轻松地将其提取到 USB/HDD 上 build_initramfs.sh 此脚本构建最小的 initramfs 可以直接在 wdmc 上运行并将输出放入 /boot 可以在 chroot 中使用来预编译 uRamdisk。这就是 build.sh 使用它的方式 生成的uRamdisk可以从内核命令行、U盘第2分区、硬盘第3分区启动 如何安装? 要在 wdmc 上使用预构建版本,您必须决定是使用 USB 驱动器还是内部驱动器。 USB(建议使用 USB 2.0 记忆棒,USB 3.0 重启时确实有问题): 创建一个 FAT32 分区(这将用于引导,将称为 sdb1) 创建一个 ext4 分区(这将用作 root,将称为 sdb2) 提取 SDB1 (FAT32) 分区上的boot-5.x.x.tar.gz 提取 SDB2 (ext4) 分区上的bullseye-rootfs.tar.gz 调整 sdb2/etc/fstab 以满足您的需求(可能没问题) 使用 U 盘启动 WDMC,root 密码为“1234” 调整时间和日期,使用 hwclock --systohc 更新 RTC 根据需要配置/添加包 内部: 确保驱动器使用的是 GPT 创建根 ext4 分区作为 SDA3 在原始 WD firmare 中,这需要是 /dev/sda3(因为 sda1 是交换和 sda2 数据) 新的 uRamdisk 也支持从 /dev/sda1 引导(尽管这是未经测试的,可能不起作用) 提取根bullseye-rootfs.tar.gz 调整 sda3/etc/fstab 以满足您的需求(至少检查一下! 引导 WDMC,root 密码为“1234” 根据需要配置/添加软件包 调整时间和日期,使用 hwclock --systohc 更新 RTC 根据需要配置/添加包 我建议从 U 盘开始,因为这不需要更改内部硬盘。 如果您需要自定义 initramfs 或其他内核设置,请检查代码并自行构建必要的文件。 WDMC 如何启动? 本节介绍 wdmc 的引导过程,它可能有助于理解为什么需要上述步骤或引导工作原理。 U-Boot阶段: U-boot(在内部闪存上)加载,开始执行和硬件初始化 寻找正确的启动介质。它检查: USB 上的第一个分区 SATA上的第三个分区 网络TFTP 如果在上述位置,文件夹调用 boot 找到,它尝试加载 uImage uRamdisk的 之后执行传递给 uImage 中的 linux 内核 内核加载,进一步初始化系统,然后将控制权传递给 uRamdisk。 uRamdisk阶段: uRamdisk 包含 busybox 一个小 shell。这用于设置包含 /dev/ /proc/ /sys/ 的基本 linux 系统 尝试挂载完整的 Debian 根目录,因此它尝试挂载以下目标 任何作为“根”传递给内核的内容 /dev/sdb2(所以 USB 上的第二个分区) /dev/sda1 (所以是 sata 上的第一个分区) /dev/sda3 (所以是 sata 上的第三个分区) 如果没有找到合适的根,它会通过救援外壳将控制权交给用户 如果安装成功,它会设置 LED 触发器、MAC 地址并运行switch_root以加载真实系统 Debian 阶段: Debian 启动。 如何调试? 如果您在任何时候遇到困难,访问启动日志并观看 uboot 和 uRamdisk 执行其操作真的很有帮助。您可以将 3.3V USB 串行转换器(通常也称为 FTDI 分支或 USB2UART)连接到 wdmc 上的 UART 引脚。wdmc 使用 115200b8n1,数据线上有 3.3V 上拉电压。使用下图作为参考(同时检查 docs 文件夹! 图像 由于: AllesterFox ( http://anionix.ddns.net/WDMyCloud/WDMyCloud-Gen2/http://anionix.ddns.net/WDMyCloud/WDMyCloud-Gen2/) Johns Q https://github.com/Johns-Q/wdmc-gen2 表彰他们在 wdmc-gen2 上的原创工作 ARMBIAN ( https://github.com/armbian/build ) 的出色构建脚本提供了大量灵感和 zram 配置:) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=HXWRU82YBV7HC&source=url) This repository contains documentation and sources to build your own linux kernel, ramdisk and debian to run a WD MyCloud Gen2 drive. It can also be used as a starting point, to get similar devices running or just learn about linux booting in general. ### Whats included? * everything to run a mainline kernel and debian - device tree source ./dts/armada-375-wdmc-gen2.dts - kernel config for various kernels (check ./config/) - some tweaks and pointers in txt files ./docs/ - toolchain for building old kernels is included as txz ./toolchain/ . I suggest using the gcc-arm-none-eabi toolchain via apt! - a build script to build the kernel, ramdisk and debootstrap a debian system - some fixes/customisation for the device - a script to update the ramdisk in place ### How to use? * clone repository, run build.sh, select the options you want, deploy to wdmc2. * prerequisites for building will be installed by build.sh automatically. - buildscript has been developed and tested on Ubuntu Jammy with gcc-arm-none-eabi hosted in a VirtualBox, there are known problems when using older debian/ubuntu releases or wsl(2) - `apt-get install build-essential bc libncurses5 dialog u-boot-tools git libncurses-dev lib32z1 lib32ncurses5-dev libmpc-dev libmpfr-dev libgmp3-dev flex bison debootstrap debian-archive-keyring qemu-user-static` - gcc for arm eabi `apt-get install gcc-arm-none-eabi` - OR (ONLY USE IF ABOVE DOES NOT WORK) - extract the gcc/glibc archive from toolchain to /opt - adjust the path to the gcc in build.sh * build.sh - provides a way of building a kernel, rootfs and uRamdisk - run build.sh as root (or with sudo) - script will use dialog to ask for features and configuration - possible parameters to skip dialogs are: - `--kernel` to select kernel building: - `--kernelbranch {branch}` to select kernel branch from kernel.org - `--clean` to reset and fetch git before compiling kernel (to remove possible changes) - `--config` to use menuconfig to allow user to customize kernel - `--rootfs` to select rootfs creation: - `--release {debianrelease}` to select the debian release to use as rootfs - `--changes` to pause and wait for changes in the rootfs before unmounting and packaging (this allows you to do customization) - `--initramfs` to create new initramfs in rootfs - `--root-pw {rootpw}` to select root pw for new rootfs - `--hostname {host}` to select hostname for new rootfs - `--zram` to enable logging and swap via ZRAM - `--boot {usb/hdd}` to select fstab to use (either for booting from usb or hdd) - if a parameters is not given, the default value is used or the user is prompted - if building a rootfs build.sh will include the tweaks from ./tweaks/ You can adjust fstab and various other stuff there, files will be copied straight to rootfs - depending on the selected actions the script will: - for the kernel: - git clone and checkout the kernel - insert kernel-config and device tree into kernel - try making it with menuconfig - attach dtb to zImage then mkimage - place the results in ./output/boot and ./output/modules - for the rootfs: - use debootstrap to generate a debian rootfs in ./output/rootfs/ - apply the tweaks and setup some useful programs via apt - copy the results from kernel making into the right folders (boot and lib) - if building initramfs is enabled it will also: - run build_initramfs.sh in the chroot and generate a new uRamdisk - pack the rootfs into a tar.gz so you can easily extract it on your usb/hdd * build_initramfs.sh - this script builds a minimal initramfs - can either be run on the wdmc directly and put the output into /boot - can be used in a chroot to precompile uRamdisk. This is how it is used by build.sh - the generated uRamdisk can boot from kernel commandline, usb-stick 2nd partition, hdd 3rd partition ### How to install? To use the prebuilt releases on your wdmc you'll have to decide wether to use a USB drive or the internal drive. ##### USB (usb 2.0 stick is recommended, usb 3.0 does have troubles rebooting): - create a FAT32 partition (this will be used to boot, will be called sdb1) - create a ext4 partition (this will be used as root, will be called sdb2) - extract boot-5.x.x.tar.gz on sdb1 (FAT32) partition - extract the bullseye-rootfs.tar.gz on the sdb2 (ext4) partition - adjust sdb2/etc/fstab to fit your needs (will probably be ok) - boot wdmc with usb stick, root password is '1234' - adjust time and date, use `hwclock --systohc` to update RTC - configure/add packages as needed ##### Internal: - make sure drive is using gpt - create root ext4 partition as sda3 - in original wd firmare this needed to be /dev/sda3 (as sda1 was swap and sda2 data) - new uRamdisk also supports booting from /dev/sda1 (though this is untested and might not work) - extract bullseye-rootfs.tar.gz on the root - adjust sda3/etc/fstab to fit your needs (check it at least!) - boot wdmc, root password is '1234' configure/add packages as needed - adjust time and date, use `hwclock --systohc` to update RTC - configure/add packages as needed - I suggest starting with USB stick, because this requires no changes on the internal harddisk. If you need custom initramfs or different kernel settings, check the code and build necessary files yourself. ### How is the WDMC booting? This section describes the boot process of the wdmc, it might help understand why the above steps are necessary or how the booting works. ##### u-boot stage: 1. u-boot (on internal flash) is loaded, starts execution and hardware initialization 2. looks for proper boot media. It checks: - first partition on usb - third partition on sata - network TFTP 3. if on the above locations a folder call `boot` is found, it tries to load - uImage - uRamdisk 4. afterwards execution is passed to the linux kernel in uImage 5. kernels loads, initializes the system further, then passes control to the uRamdisk. ##### uRamdisk stage: 6. the uRamdisk contains busybox a small shell. This is used to set up a basic linux system containing /dev/ /proc/ /sys/ 7. tries to mount the full debian root, therefore it tries to mount the following destinations - whatever is passed to the kernel as "root" - /dev/sdb2 (so second partition on usb) - /dev/sda1 (so first partition on sata) - /dev/sda3 (so third partition on sata) 8. if no suitable root is found, it hands control to the user via a rescue shell 9. if a mount was successful, it sets up the led triggers, mac address and runs switch_root to load the real system ##### debian stage: 10. debian starts. ### How to debug? If you get stuck at any point it is really helpful to access the boot log and watch uboot and the uRamdisk do its stuff. You can connect a 3.3V usb-serial converter (also often referred to as FTDI Breakout or USB2UART) to the UART pins on the wdmc. The wdmc is using 115200b8n1 with 3.3V pullups on the data lines. Use the image below for reference (also check the docs folder!) ![image](https://github.com/Heisath/wdmc2-kernel/blob/master/docs/UART_Pinout.jpg) ### Thanks to: AllesterFox (http://anionix.ddns.net/WDMyCloud/WDMyCloud-Gen2/) \ Johns Q https://github.com/Johns-Q/wdmc-gen2 for their original work on the wdmc-gen2 \ ARMBIAN (https://github.com/armbian/build) for their awesome build script which gave lots of inspiration and the zram config :) ###