17

I've messed up some files in target fs. So i would like to reassemble it. But not rebuild all.

make clean just erases all output, + build directory. What command should use to delete only target directory and all related .stamp_some_step files recursively through output/build/ structure, forcing buildroot to reassemble filesystem according to current config, but not rebuilding all libraries and binaries again and again?

xakepp35
  • 2,878
  • 7
  • 26
  • 54
  • Check my example: https://github.com/howhow/makefile – How Chen Nov 16 '17 at 11:05
  • you could delete relavent files, just build updated lib and do the link again, no need rebuild all – How Chen Nov 17 '17 at 00:07
  • How Chen, how do I determine whai is relevant, and why build root could not do this? I mean, could it clean just binaries in target and reinstall from build to target, according to its default script? not deleting build folder but target? – xakepp35 Nov 18 '17 at 12:20
  • I think make clean just a fake target named as clean, you need check under clean target, how the makefile implemented it. You want to integrate filesystem image, then you need first have a Filesystem image. Then maybe you need check your makefile how it assemble Filesystem image into whole image, then you just redo that step – How Chen Nov 18 '17 at 14:16
  • How Chen, in makefile there is just rm -rf all data in /output/ eg not only target but build and so on. so, to clean only target directory and related stamps, do i have to reimplement new 'cleantarget' target for makefile by my own? :( – xakepp35 Nov 19 '17 at 14:38
  • I think so, that what I understand, but you could also just write a script, no need modify makefile itself – How Chen Nov 21 '17 at 10:48

2 Answers2

30

Buildroot tracks build progress with .stamp_xxx in each package build dir. target install is actually the last stage for each package. So removing the .stamp_target_installed file from each package build dir would cause it to reinstall to target

In the latest buildroot, you can simply do the following:

rm -rf output/target
find output/ -name ".stamp_target_installed" -delete
rm -f output/build/host-gcc-final-*/.stamp_host_installed

In some older buildroot, there are a few other files in output that tracks the creation of the target dir with the skeleton. Citing the mailing list message, we could summarize following:

Does a "rm -rf output/target && make" work?

As Thomas said, it does not work. But, some unofficial hacks exist:

  • remove build/.root will force to reinstall skeleton
  • remove build/*/.stamp_target_installed force reinstall each target package
  • depending of you toolchain, you can reinstall libc and co by removing:
  • stamps/ext-toolchain-installed (external)
  • stamps/ct-ng-toolchain-installed (ctng)
  • target/lib/libc.so.0 (buildroot)

And then simply do make again.

Remind, there are ton of reasons these tips could do wrong things. The only current official way to rebuild target is "make clean".

Jaakko
  • 4,674
  • 2
  • 26
  • 20
Jeff Zheng
  • 416
  • 4
  • 3
  • 2
    Why no such default functional in buildroot itself, like implementing `make cleantarget` command with what you just provided? – xakepp35 Apr 16 '18 at 21:30
  • 1
    @xakepp35 send a patch! :-) Previously on mailing list: http://buildroot.uclibc.narkive.com/Kaw8KG7t/force-buildroot-to-regenerate-the-output-target-directory-tree – Ciro Santilli OurBigBook.com Sep 15 '18 at 20:18
  • 1
    @CiroSantilli新疆改造中心六四事件法轮功 Thanks Ciro, those are great hints, that may be useful. In my particular case removing `.stamp_target_installed` files and rebuilding was suffient. – xakepp35 Sep 20 '18 at 11:01
  • 1
    `output/build/.root` does not exist any more. – pevik Jun 19 '19 at 20:59
  • 2
    This doesn't seem to work with Buildroot 2020.02. Specifically I couldn't get the toolchain to reinstall, even after deleting libc.so – tmm1 Oct 08 '20 at 18:55
  • According to [this](https://patchwork.ozlabs.org/project/buildroot/patch/1430095555-8484-1-git-send-email-emeric.vigier@savoirfairelinux.com/#1082604) you may also need to `rm -f $(BUILD_DIR)/host-gcc-final-*/.stamp_host_installed` – tmm1 Oct 26 '20 at 17:43
  • Building on top of `2022.05-rc1` requires `rm -f $(BUILD_DIR)/host-gcc-final-*/.stamp_host_installed` otherwise `libstdc++.so.6` does not get installed – Jaakko May 28 '22 at 10:06
6

Buildroot has special make targets to clean out the build directory for specific packages, but this does not touch any of the installed files. To quote the user manual:

When a package is removed from the configuration, Buildroot does not do anything special. It does not remove the files installed by this package from the target root filesystem or from the toolchain sysroot. A full rebuild is needed to get rid of this package. However, generally you don’t necessarily need this package to be removed right now: you can wait for the next lunch break to restart the build from scratch.

That said, you can delete the build files for a specific package by running make <PKG-NAME>-dirclean. For example, if I wanted to delete the build files for i2c-tools, I would run make i2c-tools-dirclean. The <PKG-NAME>-dirclean target simply runs an rm -rf on the output/build/<PKG-NAME> directory. This will not remove the installed files from output/target/. If you want to remove the files from your rootfs without a full rebuild, that's fine - you can just go into output/target/, rm the files you no longer want, then run make to regenerate your final images. Make sure your Buildroot config is also not set to rebuild and install the package you are trying to remove.

John Moon
  • 924
  • 6
  • 10
  • I need 1. erase target fs. 2. init again with some skeleton, as it usually does at start of building process 3. then take each library from desired package list and try to build it (but as all of them alredy built - just copy it) - target install 4. copy overlay then compress. 5. embed to kernel (rebuild with initramfs, as i have it embedded into kernel bzImage single file) – xakepp35 Dec 03 '17 at 22:37
  • why there is no such half-clean command? are there ANY caveats to not include such functionality in buildroot? i would like to suggest that idea to dev team, but i would like to discuss is there anything i missed out? – xakepp35 Dec 03 '17 at 22:40
  • The discussion here may help you understand why a `-uninstall` command is not supported: http://lists.busybox.net/pipermail/buildroot/2013-February/067097.html Buildroot is targeted towards simplicity over features. If you need a more sophisticated build system, I might suggest Yocto. A great discussion on the differences can be found here: https://youtu.be/13LZ0szWSVg – John Moon Dec 03 '17 at 22:59
  • john-moon, Thanks for your report and good links! I really like that simplcity and seems i have no need to stick with more sophisticated build systems. In other words I don't need features (in broad sense of that word) but what i basically need is just an ability to clean (whole) target FS and make some actions to force rebuild it by just copying without actually rebuilding binaries for all nesesary packages and libraries. That could simply involve removing target installed stamps and will speedup rebuilding process alot! – xakepp35 Dec 05 '17 at 02:13
  • 1
    You're welcome. You may also consider enabling ccache which essentially does what you're talking about with a little more overhead. It has the advantage of actually checking if all the configurations are the same too: https://buildroot.org/downloads/manual/manual.html#ccache – John Moon Dec 05 '17 at 02:34
  • john-moon, afaik ccache is like compiler cache? so, if i correctly understand, "build all libraries" really occurs, but as soon as ccache stores built binaries and dont actually builds? or not? – xakepp35 Dec 23 '17 at 23:24
  • Yes, if ccache sees that the binary you are trying to build has the exact same configuration as the last build, it will just use the binary from the last build instead of rebuilding. There's some nuances, but that's the general idea. – John Moon Dec 23 '17 at 23:26